jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def forward(self, inp):
        """Get Inception feature maps
        Parameters
        ----------
        inp : torch.autograd.Variable
            Input tensor of shape Bx3xHxW. Values are expected to be in
            range (0, 1)
        Returns
        -------
        List of torch.autograd.Variable, corresponding to the selected output
        block, sorted ascending by index
        """
        outp = []
        x = inp

        if self.resize_input:
            x = F.interpolate(x, size=(299, 299), mode='bilinear')

        if self.normalize_input:
            x = x.clone()
            x[:, 0] = x[:, 0] * (0.229 / 0.5) + (0.485 - 0.5) / 0.5
            x[:, 1] = x[:, 1] * (0.224 / 0.5) + (0.456 - 0.5) / 0.5
            x[:, 2] = x[:, 2] * (0.225 / 0.5) + (0.406 - 0.5) / 0.5

        for idx, block in enumerate(self.blocks):
            x = block(x)
            if idx in self.output_blocks:
                outp.append(x)

            if idx == self.last_needed_block:
                break

        return outp
//  [python]
def forward(self, x):
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)
        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)
        x = self.layer5(x)
        x = F.upsample_bilinear(x,scale_factor=2)[:,:,:-1,:-1]
        x = F.upsample_bilinear(x,scale_factor=2)[:,:,:-1,:-1]
        x = F.upsample_bilinear(x,scale_factor=2)[:,:,:-1,:-1]
        return x
//  [python]
def forward(self, x):
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)
        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)
        x = self.layer5(x)
        x = F.interpolate(x,scale_factor=2,mode='bilinear')[:,:,:-1,:-1]
        x = F.interpolate(x,scale_factor=2,mode='bilinear')[:,:,:-1,:-1]
        x = F.interpolate(x,scale_factor=2,mode='bilinear')[:,:,:-1,:-1]
        return x
//  [python]
def forward(self, top_blob, lateral_blob):
        # Lateral 1x1 conv
        lat = self.conv_lateral(lateral_blob)
        # Top-down 2x upsampling
        # td = F.upsample(top_blob, size=lat.size()[2:], mode='bilinear')
        td = F.upsample(top_blob, scale_factor=2, mode='nearest')
        # Sum lateral and top-down
        return lat + td
//  [python]
def forward(self, top_blob, lateral_blob):
        # Lateral 1x1 conv
        lat = self.conv_lateral(lateral_blob)
        # Top-down 2x upsampling
        # td = F.upsample(top_blob, size=lat.size()[2:], mode='bilinear')
        td = F.interpolate(top_blob, scale_factor=2, mode='nearest')
        # Sum lateral and top-down
        return lat + td
//  [python]
def forward(self, x,y):
            concat_xy = torch.cat([x,y],1)
            feats = self.feats(concat_xy)
            feat3 = self.feat3(feats)
            feat4 = self.feat4(feat3)
            feat5 = self.feat5(feat4)
            fconn = self.fconn(feat5)

            score_feat3 = self.score_feat3(feat3)
            score_feat4 = self.score_feat4(feat4)
            score_fconn = self.score_fconn(fconn)

            score = F.upsample_bilinear(score_fconn, score_feat4.size()[2:])
            score += score_feat4
            score = F.upsample_bilinear(score, score_feat3.size()[2:])
            score += score_feat3

            return F.upsample_bilinear(score, x.size()[2:])
//  [python]
def forward(self, x,y):
            concat_xy = torch.cat([x,y],1)
            feats = self.feats(concat_xy)
            feat3 = self.feat3(feats)
            feat4 = self.feat4(feat3)
            feat5 = self.feat5(feat4)
            fconn = self.fconn(feat5)

            score_feat3 = self.score_feat3(feat3)
            score_feat4 = self.score_feat4(feat4)
            score_fconn = self.score_fconn(fconn)

            score = F.interpolate(score_fconn, size=score_feat4.size()[2:], mode='bilinear')
            score += score_feat4
            score = F.interpolate(score, size=score_feat3.size()[2:], mode='bilinear')
            score += score_feat3

            return F.interpolate(score, size=x.size()[2:], mode='bilinear')
//  [python]
def forward(self, x):
        next_x = []
        for level, feature in enumerate(x):

            temp_fea = self.Pconv[1](level, feature)
            if level > 0:
                temp_fea += self.Pconv[2](level, x[level - 1])
            if level < len(x) - 1:
                temp_fea += F.upsample_bilinear(self.Pconv[0](level, x[level + 1]),
                                                size=[temp_fea.size(2), temp_fea.size(3)])
            next_x.append(temp_fea)
        if self.iBN:
            next_x = iBN(next_x, self.bn)
        next_x = [self.relu(item) for item in next_x]
        return next_x
//  [python]
def forward(self, x):
        next_x = []
        for level, feature in enumerate(x):

            temp_fea = self.Pconv[1](level, feature)
            if level > 0:
                temp_fea += self.Pconv[2](level, x[level - 1])
            if level < len(x) - 1:
                temp_fea += F.interpolate(self.Pconv[0](level, x[level + 1]),
                                                size=[temp_fea.size(2), temp_fea.size(3)], mode='bilinear')
            next_x.append(temp_fea)
        if self.iBN:
            next_x = iBN(next_x, self.bn)
        next_x = [self.relu(item) for item in next_x]
        return next_x
//  [python]
def forward(self, x):
        x = self.conv1(x)
        x = self.relu1(x)
        x = self.conv2(x)
        x = self.relu2(x)
        x = self.conv3(x)
        x = self.relu3(x)
        x = self.conv4(x)
        x = self.relu4(x)
        x = self.conv5(x)
        x = F.upsample_bilinear(x, scale_factor=2)
        x = x[:, :, :-1, :-1]
        x = F.upsample_bilinear(x, scale_factor=2)
        x = x[:, :, :-1, :-1]
        x = F.upsample_bilinear(x, scale_factor=2)
        x = x[:, :, :-1, :-1]
        x = F.upsample_bilinear(x, scale_factor=2)
        x = x[:, :, :-1, :-1]
        x = F.upsample_bilinear(x, scale_factor=2)
        x = x[:, :, :-1, :-1]
        return x
//  [python]
def forward(self, x):
        x = self.conv1(x)
        x = self.relu1(x)
        x = self.conv2(x)
        x = self.relu2(x)
        x = self.conv3(x)
        x = self.relu3(x)
        x = self.conv4(x)
        x = self.relu4(x)
        x = self.conv5(x)
        x = F.interpolate(x, scale_factor=2, mode='bilinear')
        x = x[:, :, :-1, :-1]
        x = F.interpolate(x, scale_factor=2, mode='bilinear')
        x = x[:, :, :-1, :-1]
        x = F.interpolate(x, scale_factor=2, mode='bilinear')
        x = x[:, :, :-1, :-1]
        x = F.interpolate(x, scale_factor=2, mode='bilinear')
        x = x[:, :, :-1, :-1]
        x = F.interpolate(x, scale_factor=2, mode='bilinear')
        x = x[:, :, :-1, :-1]
        return x
