//  [python]
def RANet_Multiple_forward_eval(self, x1, Ker, msk2, msk_p, mode=''):  # vxd  feature * msk *2  _feature_Rf
        if mode == 'first':
            # Exact template features
            x2 = Ker
            base_features2 = self.res_forward(x2)
            Kernel_3 = f.normalize(f.max_pool2d(self.L3(base_features2[2]), 2))
            Kernel_4 = f.normalize(self.L4(base_features2[3]))
            Kernel_5 = f.normalize(f.upsample(self.L5(base_features2[4]), scale_factor=2, mode='bilinear'))
            Kernel_tmp = f.normalize(self.L_g(torch.cat([Kernel_3, Kernel_4, Kernel_5], dim=1)))
            Kernel_tmp = f.avg_pool2d(Kernel_tmp, 2)
            return [Kernel_tmp]
        # Current frame feature
        base_features1 = self.res_forward(x1)
        Feature_3 = f.normalize(f.max_pool2d(self.L3(base_features1[2]), 2))
        Feature_4 = f.normalize(self.L4(base_features1[3]))
        Feature_5 = f.normalize(f.upsample(self.L5(base_features1[4]), scale_factor=2, mode='bilinear'))
        Feature = f.normalize(self.L_g(torch.cat([Feature_3, Feature_4, Feature_5], dim=1)))

        Kernel_tmp = Ker
        Out_Rs = []

        basef1 = torch.cat([self.ls13(base_features1[2]),
                            self.ls14(base_features1[3]),
                            self.ls15(base_features1[4]), ], 1)
        basef2 = torch.cat([self.ls22(base_features1[1]),
                            self.ls23(base_features1[2]),
                            self.ls24(base_features1[3]), ], 1)
        basef3 = torch.cat([self.ls31(base_features1[0]),
                            self.ls32(base_features1[1]),
                            self.ls33(base_features1[2])], 1)

        for idx in range(len(Feature)):  # batch
            ker = Kernel_tmp[idx: idx + 1]
            feature = Feature[idx: idx + 1]
            m2 = msk2[idx: idx + 1]
            mp = msk_p[idx: idx + 1]
            max_obj = m2.max().int().data.cpu().numpy()
            if max_obj < 2:
                m2[0, 0, 0, 0] = 2
                max_obj = m2.max().int().data.cpu().numpy()
            M2s = self.P2masks(f.relu(m2 - 1), max_obj - 1)
            M2_all = m2.ge(1.5).float()
            Mps = self.P2masks(f.relu(mp - 1), max_obj - 1)
            Mp_all = mp.ge(1.5).float()

            # Correlation
            Corr_subs = []
            ker_R = self.to_kernel(ker)
            corr_R = self.correlate(ker_R, feature)

            # Ranking attention scores
            T_corr = f.max_pool2d(corr_R, 2).view(-1, 405, 405).transpose(1, 2).view(-1, 405, 15, 27)
            R_map = f.relu(self.Ranking(T_corr)) * 0.2
            Rmaps = []

            for idy in range(max_obj):  # make corrs (backgrounds(=1) and objs)
                m2_rep = f.adaptive_avg_pool2d(M2s[idy], ker.size()[-2::])
                corr_sub = m2_rep.view(m2_rep.size()[0], -1, 1, 1) * corr_R
                Corr_subs.append(corr_sub)
                Rmaps.append((R_map * m2_rep).view(-1, 1, 405))

            Outs = []
            for idy in range(1, max_obj):  # training:with_bg, testing: w/o BG
                corr = Corr_subs[idy]
                co_size = Corr_subs[idy].size()[2::]
                max_only, indices = f.max_pool2d(corr, co_size, return_indices=True)
                max_only = max_only.view(-1, 1, 405) + Rmaps[idy]
                # Rank & select FG
                m_sorted, m_sorted_idx = max_only.sort(descending=True, dim=2)
                corr = torch.cat([co.index_select(0, m_sort[0, 0:256]).unsqueeze(0) for co, m_sort in zip(corr, m_sorted_idx)])
                # Merge net FG
                corr_fores = self.p_2(self.res_1(self.p_1(f.upsample(corr, scale_factor=2, mode='bilinear'))))
                if max_obj == 1:  # only bg
                    print('missing obj')
                    corr_backs = torch.zeros(corr_fores.size()).cuda()
                else:
                    backs_idx = Corr_subs[0:idy] + Corr_subs[idy + 1::]
                    corr_b = torch.cat(backs_idx, 1)
                    R_map_b = Rmaps[0:idy] + Rmaps[idy + 1::]
                    R_map_b = torch.cat(R_map_b, 2)
                    max_only_b, indices = f.max_pool2d(corr_b, co_size, return_indices=True)
                    max_only_b = max_only_b.view(R_map_b.size()[0], 1, -1) + R_map_b
                    # Rank & select BG
                    m_sorted, m_sorted_idx = max_only_b.sort(descending=True, dim=2)
                    corr_b = torch.cat([co.index_select(0, m_sort[0, 0:256]).unsqueeze(0) for co, m_sort in zip(corr_b, m_sorted_idx)])
                    # Merge net BG
                    corr_backs = self.p_2(self.res_1(self.p_1(f.upsample(corr_b, scale_factor=2, mode='bilinear'))))
                if idy == 0:
                    tmp = corr_fores
                    corr_fores = corr_backs
                    corr_backs = tmp
                    m_p = f.adaptive_avg_pool2d(Mp_all, corr_fores.size()[-2::])
                else:
                    m_p = f.adaptive_avg_pool2d(Mps[idy], corr_fores.size()[-2::])
                # low level features
                base1 = torch.cat([basef1[idx: idx + 1], corr_fores, corr_backs, m_p], 1)
                fea1 = self.R1(base1)
                base2 = torch.cat([basef2[idx: idx + 1],
                                   fea1], 1)
                fea2 = self.R2(base2)
                base3 = torch.cat([basef3[idx: idx + 1],
                                   fea2], 1)
                fea3 = self.R3(base3)
                out = f.sigmoid(fea3)
                Outs.append(out)
            Out = torch.cat(Outs, 1)
            Out_Rs.append(Out)
        features = []
        out = [Out_Rs]
        return out, features