//  [python]
def forward(self, x, z):
        SIZE = z.size()
        y = self.avg(x)
        y = self._se_reduce(y)
        y = y * torch.sigmoid(y)
        y = self._se_expand(y)
        if self.Avg_size != 1:
            y = F.upsample_bilinear(y, size=[SIZE[2], SIZE[3]])
        z = torch.sigmoid(y) * z
        return z
//  [python]
def forward(self, x, z):
        SIZE = z.size()
        y = self.avg(x)
        y = self._se_reduce(y)
        y = y * torch.sigmoid(y)
        y = self._se_expand(y)
        if self.Avg_size != 1:
            y = F.interpolate(y, size=[SIZE[2], SIZE[3]], mode='bilinear')
        z = torch.sigmoid(y) * z
        return z
//  [python]
def forward(self,x):
        x= self.conv1(x) # -,-,161,161
        x = self.relu1(x)
        x= self.conv2(x) # -,-,81,81
        x = self.relu2(x)
        x= self.conv3(x) # -,-,41,41
        x = self.relu3(x)
        x= self.conv4(x) # -,-,21,21
        x = self.relu4(x)
        x = self.conv5(x) # -,-,11,11
        # upsample
        x = F.upsample_bilinear(x,scale_factor=2)
        x = x[:,:,:-1,:-1] # -,-, 21,21

        x = F.upsample_bilinear(x,scale_factor=2)
        x = x[:,:,:-1,:-1] # -,-,41,41

        x = F.upsample_bilinear(x,scale_factor=2)
        x = x[:,:,:-1,:-1] #-,-,81,81

        x = F.upsample_bilinear(x,scale_factor=2)
        x = x[:,:,:-1,:-1] #-,-,161,161

        x = F.upsample_bilinear(x,scale_factor=2)
        x = x[:,:,:-1,:-1] # -,-,321,321

        return x
//  [python]
def forward(self,x):
        x= self.conv1(x) # -,-,161,161
        x = self.relu1(x)
        x= self.conv2(x) # -,-,81,81
        x = self.relu2(x)
        x= self.conv3(x) # -,-,41,41
        x = self.relu3(x)
        x= self.conv4(x) # -,-,21,21
        x = self.relu4(x)
        x = self.conv5(x) # -,-,11,11
        # upsample
        x = F.interpolate(x,scale_factor=2,mode='bilinear')
        x = x[:,:,:-1,:-1] # -,-, 21,21

        x = F.interpolate(x,scale_factor=2,mode='bilinear')
        x = x[:,:,:-1,:-1] # -,-,41,41

        x = F.interpolate(x,scale_factor=2,mode='bilinear')
        x = x[:,:,:-1,:-1] #-,-,81,81

        x = F.interpolate(x,scale_factor=2,mode='bilinear')
        x = x[:,:,:-1,:-1] #-,-,161,161

        x = F.interpolate(x,scale_factor=2,mode='bilinear')
        x = x[:,:,:-1,:-1] # -,-,321,321

        return x
//  [python]
def forward_single(self, x, solo_cls, solo_mask, grid_num):

		cls_feat = F.upsample_bilinear(x,(grid_num,grid_num))
		mask_feat = x
		for cls_layer in self.cls_convs:
			cls_feat = cls_layer(cls_feat)
		
		cls_score = solo_cls(cls_feat)
		n, _, h, w = mask_feat.shape

		grid_x = torch.arange(w).view(1,-1).float().repeat(h,1).cuda() / (w-1) * 2 - 1
		grid_y = torch.arange(h).view(-1,1).float().repeat(1,w).cuda() / (h-1) * 2 - 1

		x_map = grid_x.view(1, 1, h, w).repeat(n, 1, 1, 1)
		y_map = grid_y.view(1, 1, h, w).repeat(n, 1, 1, 1)
		mask_feat_xy = torch.cat((mask_feat, x_map, y_map), dim=1)

		for mask_layer in self.mask_convs:
			mask_feat_xy = mask_layer(mask_feat_xy)
		mask_score = solo_mask(mask_feat_xy)

		return cls_score, mask_score
//  [python]
def forward_single(self, x, solo_cls, solo_mask, grid_num):

		cls_feat = F.interpolate(x,(grid_num,grid_num),mode='bilinear')
		mask_feat = x
		for cls_layer in self.cls_convs:
			cls_feat = cls_layer(cls_feat)
		
		cls_score = solo_cls(cls_feat)
		n, _, h, w = mask_feat.shape

		grid_x = torch.arange(w).view(1,-1).float().repeat(h,1).cuda() / (w-1) * 2 - 1
		grid_y = torch.arange(h).view(-1,1).float().repeat(1,w).cuda() / (h-1) * 2 - 1

		x_map = grid_x.view(1, 1, h, w).repeat(n, 1, 1, 1)
		y_map = grid_y.view(1, 1, h, w).repeat(n, 1, 1, 1)
		mask_feat_xy = torch.cat((mask_feat, x_map, y_map), dim=1)

		for mask_layer in self.mask_convs:
			mask_feat_xy = mask_layer(mask_feat_xy)
		mask_score = solo_mask(mask_feat_xy)

		return cls_score, mask_score
//  [python]
def viz_single_img(x, save_path, t_stamp, cat, ind="", clamp_mean=False, raw=None):
    x = ((x - x.min()) / (x.max() - x.min())) * 255  # cast to [0, 255]
    if torch.sum(x != x).item():
        return
    if raw is not None:
        x = F.upsample_bilinear(x[None, None], size=raw.shape[-2:]).squeeze()
    x = x.unsqueeze(-1)
    if clamp_mean:
        x = torch.clamp(x, float(x.mean()) * 0.6)
        x = ((x - x.min()) / (x.max() - x.min())) * 255

    x_color = torch.cat([x, x, x], dim=-1)
    x_color = x_color.int()
    x_np = x_color.cpu().numpy()
    x_np = x_np.astype(np.uint8)
    x_np = cv2.applyColorMap(x_np, cv2.COLORMAP_JET)
    if raw is not None:
        raw = raw.permute(1, 2, 0)
        x_np = x_np * 0.44 + raw.cpu().numpy().astype(np.uint8) * 0.56
        x_np = np.clip(x_np, 0, 255)
    cv2.imwrite(f'{save_path}/{t_stamp}_{ind}_{cat}.jpg', x_np)
//  [python]
def viz_single_img(x, save_path, t_stamp, cat, ind="", clamp_mean=False, raw=None):
    x = ((x - x.min()) / (x.max() - x.min())) * 255  # cast to [0, 255]
    if torch.sum(x != x).item():
        return
    if raw is not None:
        x = F.interpolate(x[None, None], size=raw.shape[-2:], mode='bilinear').squeeze()
    x = x.unsqueeze(-1)
    if clamp_mean:
        x = torch.clamp(x, float(x.mean()) * 0.6)
        x = ((x - x.min()) / (x.max() - x.min())) * 255

    x_color = torch.cat([x, x, x], dim=-1)
    x_color = x_color.int()
    x_np = x_color.cpu().numpy()
    x_np = x_np.astype(np.uint8)
    x_np = cv2.applyColorMap(x_np, cv2.COLORMAP_JET)
    if raw is not None:
        raw = raw.permute(1, 2, 0)
        x_np = x_np * 0.44 + raw.cpu().numpy().astype(np.uint8) * 0.56
        x_np = np.clip(x_np, 0, 255)
    cv2.imwrite(f'{save_path}/{t_stamp}_{ind}_{cat}.jpg', x_np)
//  [python]
def cross_entropy2d(input, target, weight=None, size_average=True):
    n, c, h, w = input.size()
    nt, ht, wt = target.size()

    # Handle inconsistent size between input and target
    if h > ht and w > wt:  # upsample labels
        target = target.unsequeeze(1)
        target = F.upsample(target, size=(h, w), mode="nearest")
        target = target.sequeeze(1)
    elif h < ht and w < wt:  # upsample images
        input = F.upsample(input, size=(ht, wt), mode="bilinear")
    elif h != ht and w != wt:
        raise Exception("Only support upsampling")

    input = input.transpose(1, 2).transpose(2, 3).contiguous().view(-1, c)
    target = target.view(-1)
    loss = F.cross_entropy(input, target, weight=weight, size_average=size_average, ignore_index=250)
    return loss
//  [python]
def cross_entropy2d(input, target, weight=None, size_average=True):
    n, c, h, w = input.size()
    nt, ht, wt = target.size()

    # Handle inconsistent size between input and target
    if h > ht and w > wt:  # upsample labels
        target = target.unsqueeze(1)
        target = F.interpolate(target, size=(h, w), mode="nearest")
        target = target.squeeze(1)
    elif h < ht and w < wt:  # upsample images
        input = F.interpolate(input, size=(ht, wt), mode="bilinear")
    elif h != ht and w != wt:
        raise Exception("Only support upsampling")

    input = input.transpose(1, 2).transpose(2, 3).contiguous().view(-1, c)
    target = target.view(-1)
    loss = F.cross_entropy(input, target, weight=weight, size_average=size_average, ignore_index=250)
    return loss
//  [python]
def forward(self, x):
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        c3 = x
        x = self.layer3(x)
        c4 = x

        x = self.new_layer1(x)
        c5 = x
        x = self.new_layer2(x)
        c6 = x


        c3 = self.fusion_c3(c3)

        c3 = self.fusion_end(torch.cat([c3,
                                        F.upsample_bilinear(self.fusion_c4(c4), (c3.shape[2], c3.shape[3])),
                                        F.upsample_bilinear(self.fusion_c5(c5), (c3.shape[2], c3.shape[3]))],dim=1))

        c3 = self.att_c3(c3)
        c4 = self.att_c4(c4)
        c5 = self.att_c5(c5)
        c6 = self.att_c6(c6)

        locs = self.locs_forward(c3, c4, c5, c6)
        conf = self.conf_forward(c3, c4, c5, c6)

        return (locs, conf)
//  [python]
def forward(self, x):
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        c3 = x
        x = self.layer3(x)
        c4 = x

        x = self.new_layer1(x)
        c5 = x
        x = self.new_layer2(x)
        c6 = x


        c3 = self.fusion_c3(c3)

        c3 = self.fusion_end(torch.cat([c3,
                                        F.interpolate(self.fusion_c4(c4), size=(c3.shape[2], c3.shape[3]), mode='bilinear'),
                                        F.interpolate(self.fusion_c5(c5), size=(c3.shape[2], c3.shape[3]), mode='bilinear')],dim=1))

        c3 = self.att_c3(c3)
        c4 = self.att_c4(c4)
        c5 = self.att_c5(c5)
        c6 = self.att_c6(c6)

        locs = self.locs_forward(c3, c4, c5, c6)
        conf = self.conf_forward(c3, c4, c5, c6)

        return (locs, conf)
//  [python]
def _upsample_add(self, x, y):
        '''Upsample and add two feature maps.

        Args:
          x: (Variable) top feature map to be upsampled.
          y: (Variable) lateral feature map.

        Returns:
          (Variable) added feature map.

        Note in PyTorch, when input size is odd, the upsampled feature map
        with `F.upsample(..., scale_factor=2, mode='nearest')`
        maybe not equal to the lateral feature map size.

        e.g.
        original input size: [N,_,15,15] ->
        conv2d feature map size: [N,_,8,8] ->
        upsampled feature map size: [N,_,16,16]

        So we choose bilinear upsample which supports arbitrary output sizes.
        '''
        _,_,H,W = y.size()
        return F.upsample(x, size=(H,W), mode='bilinear') + y
//  [python]
def forward(self, x):
        conv1 = self.conv_block1(x)
        conv2 = self.conv_block2(conv1)
        conv3 = self.conv_block3(conv2)
        conv4 = self.conv_block4(conv3)
        conv5 = self.conv_block5(conv4)

        score = self.classifier(conv5)

        if self.learned_billinear:
            upscore2 = self.upscore2(score)
            score_pool4c = self.score_pool4(conv4)[
                :, :, 5 : 5 + upscore2.size()[2], 5 : 5 + upscore2.size()[3]
            ]
            upscore_pool4 = self.upscore4(upscore2 + score_pool4c)

            score_pool3c = self.score_pool3(conv3)[
                :, :, 9 : 9 + upscore_pool4.size()[2], 9 : 9 + upscore_pool4.size()[3]
            ]

            out = self.upscore8(score_pool3c + upscore_pool4)[
                :, :, 31 : 31 + x.size()[2], 31 : 31 + x.size()[3]
            ]
            return out.contiguous()

        else:
            score_pool4 = self.score_pool4(conv4)
            score_pool3 = self.score_pool3(conv3)
            score = F.upsample(score, score_pool4.size()[2:])
            score += score_pool4
            score = F.upsample(score, score_pool3.size()[2:])
            score += score_pool3
            out = F.upsample(score, x.size()[2:])

        return out
//  [python]
def forward(self, x):
        conv1 = self.conv_block1(x)
        conv2 = self.conv_block2(conv1)
        conv3 = self.conv_block3(conv2)
        conv4 = self.conv_block4(conv3)
        conv5 = self.conv_block5(conv4)

        score = self.classifier(conv5)

        if self.learned_billinear:
            upscore2 = self.upscore2(score)
            score_pool4c = self.score_pool4(conv4)[
                :, :, 5 : 5 + upscore2.size()[2], 5 : 5 + upscore2.size()[3]
            ]
            upscore_pool4 = self.upscore4(upscore2 + score_pool4c)

            score_pool3c = self.score_pool3(conv3)[
                :, :, 9 : 9 + upscore_pool4.size()[2], 9 : 9 + upscore_pool4.size()[3]
            ]

            out = self.upscore8(score_pool3c + upscore_pool4)[
                :, :, 31 : 31 + x.size()[2], 31 : 31 + x.size()[3]
            ]
            return out.contiguous()

        else:
            score_pool4 = self.score_pool4(conv4)
            score_pool3 = self.score_pool3(conv3)
            score = F.interpolate(score, score_pool4.size()[2:])
            score += score_pool4
            score = F.interpolate(score, score_pool3.size()[2:])
            score += score_pool3
            out = F.interpolate(score, x.size()[2:])

        return out
//  [python]
def loss(self,
			 cls_scores,
			 mask_preds,
			 gt_bboxes,
			 gt_labels,
			 gt_masks,
			 category_targets,
			 point_ins,
			 img_metas,
			 cfg,
			 gt_bboxes_ignore=None):
		assert len(cls_scores) == len(mask_preds)
		loss_mask = 0
		_,_,b_h,b_w = mask_preds[0].shape
		for i in range(5):
			mask_preds[i] = F.sigmoid(F.upsample_bilinear(mask_preds[i],(b_h,b_w)))
		bound=[self.grid_num[i]**2 for i in range(5)]
		for i in range(1,5):
			bound[i] += bound[i-1]
		 
		num_imgs=len(category_targets)
		for i in range(num_imgs):
			_, i_h, i_w = gt_masks[i].shape
			gt_masks[i] = nn.ConstantPad2d((0,b_w*self.strides[0]-i_w,0,b_h*self.strides[0]-i_h),0)(torch.tensor(gt_masks[i]))
			gt_masks[i] = F.upsample_bilinear(gt_masks[i].float().unsqueeze(0),(b_h,b_w))[0]

		flatten_cls_scores = [cls_score.permute(0, 2, 3, 1).reshape(num_imgs,-1, self.cls_out_channels) for cls_score in cls_scores]
		# need to check images first or dimensions first: image first and then row first
		flatten_cls_scores = torch.cat([cls_score for cls_score in flatten_cls_scores],dim=1).reshape(-1, self.cls_out_channels)
		mask_preds = torch.cat([mask_pred for mask_pred in mask_preds],dim=1)

		for i in range(num_imgs):
			ind = torch.nonzero(category_targets[i]).squeeze(-1)
			ins_ind = point_ins[i][ind]
			ins_mask = gt_masks[i][ins_ind].to(mask_preds.device)
			pred_mask = mask_preds[i][ind]
			loss_mask += self.dice_loss(pred_mask, ins_mask)
		loss_mask = self.dict_weight * (loss_mask/num_imgs)
		category_targets = torch.cat(category_targets)
		num_pos = (category_targets > 0).sum()

		loss_cls = self.loss_cls(flatten_cls_scores, category_targets, avg_factor=num_pos+num_imgs)
		
		return dict(
			   loss_cls=loss_cls,
			   loss_mask=loss_mask)
//  [python]
def loss(self,
			 cls_scores,
			 mask_preds,
			 gt_bboxes,
			 gt_labels,
			 gt_masks,
			 category_targets,
			 point_ins,
			 img_metas,
			 cfg,
			 gt_bboxes_ignore=None):
		assert len(cls_scores) == len(mask_preds)
		loss_mask = 0
		_,_,b_h,b_w = mask_preds[0].shape
		for i in range(5):
			mask_preds[i] = F.sigmoid(F.interpolate(mask_preds[i],(b_h,b_w),mode='bilinear'))
		bound=[self.grid_num[i]**2 for i in range(5)]
		for i in range(1,5):
			bound[i] += bound[i-1]
		 
		num_imgs=len(category_targets)
		for i in range(num_imgs):
			_, i_h, i_w = gt_masks[i].shape
			gt_masks[i] = nn.ConstantPad2d((0,b_w*self.strides[0]-i_w,0,b_h*self.strides[0]-i_h),0)(torch.tensor(gt_masks[i]))
			gt_masks[i] = F.interpolate(gt_masks[i].float().unsqueeze(0),(b_h,b_w),mode='bilinear')[0]

		flatten_cls_scores = [cls_score.permute(0, 2, 3, 1).reshape(num_imgs,-1, self.cls_out_channels) for cls_score in cls_scores]
		# need to check images first or dimensions first: image first and then row first
		flatten_cls_scores = torch.cat([cls_score for cls_score in flatten_cls_scores],dim=1).reshape(-1, self.cls_out_channels)
		mask_preds = torch.cat([mask_pred for mask_pred in mask_preds],dim=1)

		for i in range(num_imgs):
			ind = torch.nonzero(category_targets[i]).squeeze(-1)
			ins_ind = point_ins[i][ind]
			ins_mask = gt_masks[i][ins_ind].to(mask_preds.device)
			pred_mask = mask_preds[i][ind]
			loss_mask += self.dice_loss(pred_mask, ins_mask)
		loss_mask = self.dict_weight * (loss_mask/num_imgs)
		category_targets = torch.cat(category_targets)
		num_pos = (category_targets > 0).sum()

		loss_cls = self.loss_cls(flatten_cls_scores, category_targets, avg_factor=num_pos+num_imgs)
		
		return dict(
			   loss_cls=loss_cls,
			   loss_mask=loss_mask)
//  [python]
def __init__(self, in_ch_1,in_ch_2, out_ch, type='bilinear'):
        super(up, self).__init__()
        self.type=type
        if type=='bilinear':
            self.up = nn.Upsample(scale_factor=2,mode='bilinear',align_corners=True)
        elif type=='deconv':
            self.up = nn.ConvTranspose2d((in_ch_1+in_ch_2)//2, (in_ch_1+in_ch_2)//2, 2, stride=2)
        elif type == 'nearest':
            self.up = nn.Upsample(scale_factor=2)
        else:
            self.up=None
            F.upsample_bilinear()
        if type=='bilinear_additive':
            self.conv = double_conv (in_ch_1//2+in_ch_2,out_ch)
        else:
            self.conv = double_conv(in_ch_1+in_ch_2, out_ch)
//  [python]
def __init__(self, in_ch_1,in_ch_2, out_ch, type='bilinear'):
        super(up, self).__init__()
        self.type=type
        if type=='bilinear':
            self.up = nn.Upsample(scale_factor=2,mode='bilinear',align_corners=True)
        elif type=='deconv':
            self.up = nn.ConvTranspose2d((in_ch_1+in_ch_2)//2, (in_ch_1+in_ch_2)//2, 2, stride=2)
        elif type == 'nearest':
            self.up = nn.Upsample(scale_factor=2)
        else:
            self.up=None
        if type=='bilinear_additive':
            self.conv = double_conv (in_ch_1//2+in_ch_2,out_ch)
        else:
            self.conv = double_conv(in_ch_1+in_ch_2, out_ch)
//  [python]
def forward(self,x):

        
        x = self.frontend(x)

        x = self.own_reslayer_3(x)

        x = self.de_pred(x)

        x = F.upsample(x,scale_factor=8)
        return x
//  [python]
def forward(self,x):

        
        x = self.frontend(x)

        x = self.own_reslayer_3(x)

        x = self.de_pred(x)

        x = F.interpolate(x,scale_factor=8)
        return x
//  [python]
def forward(self,x):
        x = self.frontend(x)

        x = self.own_reslayer_3(x)

        # pdb.set_trace()
        x = self.backend(x)
        x = self.convDU(x)
        x = self.convLR(x)
        x = self.output_layer(x)

        x = F.upsample(x,scale_factor=8)
        return x
//  [python]
def forward(self,x):
        x = self.frontend(x)

        x = self.own_reslayer_3(x)

        # pdb.set_trace()
        x = self.backend(x)
        x = self.convDU(x)
        x = self.convLR(x)
        x = self.output_layer(x)

        x = F.interpolate(x,scale_factor=8)
        return x
//  [python]
def forward(self, x):
        print("x", x.size())
        x = self.conv1(x)
        print("conv1", x.size())
        x = self.layer1(x)
        print("layer1", x.size())
        x = self.layer2(x)
        print("layer2", x.size())
        x = self.layer3(x)
        print("layer3", x.size())
        x = self.layer4(x)
        print("layer4", x.size())
        x = self.final(
            torch.cat(
                [x, self.layer5a(x), self.layer5b(x), self.layer5c(x), self.layer5d(x)],
                1,
            )
        )
        print("final", x.size())

        return F.upsample_bilinear(x, x.size()[2:])
//  [python]
def forward(self, x):
        print("x", x.size())
        x = self.conv1(x)
        print("conv1", x.size())
        x = self.layer1(x)
        print("layer1", x.size())
        x = self.layer2(x)
        print("layer2", x.size())
        x = self.layer3(x)
        print("layer3", x.size())
        x = self.layer4(x)
        print("layer4", x.size())
        x = self.final(
            torch.cat(
                [x, self.layer5a(x), self.layer5b(x), self.layer5c(x), self.layer5d(x)],
                1,
            )
        )
        print("final", x.size())

        return F.interpolate(x, size=x.size()[2:], mode='bilinear')
//  [python]
def _upsample_like(src, tar):

    src = F.upsample(src, size=tar.shape[2:], mode="bilinear")

    return src
//  [python]
def _upsample_like(src, tar):

    src = F.interpolate(src, size=tar.shape[2:], mode="bilinear")

    return src
//  [python]
def forward(self, x):
        dec1 = self.dec1(x)
        dec2 = self.dec2(dec1)
        dec3 = self.dec3(dec2)
        dec4 = self.dec4(dec3)
        center = self.center(dec4)
        enc4 = self.enc4(
            torch.cat([center, F.upsample_bilinear(dec4, center.size()[2:])], 1)
        )
        enc3 = self.enc3(
            torch.cat([enc4, F.upsample_bilinear(dec3, enc4.size()[2:])], 1)
        )
        enc2 = self.enc2(
            torch.cat([enc3, F.upsample_bilinear(dec2, enc3.size()[2:])], 1)
        )
        enc1 = self.enc1(
            torch.cat([enc2, F.upsample_bilinear(dec1, enc2.size()[2:])], 1)
        )

        return F.upsample_bilinear(self.final(enc1), x.size()[2:])
//  [python]
def forward(self, x):
        dec1 = self.dec1(x)
        dec2 = self.dec2(dec1)
        dec3 = self.dec3(dec2)
        dec4 = self.dec4(dec3)
        center = self.center(dec4)
        enc4 = self.enc4(
            torch.cat([center, F.interpolate(dec4, center.size()[2:], mode='bilinear')], 1)
        )
        enc3 = self.enc3(
            torch.cat([enc4, F.interpolate(dec3, enc4.size()[2:], mode='bilinear')], 1)
        )
        enc2 = self.enc2(
            torch.cat([enc3, F.interpolate(dec2, enc3.size()[2:], mode='bilinear')], 1)
        )
        enc1 = self.enc1(
            torch.cat([enc2, F.interpolate(dec1, enc2.size()[2:], mode='bilinear')], 1)
        )

        return F.interpolate(self.final(enc1), x.size()[2:], mode='bilinear')
//  [python]
def forward(self, ref, tgt, iters=6, scale=1):
        b, *_ = ref.shape

        feat1 = self.encoder(ref)
        feat2 = self.encoder(tgt)

        flows = []
        flow = torch.zeros(b, 2, *feat2.shape[-2:]).cuda()

        corr_fn = CorrBlock(feat2, feat1, num_levels=2, radius=4)
        coords0, coords1 = self.initialize_flow(feat1, scale=1)

        delta_stack = 0
        for itr in range(iters):
            corr = corr_fn(coords1)
            delta = self.update_ctrlpts(corr, flow)

            theta = self.theta.repeat(b,1,1)
            delta_stack = delta_stack + delta
            coords1 = self.tps_grid(delta_stack, theta, feat_size=self.feat_size)

            flow = coords1.permute(0,3,1,2) - coords0
            flow = self.scaling_flow(flow, self.feat_size, self.base_size, scale)
            flow_ = F.upsample_bilinear(flow, None, [int(8 * scale),int(8 * scale)]).permute(0,2,3,1)
            flows.append(flow_)

            coords1 = coords1.permute(0,3,1,2)

        return flows
//  [python]
def forward(self, ref, tgt, iters=6, scale=1):
        b, *_ = ref.shape

        feat1 = self.encoder(ref)
        feat2 = self.encoder(tgt)

        flows = []
        flow = torch.zeros(b, 2, *feat2.shape[-2:]).cuda()

        corr_fn = CorrBlock(feat2, feat1, num_levels=2, radius=4)
        coords0, coords1 = self.initialize_flow(feat1, scale=1)

        delta_stack = 0
        for itr in range(iters):
            corr = corr_fn(coords1)
            delta = self.update_ctrlpts(corr, flow)

            theta = self.theta.repeat(b,1,1)
            delta_stack = delta_stack + delta
            coords1 = self.tps_grid(delta_stack, theta, feat_size=self.feat_size)

            flow = coords1.permute(0,3,1,2) - coords0
            flow = self.scaling_flow(flow, self.feat_size, self.base_size, scale)
            flow_ = F.interpolate(flow, size=[int(8 * scale),int(8 * scale)], mode='bilinear').permute(0,2,3,1)
            flows.append(flow_)

            coords1 = coords1.permute(0,3,1,2)

        return flows
//  [python]
def forward(self,x):
            outs = self.backbone(x)
            if self.training:
                out1, out3 = self.decode_head(outs)
                out2 = self.auxiliary_head(outs)
                return F.upsample_bilinear(out1,scale_factor=4.0),F.upsample_bilinear(out2,scale_factor=16.0),F.upsample_bilinear(out3,scale_factor=4.0)
            else:
                out1 = self.decode_head(outs)
            return F.upsample_bilinear(out1,scale_factor=4.0)
//  [python]
def forward(self,x):
            outs = self.backbone(x)
            if self.training:
                out1, out3 = self.decode_head(outs)
                out2 = self.auxiliary_head(outs)
                return F.interpolate(out1,scale_factor=4.0,mode='bilinear'),F.interpolate(out2,scale_factor=16.0,mode='bilinear'),F.interpolate(out3,scale_factor=4.0,mode='bilinear')
            else:
                out1 = self.decode_head(outs)
            return F.interpolate(out1,scale_factor=4.0,mode='bilinear')
//  [python]
def forward(self, wav): # wav: B, C, T
        spec=self.stft.transform(wav) #B,C,F,T
        
        B,Cin,_,T=spec[0].shape
        
        tlr=spec[0].flatten(1,2)
        tli=spec[1].flatten(1,2)
        
        tl=self.preconv((tlr,tli))
        
        t=tl
        
        tl=self.synth_first(tl)
        tl=self.bn_first(tl)
        
        ts_sum=None
        scale_factor=1
        for i in range(len(self.synth_conv)):
            if i%self.synth_layer==0 and i!=0:
                tl=self.reduce_conv[i//self.synth_layer-1](tl)
                scale_factor*=2
                
            tl, ts=self.synth_conv[i](tl)
            if ts is not None:
                if ts_sum is None:
                    ts_sum=ts
                else:
                    ts0=F.upsample_nearest(ts[0], scale_factor=scale_factor)
                    ts1=F.upsample_nearest(ts[1], scale_factor=scale_factor)
                    
                    ts=ts0,ts1
                    ts_sum=tuple_plus(ts_sum, ts)
            
        spec=self.synth_final(ts_sum) # B, freq*ch_in, T
        
        padding=spec[0][..., :self.lookahead], spec[1][..., :self.lookahead]
        padding=padding[0]-padding[0], padding[1]-padding[1]
        
        spec=spec[0][..., self.lookahead:], spec[1][..., self.lookahead:]
        spec=torch.cat([spec[0], padding[0]], dim=-1), torch.cat([spec[1], padding[1]], dim=-1)
        
        spec=cMul(self.synth_act(spec), t)
        spec=self.synth_last(spec)
        spec=spec[0].unsqueeze(1), spec[1].unsqueeze(1)
        return self.stft.reverse(spec)
//  [python]
def forward(self, wav): # wav: B, C, T
        spec=self.stft.transform(wav) #B,C,F,T
        
        B,Cin,_,T=spec[0].shape
        
        tlr=spec[0].flatten(1,2)
        tli=spec[1].flatten(1,2)
        
        tl=self.preconv((tlr,tli))
        
        t=tl
        
        tl=self.synth_first(tl)
        tl=self.bn_first(tl)
        
        ts_sum=None
        scale_factor=1
        for i in range(len(self.synth_conv)):
            if i%self.synth_layer==0 and i!=0:
                tl=self.reduce_conv[i//self.synth_layer-1](tl)
                scale_factor*=2
                
            tl, ts=self.synth_conv[i](tl)
            if ts is not None:
                if ts_sum is None:
                    ts_sum=ts
                else:
                    ts0=F.interpolate(ts[0], scale_factor=scale_factor, mode='nearest')
                    ts1=F.interpolate(ts[1], scale_factor=scale_factor, mode='nearest')
                    
                    ts=ts0,ts1
                    ts_sum=tuple_plus(ts_sum, ts)
            
        spec=self.synth_final(ts_sum) # B, freq*ch_in, T
        
        padding=spec[0][..., :self.lookahead], spec[1][..., :self.lookahead]
        padding=padding[0]-padding[0], padding[1]-padding[1]
        
        spec=spec[0][..., self.lookahead:], spec[1][..., self.lookahead:]
        spec=torch.cat([spec[0], padding[0]], dim=-1), torch.cat([spec[1], padding[1]], dim=-1)
        
        spec=cMul(self.synth_act(spec), t)
        spec=self.synth_last(spec)
        spec=spec[0].unsqueeze(1), spec[1].unsqueeze(1)
        return self.stft.reverse(spec)
//  [python]
def forward(self, image, text=None, ref_image=None):
        image = torch.nn.functional.upsample_bilinear(image, (224, 224))
        if text is not None:
            similarity = 1 - self.model(image, text)[0] / 100  # cos is big when angle is small, thus 1 - cos
        elif ref_image is not None:
            ref_image = torch.nn.functional.upsample_bilinear(ref_image, (224, 224))
            ref_image_features = self.model.encode_image(ref_image)
            image_features = self.model.encode_image(image)
            ref_image_features = ref_image_features / ref_image_features.norm(dim=-1, keepdim=True)
            image_features = image_features / image_features.norm(dim=-1, keepdim=True)
            similarity = (100.0 * image_features @ ref_image_features.T)
            similarity = 1 - similarity[0] / 100

        return similarity
//  [python]
def forward(self, image, text=None, ref_image=None):
        image = torch.nn.functional.interpolate(image, (224, 224), mode='bilinear')
        if text is not None:
            similarity = 1 - self.model(image, text)[0] / 100  # cos is big when angle is small, thus 1 - cos
        elif ref_image is not None:
            ref_image = torch.nn.functional.interpolate(ref_image, (224, 224), mode='bilinear')
            ref_image_features = self.model.encode_image(ref_image)
            image_features = self.model.encode_image(image)
            ref_image_features = ref_image_features / ref_image_features.norm(dim=-1, keepdim=True)
            image_features = image_features / image_features.norm(dim=-1, keepdim=True)
            similarity = (100.0 * image_features @ ref_image_features.T)
            similarity = 1 - similarity[0] / 100

        return similarity
//  [python]
def forward(self, x):
        c0 = x

        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)

        c1 = x

        x = self.maxpool(x)
        x = self.layer1(x)

        c2 = x

        x = self.layer2(x)
        c3 = x

        x = self.layer3(x)
        c4 = x

        x = self.new_layer1(x)
        c5 = x
        x = self.new_layer2(x)
        c6 = x

        c3 = self.fusion_c3(c3)

        c3 = self.fusion_end(torch.cat([c3,
                                        F.upsample_bilinear(self.fusion_c4(c4), (c3.shape[2], c3.shape[3])),
                                        F.upsample_bilinear(self.fusion_c5(c5), (c3.shape[2], c3.shape[3]))],dim=1))

        c3 = self.att_c3(c3)
        c4 = self.att_c4(c4)
        c5 = self.att_c5(c5)
        c6 = self.att_c6(c6)

        locs = self.locs_forward(c3, c4, c5, c6)
        conf = self.conf_forward(c3, c4, c5, c6)

        return (locs, conf, [c0, c1, c2, c3, c4])
//  [python]
def forward(self, x):
        c0 = x

        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)

        c1 = x

        x = self.maxpool(x)
        x = self.layer1(x)

        c2 = x

        x = self.layer2(x)
        c3 = x

        x = self.layer3(x)
        c4 = x

        x = self.new_layer1(x)
        c5 = x
        x = self.new_layer2(x)
        c6 = x

        c3 = self.fusion_c3(c3)

        c3 = self.fusion_end(torch.cat([c3,
                                        F.interpolate(self.fusion_c4(c4), size=(c3.shape[2], c3.shape[3]), mode='bilinear'),
                                        F.interpolate(self.fusion_c5(c5), size=(c3.shape[2], c3.shape[3]), mode='bilinear')],dim=1))

        c3 = self.att_c3(c3)
        c4 = self.att_c4(c4)
        c5 = self.att_c5(c5)
        c6 = self.att_c6(c6)

        locs = self.locs_forward(c3, c4, c5, c6)
        conf = self.conf_forward(c3, c4, c5, c6)

        return (locs, conf, [c0, c1, c2, c3, c4])
//  [python]
def forward(self, x):
        out = self.conv1(x)
        out = self.bn1(out)
        out = self.relu(out)
        out = self.maxpool(out)

        conv2 = self.layer1(out)
        conv3 = self.layer2(conv2)
        conv4 = self.layer3(conv3)
        conv5 = self.layer4(conv4)

        score = self.classifier(conv5)
        score_pool4 = self.score_pool4(conv4)
        score_pool3 = self.score_pool3(conv3)
        score_pool2 = self.score_pool2(conv2)
        score = F.upsample_bilinear(score, score_pool4.size()[2:])
        score += score_pool4
        score = F.upsample_bilinear(score, score_pool3.size()[2:])
        score += score_pool3
        score = F.upsample_bilinear(score, score_pool2.size()[2:])
        score += score_pool2
        final = F.upsample_bilinear(score, x.size()[2:])

        return final
//  [python]
def forward(self, x):
        out = self.conv1(x)
        out = self.bn1(out)
        out = self.relu(out)
        out = self.maxpool(out)

        conv2 = self.layer1(out)
        conv3 = self.layer2(conv2)
        conv4 = self.layer3(conv3)
        conv5 = self.layer4(conv4)

        score = self.classifier(conv5)
        score_pool4 = self.score_pool4(conv4)
        score_pool3 = self.score_pool3(conv3)
        score_pool2 = self.score_pool2(conv2)
        score = F.interpolate(score, size=score_pool4.size()[2:], mode='bilinear')
        score += score_pool4
        score = F.interpolate(score, size=score_pool3.size()[2:], mode='bilinear')
        score += score_pool3
        score = F.interpolate(score, size=score_pool2.size()[2:], mode='bilinear')
        score += score_pool2
        final = F.interpolate(score, size=x.size()[2:], mode='bilinear')

        return final
//  [python]
def forward(self, x):
        from torch.nn import functional as F
        return F.upsample_nearest(x, scale_factor=2)
//  [python]
def forward(self, x):
        from torch.nn import functional as F
        return F.interpolate(x, scale_factor=2, mode='nearest')
//  [python]
def forward(self, x, y):
        x = F.upsample_nearest(x, size=(12,12))
        x = F.upsample_nearest(x, scale_factor=2)

        y = F.upsample_nearest(y, size=(8,10,9))
        y = F.upsample_nearest(y, scale_factor=3)
        return x, y
//  [python]
def forward(self, x, y):
        x = F.interpolate(x, size=(12,12), mode='nearest')
        x = F.interpolate(x, scale_factor=2, mode='nearest')

        y = F.interpolate(y, size=(8,10,9), mode='nearest')
        y = F.interpolate(y, scale_factor=3, mode='nearest')
        return x, y
//  [python]
def forward(self, x):
        # conv & downsampling
        down_sampled_fmaps = []
        for i in range(self.n_stages-1):
            x = self.down_convs[i](x)
            x = self.max_pooling(x)
            down_sampled_fmaps.insert(0, x)

        # center convs
        x = self.down_convs[self.n_stages-1](x)
        x = self.up_convs[0](x)

        # conv & upsampling
        for i, down_sampled_fmap in enumerate(down_sampled_fmaps):
            x = torch.cat([x, down_sampled_fmap], 1)
            x = self.up_convs[i+1](x)
            x = F.upsample(x, scale_factor=2, mode='bilinear')

        return self.out_conv(x)
//  [python]
def forward(self, x):
        # conv & downsampling
        down_sampled_fmaps = []
        for i in range(self.n_stages-1):
            x = self.down_convs[i](x)
            x = self.max_pooling(x)
            down_sampled_fmaps.insert(0, x)

        # center convs
        x = self.down_convs[self.n_stages-1](x)
        x = self.up_convs[0](x)

        # conv & upsampling
        for i, down_sampled_fmap in enumerate(down_sampled_fmaps):
            x = torch.cat([x, down_sampled_fmap], 1)
            x = self.up_convs[i+1](x)
            x = F.interpolate(x, scale_factor=2, mode='bilinear')

        return self.out_conv(x)
//  [python]
def compute_loss(self, seg_outputs, segs, weights=[0.125, 0.25, 0.5, 1.0]):
        seg_loss_f = nn.CrossEntropyLoss()
        segs = segs.float()
        loss_scales = []
        scales = [1/32, 1/16, 1/8, 1/4]
        for index_str in seg_outputs:
            index = int(index_str)
            target = F.upsample_nearest(segs, scale_factor=scales[index]).long().squeeze(1)
            loss_scales.append(weights[index]*seg_loss_f(seg_outputs[index_str], target))
        return torch.sum(torch.stack(loss_scales))
//  [python]
def compute_loss(self, seg_outputs, segs, weights=[0.125, 0.25, 0.5, 1.0]):
        seg_loss_f = nn.CrossEntropyLoss()
        segs = segs.float()
        loss_scales = []
        scales = [1/32, 1/16, 1/8, 1/4]
        for index_str in seg_outputs:
            index = int(index_str)
            target = F.interpolate(segs, scale_factor=scales[index], mode='nearest').long().squeeze(1)
            loss_scales.append(weights[index]*seg_loss_f(seg_outputs[index_str], target))
        return torch.sum(torch.stack(loss_scales))
//  [python]
def _upsample_add(self, x, y):
        _,_,H,W = y.shape
        return F.upsample(x, size=(H,W), mode='bilinear') + y
//  [python]
def _upsample_add(self, x, y):
        _,_,H,W = y.shape
        return F.interpolate(x, size=(H,W), mode='bilinear') + y
//  [python]
def forward(self, x):
        x = self.up_0(x)
        x = self.up_1(x)
        x = self.up_2(x)
        x = self.up_3(x)
        x = F.upsample(x, scale_factor=1, mode='bilinear')
        x = F.upsample(x, size=(12,52), mode='bicubic', align_corners=True)
        x = F.upsample_bilinear(x, scale_factor=1)
        x = F.upsample_nearest(x, size=(12,52))
        x = F.interpolate(x, scale_factor=(1,1), mode='nearest', recompute_scale_factor=True)
        x = F.interpolate(x, scale_factor=(1,1), mode='bicubic', align_corners=True, recompute_scale_factor=True)
        x = F.interpolate(x, size=(12,52), mode='bicubic', align_corners=False)
        x = F.relu(x)
        return x
//  [python]
def forward(self, x):
        x = self.up_0(x)
        x = self.up_1(x)
        x = self.up_2(x)
        x = self.up_3(x)
        x = F.interpolate(x, scale_factor=1, mode='bilinear')
        x = F.interpolate(x, size=(12,52), mode='bicubic', align_corners=True)
        x = F.interpolate(x, scale_factor=1, mode='bilinear')
        x = F.interpolate(x, size=(12,52), mode='nearest')
        x = F.interpolate(x, scale_factor=(1,1), mode='nearest', recompute_scale_factor=True)
        x = F.interpolate(x, scale_factor=(1,1), mode='bicubic', align_corners=True, recompute_scale_factor=True)
        x = F.interpolate(x, size=(12,52), mode='bicubic', align_corners=False)
        x = F.relu(x)
        return x
//  [python]
def forward(self, x):
		size=x.size()
		output=F.upsample(self.features(x), size[2:], mode='bilinear')
		return output
//  [python]
def forward(self, x):
		size=x.size()
		output=F.interpolate(self.features(x), size[2:], mode='bilinear')
		return output
//  [python]
def forward(self, x):

		#Size of input=1,num_classes,256,256
		feats = self.feats(x) #1,128,64,64
		feat3 = self.feat3(feats)#1,256,32,32
		feat4 = self.feat4(feat3)#1,512,16,16
		feat5 = self.feat5(feat4)#1,512,8,8
		fconn = self.fconn(feat5)#1,4096,8,8

		score_feat3 = self.score_feat3(feat3)#1,num_classes,32,32
		score_feat4 = self.score_feat4(feat4)#1,num_classes,16,16
		score_fconn = self.score_fconn(fconn)#1,num_classes,8,8

		score = F.upsample_bilinear(score_fconn, score_feat4.size()[2:])
		score += score_feat4
		score = F.upsample_bilinear(score, score_feat3.size()[2:])
		score += score_feat3

		output = F.upsample_bilinear(score, x.size()[2:])#1,num_classes,256,256

		return output
//  [python]
def forward(self, x):

		#Size of input=1,num_classes,256,256
		feats = self.feats(x) #1,128,64,64
		feat3 = self.feat3(feats)#1,256,32,32
		feat4 = self.feat4(feat3)#1,512,16,16
		feat5 = self.feat5(feat4)#1,512,8,8
		fconn = self.fconn(feat5)#1,4096,8,8

		score_feat3 = self.score_feat3(feat3)#1,num_classes,32,32
		score_feat4 = self.score_feat4(feat4)#1,num_classes,16,16
		score_fconn = self.score_fconn(fconn)#1,num_classes,8,8

		score = F.interpolate(score_fconn, size=score_feat4.size()[2:], mode='bilinear')
		score += score_feat4
		score = F.interpolate(score, size=score_feat3.size()[2:], mode='bilinear')
		score += score_feat3

		output = F.interpolate(score, size=x.size()[2:], mode='bilinear')#1,num_classes,256,256

		return output
//  [python]
def forward(self, f, corr_feature, pos):
        p0 = F.pad(f[0], [16, 16, 16, 16])[:, :, 4*pos[0]:4*pos[0]+61, 4*pos[1]:4*pos[1]+61]
        p1 = F.pad(f[1], [8, 8, 8, 8])[:, :, 2*pos[0]:2*pos[0]+31, 2*pos[1]:2*pos[1]+31]
        p2 = F.pad(f[2], [4, 4, 4, 4])[:, :, pos[0]:pos[0]+15, pos[1]:pos[1]+15]

        p3 = corr_feature[:, :, pos[0], pos[1]].view(-1, 256, 1, 1)

        out = self.deconv(p3)
        out = self.post0(F.upsample(self.h2(out) + self.v2(p2), size=(31, 31)))
        out = self.post1(F.upsample(self.h1(out) + self.v1(p1), size=(61, 61)))
        out = self.post2(F.upsample(self.h0(out) + self.v0(p0), size=(127, 127)))
        out = out.view(-1, 127*127)
        return out
//  [python]
def forward(self, f, corr_feature, pos):
        p0 = F.pad(f[0], [16, 16, 16, 16])[:, :, 4*pos[0]:4*pos[0]+61, 4*pos[1]:4*pos[1]+61]
        p1 = F.pad(f[1], [8, 8, 8, 8])[:, :, 2*pos[0]:2*pos[0]+31, 2*pos[1]:2*pos[1]+31]
        p2 = F.pad(f[2], [4, 4, 4, 4])[:, :, pos[0]:pos[0]+15, pos[1]:pos[1]+15]

        p3 = corr_feature[:, :, pos[0], pos[1]].view(-1, 256, 1, 1)

        out = self.deconv(p3)
        out = self.post0(F.interpolate(self.h2(out) + self.v2(p2), size=(31, 31)))
        out = self.post1(F.interpolate(self.h1(out) + self.v1(p1), size=(61, 61)))
        out = self.post2(F.interpolate(self.h0(out) + self.v0(p0), size=(127, 127)))
        out = out.view(-1, 127*127)
        return out
//  [python]
def forward(self, x):
        count=0

        size=x.size()
        x = self.resnet.conv1(x)
        x = self.resnet.bn1(x)
        x = self.resnet.relu(x)
        # x = self.resnet.maxpool(x)
        x = self.resnet.layer1(x)
        x = self.resnet.layer2(x)
        x = self.resnet.layer3(x)
        x = self.resnet.layer4(x)

        x = self.final(torch.cat([
        	x,
        	self.layer5a(x),
        	self.layer5b(x),
        	self.layer5c(x),
        	self.layer5d(x),
        ], 1))


        return F.upsample_bilinear(x,size[2:])