jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def visualize(x, y, y_pred, att_maps, batch_id):
    batch_size, num_maps, H, W, num_cls = att_maps.size()
    attention_map = att_maps[torch.arange(batch_size), :, :, :, y_pred]
    attention_map = attention_map.view(batch_size, num_maps, -1)  # (B, K, H * W)
    attention_map_max, _ = attention_map.max(dim=2, keepdim=True)  # (B, K, 1)
    attention_map_min, _ = attention_map.min(dim=2, keepdim=True)  # (B, K, 1)
    attention_map = (attention_map - attention_map_min) / (attention_map_max - attention_map_min)  # (B, K, H * W)
    attention_map = attention_map.view(batch_size, num_maps, H, W)  # (B, K, H, W)
    attention_map = F.upsample_bilinear(attention_map, size=(x.size(2), x.size(3)))
    for batch_index in range(batch_size):
        title = 'True: {}, Pred: {}'.format(y[batch_index], y_pred[batch_index])
        img_num = str(batch_id * batch_size + batch_index)
        img_save_path = os.path.join(viz_dir, img_num)
        visualize_attention(x[batch_index].squeeze().cpu().numpy()*255., attention_map[batch_index].cpu().numpy(), title, img_save_path)
//  [python]
def visualize(x, y, y_pred, att_maps, batch_id):
    batch_size, num_maps, H, W, num_cls = att_maps.size()
    attention_map = att_maps[torch.arange(batch_size), :, :, :, y_pred]
    attention_map = attention_map.view(batch_size, num_maps, -1)  # (B, K, H * W)
    attention_map_max, _ = attention_map.max(dim=2, keepdim=True)  # (B, K, 1)
    attention_map_min, _ = attention_map.min(dim=2, keepdim=True)  # (B, K, 1)
    attention_map = (attention_map - attention_map_min) / (attention_map_max - attention_map_min)  # (B, K, H * W)
    attention_map = attention_map.view(batch_size, num_maps, H, W)  # (B, K, H, W)
    attention_map = F.interpolate(attention_map, size=(x.size(2), x.size(3)), mode='bilinear')
    for batch_index in range(batch_size):
        title = 'True: {}, Pred: {}'.format(y[batch_index], y_pred[batch_index])
        img_num = str(batch_id * batch_size + batch_index)
        img_save_path = os.path.join(viz_dir, img_num)
        visualize_attention(x[batch_index].squeeze().cpu().numpy()*255., attention_map[batch_index].cpu().numpy(), title, img_save_path)
//  [python]
def _upsample_product(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 _upsample_product(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.interpolate(x, size=(H,W), mode='bilinear') * y
//  [python]
def test_upsamplingNearest1d(self):
        m = nn.Upsample(size=4, mode='nearest')
        in_t = torch.ones(1, 1, 2)
        out_t = m(Variable(in_t))
        self.assertEqual(torch.ones(1, 1, 4), out_t.data)

        input = Variable(torch.randn(1, 1, 2), requires_grad=True)
        self.assertTrue(gradcheck(lambda x: F.upsample(x, 4, mode='nearest'), (input,)))
//  [python]
def test_upsamplingNearest1d(self):
        m = nn.Upsample(size=4, mode='nearest')
        in_t = torch.ones(1, 1, 2)
        out_t = m(Variable(in_t))
        self.assertEqual(torch.ones(1, 1, 4), out_t.data)

        input = Variable(torch.randn(1, 1, 2), requires_grad=True)
        self.assertTrue(gradcheck(lambda x: F.interpolate(x, 4, mode='nearest'), (input,)))
//  [python]
def test_upsamplingLinear1d(self):
        m = nn.Upsample(size=4, mode='linear')
        in_t = torch.ones(1, 1, 2)
        out_t = m(Variable(in_t))
        self.assertEqual(torch.ones(1, 1, 4), out_t.data)

        input = Variable(torch.randn(1, 1, 2), requires_grad=True)
        self.assertTrue(gradcheck(lambda x: F.upsample(x, 4, mode='linear'), (input,)))
//  [python]
def test_upsamplingLinear1d(self):
        m = nn.Upsample(size=4, mode='linear')
        in_t = torch.ones(1, 1, 2)
        out_t = m(Variable(in_t))
        self.assertEqual(torch.ones(1, 1, 4), out_t.data)

        input = Variable(torch.randn(1, 1, 2), requires_grad=True)
        self.assertTrue(gradcheck(lambda x: F.interpolate(x, 4, mode='linear'), (input,)))
//  [python]
def forward(self, x):


        basic = self.conv0(x)
        basic1 = self.conv1(basic)

        encode0 = self.encoder0(basic1)
        down0 = self.down0(encode0)

        encode1 = self.encoder1(down0)
        down1 = self.down1(encode1)

        encode2 = self.encoder2(down1)
        down2 = self.down2(encode2)

        media_end = self.middle(down2)

        deblock2 = F.upsample_bilinear(media_end, scale_factor=2)
        deblock2 = torch.cat((deblock2, encode2), dim=1)
        deblock2 = self.up_conv2(deblock2)
        deblock2 = self.decoder2(deblock2)

        deblock1 = F.upsample_bilinear(deblock2, scale_factor=2)
        deblock1 = torch.cat((deblock1, encode1), dim=1)
        deblock1 = self.up_conv1(deblock1)
        deblock1 = self.decoder1(deblock1)

        deblock0 = F.upsample_bilinear(deblock1, scale_factor=2)
        deblock0 = torch.cat((deblock0, encode0), dim=1)
        deblock0 = self.up_conv0(deblock0)
        deblock0 = self.decoder0(deblock0)


        decoding_end = deblock0 + basic
        res = self.Conv(decoding_end)
        out = x + res
        
        return out
//  [python]
def forward(self, x):

        basic = self.conv0(x)
        basic1 = self.conv1(basic)

        encode0 = self.encoder0(basic1)
        down0 = self.down0(encode0)

        encode1 = self.encoder1(down0)
        down1 = self.down1(encode1)

        encode2 = self.encoder2(down1)
        down2 = self.down2(encode2)

        media_end = self.middle(down2)

        deblock2 = F.interpolate(media_end, scale_factor=2, mode='bilinear')
        deblock2 = torch.cat((deblock2, encode2), dim=1)
        deblock2 = self.up_conv2(deblock2)
        deblock2 = self.decoder2(deblock2)

        deblock1 = F.interpolate(deblock2, scale_factor=2, mode='bilinear')
        deblock1 = torch.cat((deblock1, encode1), dim=1)
        deblock1 = self.up_conv1(deblock1)
        deblock1 = self.decoder1(deblock1)

        deblock0 = F.interpolate(deblock1, scale_factor=2, mode='bilinear')
        deblock0 = torch.cat((deblock0, encode0), dim=1)
        deblock0 = self.up_conv0(deblock0)
        deblock0 = self.decoder0(deblock0)


        decoding_end = deblock0 + basic
        res = self.Conv(decoding_end)
        out = x + res
        
        return out
//  [python]
def test_upsamplingNearest2d(self):
        m = nn.Upsample(size=4, mode='nearest')
        in_t = torch.ones(1, 1, 2, 2)
        out_t = m(Variable(in_t))
        self.assertEqual(torch.ones(1, 1, 4, 4), out_t.data)

        input = Variable(torch.randn(1, 1, 2, 2), requires_grad=True)
        self.assertTrue(gradcheck(lambda x: F.upsample(x, 4, mode='nearest'), (input,)))
//  [python]
def test_upsamplingNearest2d(self):
        m = nn.Upsample(size=4, mode='nearest')
        in_t = torch.ones(1, 1, 2, 2)
        out_t = m(Variable(in_t))
        self.assertEqual(torch.ones(1, 1, 4, 4), out_t.data)

        input = Variable(torch.randn(1, 1, 2, 2), requires_grad=True)
        self.assertTrue(gradcheck(lambda x: F.interpolate(x, 4, mode='nearest'), (input,)))
//  [python]
def test_upsamplingBilinear2d(self):
        m = nn.Upsample(size=4, mode='bilinear')
        in_t = torch.ones(1, 1, 2, 2)
        out_t = m(Variable(in_t))
        self.assertEqual(torch.ones(1, 1, 4, 4), out_t.data)

        input = Variable(torch.randn(1, 1, 2, 2), requires_grad=True)
        self.assertTrue(gradcheck(lambda x: F.upsample(x, 4, mode='bilinear'), (input,)))
//  [python]
def test_upsamplingBilinear2d(self):
        m = nn.Upsample(size=4, mode='bilinear')
        in_t = torch.ones(1, 1, 2, 2)
        out_t = m(Variable(in_t))
        self.assertEqual(torch.ones(1, 1, 4, 4), out_t.data)

        input = Variable(torch.randn(1, 1, 2, 2), requires_grad=True)
        self.assertTrue(gradcheck(lambda x: F.interpolate(x, 4, mode='bilinear'), (input,)))
//  [python]
def test_upsamplingNearest3d(self):
        m = nn.Upsample(size=4, mode='nearest')
        in_t = torch.ones(1, 1, 2, 2, 2)
        out_t = m(Variable(in_t))
        self.assertEqual(torch.ones(1, 1, 4, 4, 4), out_t.data)

        input = Variable(torch.randn(1, 1, 2, 2, 2), requires_grad=True)
        self.assertTrue(gradcheck(lambda x: F.upsample(x, 4, mode='nearest'), (input,)))
//  [python]
def test_upsamplingNearest3d(self):
        m = nn.Upsample(size=4, mode='nearest')
        in_t = torch.ones(1, 1, 2, 2, 2)
        out_t = m(Variable(in_t))
        self.assertEqual(torch.ones(1, 1, 4, 4, 4), out_t.data)

        input = Variable(torch.randn(1, 1, 2, 2, 2), requires_grad=True)
        self.assertTrue(gradcheck(lambda x: F.interpolate(x, 4, mode='nearest'), (input,)))
//  [python]
def test_upsamplingTrilinear3d(self):
        m = nn.Upsample(size=4, mode='trilinear')
        in_t = torch.ones(1, 1, 2, 2, 2)
        out_t = m(Variable(in_t))
        self.assertEqual(torch.ones(1, 1, 4, 4, 4), out_t.data)

        input = Variable(torch.randn(1, 1, 2, 2, 2), requires_grad=True)
        self.assertTrue(gradcheck(lambda x: F.upsample(x, 4, mode='trilinear'), (input,)))
//  [python]
def test_upsamplingTrilinear3d(self):
        m = nn.Upsample(size=4, mode='trilinear')
        in_t = torch.ones(1, 1, 2, 2, 2)
        out_t = m(Variable(in_t))
        self.assertEqual(torch.ones(1, 1, 4, 4, 4), out_t.data)

        input = Variable(torch.randn(1, 1, 2, 2, 2), requires_grad=True)
        self.assertTrue(gradcheck(lambda x: F.interpolate(x, 4, mode='trilinear'), (input,)))
//  [python]
def scale_tensor(input, size=512, mode='bilinear'):
    print(input.size())
    # b,h,w = input.size()
    _, _, h, w = input.size()
    if mode == 'nearest':
        if h == 512 and w == 512:
            return input
        return F.upsample_nearest(input, size=(size, size))
    if h > 512 and w > 512:
        return F.upsample(input, size=(size, size), mode=mode, align_corners=True)
    return F.upsample(input, size=(size, size), mode=mode, align_corners=True)
//  [python]
def scale_tensor(input, size=512, mode='bilinear'):
    print(input.size())
    # b,h,w = input.size()
    _, _, h, w = input.size()
    if mode == 'nearest':
        if h == 512 and w == 512:
            return input
        return F.interpolate(input, size=(size, size), mode=mode)
    if h > 512 and w > 512:
        return F.interpolate(input, size=(size, size), mode=mode, align_corners=True)
    return F.interpolate(input, size=(size, size), mode=mode, align_corners=True)
//  [python]
def scale_tensor_list(input, ):
    output = []
    for i in range(len(input) - 1):
        output_item = []
        for j in range(len(input[i])):
            _, _, h, w = input[-1][j].size()
            output_item.append(F.upsample(input[i][j], size=(h, w), mode='bilinear', align_corners=True))
        output.append(output_item)
    output.append(input[-1])
    return output
//  [python]
def scale_tensor_list(input, ):
    output = []
    for i in range(len(input) - 1):
        output_item = []
        for j in range(len(input[i])):
            _, _, h, w = input[-1][j].size()
            output_item.append(F.interpolate(input[i][j], size=(h, w), mode='bilinear', align_corners=True))
        output.append(output_item)
    output.append(input[-1])
    return output
//  [python]
def scale_tensor_list_0(input, base_input):
    output = []
    assert len(input) == len(base_input)
    for j in range(len(input)):
        _, _, h, w = base_input[j].size()
        after_size = F.upsample(input[j], size=(h, w), mode='bilinear', align_corners=True)
        base_input[j] = base_input[j] + after_size
    # output.append(output_item)
    # output.append(input[-1])
    return base_input
//  [python]
def scale_tensor_list_0(input, base_input):
    output = []
    assert len(input) == len(base_input)
    for j in range(len(input)):
        _, _, h, w = base_input[j].size()
        after_size = F.interpolate(input[j], size=(h, w), mode='bilinear', align_corners=True)
        base_input[j] = base_input[j] + after_size
    # output.append(output_item)
    # output.append(input[-1])
    return base_input
//  [python]
def _forward(self, level, inp):
        # Upper branch
        up1 = inp
        up1 = self._modules['b1_' + str(level)](up1)

        # Lower branch
        low1 = F.max_pool2d(inp, 2, stride=2)
        low1 = self._modules['b2_' + str(level)](low1)

        if level > 1:
            low2 = self._forward(level - 1, low1)
        else:
            low2 = low1
            low2 = self._modules['b2_plus_' + str(level)](low2)

        low3 = low2
        low3 = self._modules['b3_' + str(level)](low3)
        if isinstance(self.sizes, tuple):
            low3 = self._modules['b_psp_' + str(level)](low3)

        up2 = F.upsample_nearest(low3, scale_factor=2)

        return self.ba(up1 + up2)
//  [python]
def _forward(self, level, inp):
        # Upper branch
        up1 = inp
        up1 = self._modules['b1_' + str(level)](up1)

        # Lower branch
        low1 = F.max_pool2d(inp, 2, stride=2)
        low1 = self._modules['b2_' + str(level)](low1)

        if level > 1:
            low2 = self._forward(level - 1, low1)
        else:
            low2 = low1
            low2 = self._modules['b2_plus_' + str(level)](low2)

        low3 = low2
        low3 = self._modules['b3_' + str(level)](low3)
        if isinstance(self.sizes, tuple):
            low3 = self._modules['b_psp_' + str(level)](low3)

        up2 = F.interpolate(low3, scale_factor=2, mode='nearest')

        return self.ba(up1 + up2)
//  [python]
def forward(self, feats):
        h, w = feats.size(2), feats.size(3)
        # h, w = max(self.sizes), max(self.sizes)
        priors = [F.upsample(input=stage(feats), size=(h, w), mode='bilinear') for stage in self.stages] + [feats]
        bottle = self.bottleneck(torch.cat(priors, 1))
        return self.relu(bottle)
//  [python]
def forward(self, feats):
        h, w = feats.size(2), feats.size(3)
        # h, w = max(self.sizes), max(self.sizes)
        priors = [F.interpolate(input=stage(feats), size=(h, w), mode='bilinear') for stage in self.stages] + [feats]
        bottle = self.bottleneck(torch.cat(priors, 1))
        return self.relu(bottle)
//  [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
        # upsample
        
        if self._nd==2:
            mode = 'bilinear'
        elif self._nd==3:
            mode = 'trilinear'
        elif self._nd==1:
            mode = 'linear'
        else:
            mode = 'nearest'
        
        x = F.upsample(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 21,21
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        x = F.upsample(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 41,41
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        x = F.upsample(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 81,81
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]
        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
        # upsample
        
        if self._nd==2:
            mode = 'bilinear'
        elif self._nd==3:
            mode = 'trilinear'
        elif self._nd==1:
            mode = 'linear'
        else:
            mode = 'nearest'
        
        x = F.interpolate(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 21,21
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        x = F.interpolate(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 41,41
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        x = F.interpolate(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 81,81
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]
        return x
//  [python]
def forward(self, x: torch.Tensor):
        x = x.unsqueeze(-1).unsqueeze(-1)  # [bz, emb_dim, 1, 1]
        x = x.expand(-1, -1, 2, 2)
        #pos_emb = torch.Tensor([[1, 2], [4, 3]]).type_as(x).unsqueeze(0).unsqueeze(0).expand(x.size(0), x.size(1), -1, -1)
        #x = x + pos_emb

        x = self.block1(x)
        x = torch.nn.functional.upsample_bilinear(x, scale_factor=2)
        x = self.block2(x)
        x = torch.nn.functional.upsample_bilinear(x, scale_factor=2)
        x = self.block3(x)
        x = torch.nn.functional.upsample_bilinear(x, scale_factor=2)
        x = self.block4(x)
        x = torch.nn.functional.upsample_bilinear(x, scale_factor=2)
        x = self.block5(x)
        x = self.block6(x)
        x = x[:, :, 2:30, 2:30]
        x = torch.sigmoid(x)
        return x
//  [python]
def forward(self, x: torch.Tensor):
        x = x.unsqueeze(-1).unsqueeze(-1)  # [bz, emb_dim, 1, 1]
        x = x.expand(-1, -1, 2, 2)
        #pos_emb = torch.Tensor([[1, 2], [4, 3]]).type_as(x).unsqueeze(0).unsqueeze(0).expand(x.size(0), x.size(1), -1, -1)
        #x = x + pos_emb

        x = self.block1(x)
        x = torch.nn.functional.interpolate(x, scale_factor=2, mode='bilinear')
        x = self.block2(x)
        x = torch.nn.functional.interpolate(x, scale_factor=2, mode='bilinear')
        x = self.block3(x)
        x = torch.nn.functional.interpolate(x, scale_factor=2, mode='bilinear')
        x = self.block4(x)
        x = torch.nn.functional.interpolate(x, scale_factor=2, mode='bilinear')
        x = self.block5(x)
        x = self.block6(x)
        x = x[:, :, 2:30, 2:30]
        x = torch.sigmoid(x)
        return x
//  [python]
def _forward(self, level, inp):
        # Upper branch
        up1 = inp
        up1 = self._modules['b1_' + str(level)](up1)

        # Lower branch
        low1 = F.avg_pool2d(inp, 2, stride=2)
        low1 = self._modules['b2_' + str(level)](low1)

        if level > 1:
            low2 = self._forward(level - 1, low1)
        else:
            low2 = low1
            low2 = self._modules['b2_plus_' + str(level)](low2)

        low3 = low2
        low3 = self._modules['b3_' + str(level)](low3)

        up2 = F.upsample(low3, scale_factor=2, mode='nearest')

        return up1 + up2
//  [python]
def _forward(self, level, inp):
        # Upper branch
        up1 = inp
        up1 = self._modules['b1_' + str(level)](up1)

        # Lower branch
        low1 = F.avg_pool2d(inp, 2, stride=2)
        low1 = self._modules['b2_' + str(level)](low1)

        if level > 1:
            low2 = self._forward(level - 1, low1)
        else:
            low2 = low1
            low2 = self._modules['b2_plus_' + str(level)](low2)

        low3 = low2
        low3 = self._modules['b3_' + str(level)](low3)

        up2 = F.interpolate(low3, scale_factor=2, mode='nearest')

        return up1 + up2
//  [python]
def forward(self, x):
        # import pudb;pu.db

        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)

        out = F.upsample_bilinear(score, x.size()[2:])

        return out
//  [python]
def forward(self, x):
        # import pudb;pu.db

        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)

        out = F.interpolate(score, size=x.size()[2:], mode='bilinear')

        return out
//  [python]
def predict_img(net, full_img, gpu=False):
    img = resize(full_img)
    img = np.array(img)
    img = torch.FloatTensor(img)

    x = img.permute(2, 0, 1).contiguous()  # transform to (C x H x W)

    x = x.view(1, 3, 256, 255)  # image (N x C x H x W)

    if gpu:
        with torch.no_grad():
            x = Variable(x).cuda()
    else:
        with torch.no_grad():
            x = Variable(x)

    x = normalize(x)  # normalize values to [0, 1]

    x = net(x)  # feed into the net

    x = F.sigmoid(x)
    x = F.upsample_bilinear(x, scale_factor=2).data[0][0].cpu().numpy()  # rescale the image to full size

    yy = dense_crf(np.array(full_img).astype(np.uint8), x)

    return yy > 0.5
//  [python]
def predict_img(net, full_img, gpu=False):
    img = resize(full_img)
    img = np.array(img)
    img = torch.FloatTensor(img)

    x = img.permute(2, 0, 1).contiguous()  # transform to (C x H x W)

    x = x.view(1, 3, 256, 255)  # image (N x C x H x W)

    if gpu:
        with torch.no_grad():
            x = Variable(x).cuda()
    else:
        with torch.no_grad():
            x = Variable(x)

    x = normalize(x)  # normalize values to [0, 1]

    x = net(x)  # feed into the net

    x = F.sigmoid(x)
    x = F.interpolate(x, scale_factor=2, mode='bilinear').data[0][0].cpu().numpy()  # rescale the image to full size

    yy = dense_crf(np.array(full_img).astype(np.uint8), x)

    return yy > 0.5
//  [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
        
        if self._nd==2:
            mode = 'bilinear'
        elif self._nd==3:
            mode = 'trilinear'
        elif self._nd==1:
            mode = 'linear'
        else:
            mode = 'nearest'
        
        x = F.upsample(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 21,21
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        x = F.upsample(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 41,41
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        x = F.upsample(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 81,81
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        x = F.upsample(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 161,161
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        x = F.upsample(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 321,321
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        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
        
        if self._nd==2:
            mode = 'bilinear'
        elif self._nd==3:
            mode = 'trilinear'
        elif self._nd==1:
            mode = 'linear'
        else:
            mode = 'nearest'
        
        x = F.interpolate(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 21,21
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        x = F.interpolate(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 41,41
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        x = F.interpolate(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 81,81
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        x = F.interpolate(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 161,161
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        x = F.interpolate(x,scale_factor=2, mode=mode)
        if self._nd==2:
            x = x[:,:,:-1,:-1] # -,-, 321,321
        if self._nd==3:
            x = x[:,:,:-1,:-1,:-1]

        return x
//  [python]
def forward(self, input, class_id=None):
        out = input

        if self.bn:
            out = self.norm1(out, class_id,emb=self.emb)
        out = self.activation(out)
        if self.upsample:
            out = F.upsample(out, scale_factor=2)
        out = self.conv1(out)
        if self.bn:
            out = self.norm2(out, class_id,emb=self.emb)
        out = self.activation(out)
        out = self.conv2(out)

        if self.downsample:
            out = F.avg_pool2d(out, 2)

        if self.skip_proj:
            skip = input
            if self.upsample:
                skip = F.upsample(skip, scale_factor=2)
            skip = self.conv_skip(skip)
            if self.downsample:
                skip = F.avg_pool2d(skip, 2)

        else:
            skip = input

        return out + skip
//  [python]
def forward(self, input, class_id=None):
        out = input

        if self.bn:
            out = self.norm1(out, class_id,emb=self.emb)
        out = self.activation(out)
        if self.upsample:
            out = F.interpolate(out, scale_factor=2)
        out = self.conv1(out)
        if self.bn:
            out = self.norm2(out, class_id,emb=self.emb)
        out = self.activation(out)
        out = self.conv2(out)

        if self.downsample:
            out = F.avg_pool2d(out, 2)

        if self.skip_proj:
            skip = input
            if self.upsample:
                skip = F.interpolate(skip, scale_factor=2)
            skip = self.conv_skip(skip)
            if self.downsample:
                skip = F.avg_pool2d(skip, 2)

        else:
            skip = input

        return out + skip
//  [python]
def forward(self, x):
        output = x
        for layer in self.layers:
            output = layer(output)
        output = self.project_layer(output)
        output = F.upsample(output, scale_factor=8, mode='bilinear')
        if not self.training:
            output = F.upsample(output, scale_factor=2, mode='bilinear')
        return output
//  [python]
def forward(self, x):
        output = x
        for layer in self.layers:
            output = layer(output)
        output = self.project_layer(output)
        output = F.interpolate(output, scale_factor=8, mode='bilinear')
        if not self.training:
            output = F.interpolate(output, scale_factor=2, mode='bilinear')
        return output
//  [python]
def do_forward(self, feat, up8X):
        ## x, y should be normalized
        n, c, w, h = feat.size()
        x = self.conv1(feat)
        x = self.bn1(x)
        x = self.relu(x)
        
        x = self.conv2(x)
        x = self.bn2(x)
        x = self.relu(x)
        
        x = self.conv3(x)
        x = self.bn3(x)
        x = self.relu(x)
        
        x = self.conv4(x)
        
        
        x = self.sigmoid(x)
        
        x = F.upsample_bilinear(x, size=None, scale_factor=8) if up8X else x
        
        return x
//  [python]
def do_forward(self, feat, up8X):
        ## x, y should be normalized
        n, c, w, h = feat.size()
        x = self.conv1(feat)
        x = self.bn1(x)
        x = self.relu(x)
        
        x = self.conv2(x)
        x = self.bn2(x)
        x = self.relu(x)
        
        x = self.conv3(x)
        x = self.bn3(x)
        x = self.relu(x)
        
        x = self.conv4(x)
        
        
        x = self.sigmoid(x)
        
        x = F.interpolate(x, size=None, scale_factor=8, mode='bilinear') if up8X else x
        
        return x
//  [python]
def do_forward(self, coef, up8X):
        ## x, y should be normalized
        n, c, w, h = coef.size()
        x = self.conv1(coef)
        x = self.bn1(x)
        x = self.relu(x)
        
        x = self.conv2(x)
        x = self.bn2(x)
        x = self.relu(x)
        
        x = self.conv3(x)
        x = self.bn3(x)
        x = self.relu(x)
        
        x = self.conv4(x)
        
        ## scale the similarity term and do softmax (self.heat is learnt as well) 
        x = self.softmax(x)
        
        ## flow 
        flowX = torch.sum(x * self.gridX, dim=1, keepdim=True) / h * 2
        flowY = torch.sum(x * self.gridY, dim=1, keepdim=True) / w * 2
        flow = torch.cat((flowX, flowY), dim=1)
        flow = F.upsample_bilinear(flow, size=None, scale_factor=8) if up8X else flow
        
        return flow
//  [python]
def do_forward(self, coef, up8X):
        ## x, y should be normalized
        n, c, w, h = coef.size()
        x = self.conv1(coef)
        x = self.bn1(x)
        x = self.relu(x)
        
        x = self.conv2(x)
        x = self.bn2(x)
        x = self.relu(x)
        
        x = self.conv3(x)
        x = self.bn3(x)
        x = self.relu(x)
        
        x = self.conv4(x)
        
        ## scale the similarity term and do softmax (self.heat is learnt as well) 
        x = self.softmax(x)
        
        ## flow 
        flowX = torch.sum(x * self.gridX, dim=1, keepdim=True) / h * 2
        flowY = torch.sum(x * self.gridY, dim=1, keepdim=True) / w * 2
        flow = torch.cat((flowX, flowY), dim=1)
        flow = F.interpolate(flow, size=None, scale_factor=8, mode='bilinear') if up8X else flow
        
        return flow
//  [python]
def forward(self, x, alpha, **kwargs):
        img_size = x.shape[-1]
        if img_size < 128:
            x = F.upsample_bilinear(x, size=128)
        if kwargs.get('instance_noise', 0) > 0:
            x = x + torch.randn_like(x) * kwargs['instance_noise']
        for i, layer in enumerate(self.layers):
            if global_cfg.tl_debug:
                VerboseModel.forward_verbose(layer, inputs_args=(x.clone(),), submodels=['network', 'proj'], name_prefix=f'layers[{i}].')
            x = layer(x)
        x = F.adaptive_avg_pool2d(x, output_size=1)
        x = x.flatten(1)
        if global_cfg.tl_debug:
            VerboseModel.forward_verbose(self.final_layer, inputs_args=(x,), name_prefix=f'final_layer.')
        x = self.final_layer(x).reshape(x.shape[0], -1)
        prediction = x[..., 0:1]
        latent = x[..., 1:1 + self.dim_z]
        position = x[..., 1 + self.dim_z:]
        return prediction, latent, position
//  [python]
def forward(self, x, alpha, **kwargs):
        img_size = x.shape[-1]
        if img_size < 128:
            x = F.interpolate(x, size=128, mode='bilinear')
        if kwargs.get('instance_noise', 0) > 0:
            x = x + torch.randn_like(x) * kwargs['instance_noise']
        for i, layer in enumerate(self.layers):
            if global_cfg.tl_debug:
                VerboseModel.forward_verbose(layer, inputs_args=(x.clone(),), submodels=['network', 'proj'], name_prefix=f'layers[{i}].')
            x = layer(x)
        x = F.adaptive_avg_pool2d(x, output_size=1)
        x = x.flatten(1)
        if global_cfg.tl_debug:
            VerboseModel.forward_verbose(self.final_layer, inputs_args=(x,), name_prefix=f'final_layer.')
        x = self.final_layer(x).reshape(x.shape[0], -1)
        prediction = x[..., 0:1]
        latent = x[..., 1:1 + self.dim_z]
        position = x[..., 1 + self.dim_z:]
        return prediction, latent, position
//  [python]
def forward(self, input):
        input_size = input.size()
        sx = self.saptial_path(input)
        cx1, cx2, tail = self.context_path(input)
        cx1 = self.attention_refinement_module1(cx1)
        cx2 = self.attention_refinement_module2(cx2)
        cx2 = torch.mul(cx2, tail)
        cx1 = F.upsample_bilinear(cx1, (input_size[2] // 8, input_size[3] // 8))
        cx2 = F.upsample_bilinear(cx2, (input_size[2] // 8, input_size[3] // 8))
        cx = torch.cat((cx1, cx2), dim=1)
        result = self.feature_fusion_module(sx, cx)
        result = F.upsample_bilinear(result, scale_factor=8)
        result = self.conv(result)
        return result
//  [python]
def forward(self, input):
        input_size = input.size()
        sx = self.saptial_path(input)
        cx1, cx2, tail = self.context_path(input)
        cx1 = self.attention_refinement_module1(cx1)
        cx2 = self.attention_refinement_module2(cx2)
        cx2 = torch.mul(cx2, tail)
        cx1 = F.interpolate(cx1, size=(input_size[2] // 8, input_size[3] // 8), mode='bilinear')
        cx2 = F.interpolate(cx2, size=(input_size[2] // 8, input_size[3] // 8), mode='bilinear')
        cx = torch.cat((cx1, cx2), dim=1)
        result = self.feature_fusion_module(sx, cx)
        result = F.interpolate(result, scale_factor=8, mode='bilinear')
        result = self.conv(result)
        return result
//  [python]
def forward(self, x):
        x_size = x.size()
        x_conv1 = self.conv1(x)
        x = self.bn1(x_conv1)
        x = self.relu(x)
        x_pool = self.maxpool(x)
        x_layer1 = self.layer1(x_pool)
        x_layer2 = self.layer2(x_layer1)
        x = self.layer3(x_layer2)
        x = self.layer4(x)
        x_sem = self.out_conv(x)
        x_sem = F.upsample_bilinear(x_sem, x_size[2:])
        x_det = self.layer5(x)
        x_det = self.conv_end(x_det)
        x_det = self.bn_end(x_det)
        x_det = F.sigmoid(x_det)
        x_det = x_det.permute(0, 2, 3, 1)
        return x_sem, x_det
//  [python]
def forward(self, x):
        x_size = x.size()
        x_conv1 = self.conv1(x)
        x = self.bn1(x_conv1)
        x = self.relu(x)
        x_pool = self.maxpool(x)
        x_layer1 = self.layer1(x_pool)
        x_layer2 = self.layer2(x_layer1)
        x = self.layer3(x_layer2)
        x = self.layer4(x)
        x_sem = self.out_conv(x)
        x_sem = F.interpolate(x_sem, x_size[2:], mode='bilinear')
        x_det = self.layer5(x)
        x_det = self.conv_end(x_det)
        x_det = self.bn_end(x_det)
        x_det = F.sigmoid(x_det)
        x_det = x_det.permute(0, 2, 3, 1)
        return x_sem, x_det
//  [python]
def forward(self, x):
        conv1 = self.conv1_block(x)
        conv2 = self.conv2_block(conv1)
        conv3 = self.conv3_block(conv2)
        conv4 = self.conv4_block(conv3)
        conv5 = self.conv5_block(conv4)
        score = self.classifier(conv5)
        if self.module_type == '16s' or self.module_type == '8s':
            score_pool4 = self.score_pool4(conv4)
        if self.module_type == '8s':
            score_pool3 = self.score_pool3(conv3)
        if self.module_type == '16s' or self.module_type == '8s':
            score = F.upsample_bilinear(score, score_pool4.size()[2:])
            score += score_pool4
        if self.module_type == '8s':
            score = F.upsample_bilinear(score, score_pool3.size()[2:])
            score += score_pool3
        out = F.upsample_bilinear(score, x.size()[2:])
        return out
//  [python]
def forward(self, x):
        conv1 = self.conv1_block(x)
        conv2 = self.conv2_block(conv1)
        conv3 = self.conv3_block(conv2)
        conv4 = self.conv4_block(conv3)
        conv5 = self.conv5_block(conv4)
        score = self.classifier(conv5)
        if self.module_type == '16s' or self.module_type == '8s':
            score_pool4 = self.score_pool4(conv4)
        if self.module_type == '8s':
            score_pool3 = self.score_pool3(conv3)
        if self.module_type == '16s' or self.module_type == '8s':
            score = F.interpolate(score, size=score_pool4.size()[2:], mode='bilinear', align_corners=True)
            score += score_pool4
        if self.module_type == '8s':
            score = F.interpolate(score, size=score_pool3.size()[2:], mode='bilinear', align_corners=True)
            score += score_pool3
        out = F.interpolate(score, size=x.size()[2:], mode='bilinear', align_corners=True)
        return out
//  [python]
def forward(self, y, z):
        x = torch.cat([y, nn.MaxPool2d(self.scale, self.scale)(z)], dim=1)
        y_prime = self.conv1(x)
        y_prime = self.conv2(y_prime)
        x = self.conv_res(y_prime)
        upsample_size = torch.Size([(_s * self.scale) for _s in y_prime.shape[-2:]])
        x = F.upsample(x, size=upsample_size, mode='nearest')
        z_prime = z + x
        return y_prime, z_prime
//  [python]
def forward(self, y, z):
        x = torch.cat([y, nn.MaxPool2d(self.scale, self.scale)(z)], dim=1)
        y_prime = self.conv1(x)
        y_prime = self.conv2(y_prime)
        x = self.conv_res(y_prime)
        upsample_size = torch.Size([(_s * self.scale) for _s in y_prime.shape[-2:]])
        x = F.interpolate(x, size=upsample_size, mode='nearest')
        z_prime = z + x
        return y_prime, z_prime
//  [python]
def forward(self, Rf, Mf):
        Mf_size = Mf.size()
        mf = self.conv_M2m(Mf)
        rf = torch.cat((mf[:, :, :Rf.shape[2], :Rf.shape[3]], Rf), 1)
        rf = self.conv_R2r(rf)
        out = F.upsample_bilinear(rf, Mf_size[2:])
        return out
//  [python]
def forward(self, x):
        output_slices = [x]
        h, w = x.view()[2:]
        for module, pool_size in zip(self.path_module_list, self.pool_sizes):
            out = F.avg_pool2d(x, pool_size, stride=1, padding=0)
            out = module(out)
            out = F.upsample(out, size=(h, w), mode='bilinear')
            output_slices.append(out)
        return torch.cat(output_slices, dim=1)
//  [python]
def forward(self, x):
        output_slices = [x]
        h, w = x.view()[2:]
        for module, pool_size in zip(self.path_module_list, self.pool_sizes):
            out = F.avg_pool2d(x, pool_size, stride=1, padding=0)
            out = module(out)
            out = F.interpolate(out, size=(h, w), mode='bilinear')
            output_slices.append(out)
        return torch.cat(output_slices, dim=1)
//  [python]
def forward(self, x):
        x_size = x.size()[2:]
        x_conv1 = self.conv1(x)
        x = self.bn1(x_conv1)
        x = self.relu(x)
        x = self.maxpool(x)
        x_layer1 = self.layer1(x)
        x_layer2 = self.layer2(x_layer1)
        x_layer3 = self.layer3(x_layer2)
        x = self.layer4(x_layer3)
        score = self.classifier(x)
        if self.module_type == '16s' or self.module_type == '8s':
            score_pool4 = self.score_pool4(x_layer3)
        if self.module_type == '8s':
            score_pool3 = self.score_pool3(x_layer2)
        if self.module_type == '16s' or self.module_type == '8s':
            if self.upsample_method == 'upsample_bilinear':
                score = F.upsample_bilinear(score, score_pool4.size()[2:])
            elif self.upsample_method == 'ConvTranspose2d':
                score = self.upsample_1(score)
            score += score_pool4
        if self.module_type == '8s':
            if self.upsample_method == 'upsample_bilinear':
                score = F.upsample_bilinear(score, score_pool3.size()[2:])
            elif self.upsample_method == 'ConvTranspose2d':
                score = self.upsample_2(score)
            score += score_pool3
        out = F.upsample_bilinear(score, x_size)
        return out
//  [python]
def forward(self, x):
        x_size = x.size()[2:]
        x_conv1 = self.conv1(x)
        x = self.bn1(x_conv1)
        x = self.relu(x)
        x = self.maxpool(x)
        x_layer1 = self.layer1(x)
        x_layer2 = self.layer2(x_layer1)
        x_layer3 = self.layer3(x_layer2)
        x = self.layer4(x_layer3)
        score = self.classifier(x)
        if self.module_type == '16s' or self.module_type == '8s':
            score_pool4 = self.score_pool4(x_layer3)
        if self.module_type == '8s':
            score_pool3 = self.score_pool3(x_layer2)
        if self.module_type == '16s' or self.module_type == '8s':
            if self.upsample_method == 'upsample_bilinear':
                score = F.interpolate(score, size=score_pool4.size()[2:], mode='bilinear')
            elif self.upsample_method == 'ConvTranspose2d':
                score = self.upsample_1(score)
            score += score_pool4
        if self.module_type == '8s':
            if self.upsample_method == 'upsample_bilinear':
                score = F.interpolate(score, size=score_pool3.size()[2:], mode='bilinear')
            elif self.upsample_method == 'ConvTranspose2d':
                score = self.upsample_2(score)
            score += score_pool3
        out = F.interpolate(score, size=x_size, mode='bilinear')
        return out
//  [python]
def forward(self, x):
        x_size = x.size()[2:]
        features = []
        for name, module in self.shufflenet._modules.items()[:-1]:
            if name in ['stage3', 'stage4']:
                features.append(x)
            x = module(x)
        score = self.classifier(x)
        if self.module_type == '16s' or self.module_type == '8s':
            score_16s_out = self.score_16s_conv(features[1])
        if self.module_type == '8s':
            score_8s_out = self.score_8s_conv(features[0])
        if self.module_type == '16s' or self.module_type == '8s':
            if self.upsample_method == 'upsample_bilinear':
                score = F.upsample_bilinear(score, score_16s_out.size()[2:])
            elif self.upsample_method == 'ConvTranspose2d':
                score = self.upsample_1(score)
            score += score_16s_out
        if self.module_type == '8s':
            if self.upsample_method == 'upsample_bilinear':
                score = F.upsample_bilinear(score, score_8s_out.size()[2:])
            elif self.upsample_method == 'ConvTranspose2d':
                score = self.upsample_2(score)
            score += score_8s_out
        out = F.upsample_bilinear(score, x_size)
        return out
//  [python]
def forward(self, x):
        x_size = x.size()[2:]
        features = []
        for name, module in self.shufflenet._modules.items()[:-1]:
            if name in ['stage3', 'stage4']:
                features.append(x)
            x = module(x)
        score = self.classifier(x)
        if self.module_type == '16s' or self.module_type == '8s':
            score_16s_out = self.score_16s_conv(features[1])
        if self.module_type == '8s':
            score_8s_out = self.score_8s_conv(features[0])
        if self.module_type == '16s' or self.module_type == '8s':
            if self.upsample_method == 'upsample_bilinear':
                score = F.interpolate(score, size=score_16s_out.size()[2:], mode='bilinear')
            elif self.upsample_method == 'ConvTranspose2d':
                score = self.upsample_1(score)
            score += score_16s_out
        if self.module_type == '8s':
            if self.upsample_method == 'upsample_bilinear':
                score = F.interpolate(score, size=score_8s_out.size()[2:], mode='bilinear')
            elif self.upsample_method == 'ConvTranspose2d':
                score = self.upsample_2(score)
            score += score_8s_out
        out = F.interpolate(score, size=x_size, mode='bilinear')
        return out
//  [python]
def forward(self, x):
        x = self.conv1(x)
        for i in range(3):
            x = self.up_residual_units[i](x)
        y = x
        z = self.split_conv(x)
        prev_channels = 48
        for n_blocks, channels, scale in self.encoder_frru_specs:
            y_pooled = F.max_pool2d(y, stride=2, kernel_size=2, padding=0)
            for block in range(n_blocks):
                key = '_'.join(map(str, ['encoding_frru', n_blocks, channels, scale, block]))
                y, z = getattr(self, key)(y_pooled, z)
            prev_channels = channels
        for n_blocks, channels, scale in self.decoder_frru_specs:
            upsample_size = torch.Size([(_s * 2) for _s in y.size()[-2:]])
            y_upsampled = F.upsample(y, size=upsample_size, mode='bilinear', align_corners=True)
            for block in range(n_blocks):
                key = '_'.join(map(str, ['decoding_frru', n_blocks, channels, scale, block]))
                y, z = getattr(self, key)(y_upsampled, z)
            prev_channels = channels
        x = torch.cat([F.upsample(y, scale_factor=2, mode='bilinear', align_corners=True), z], dim=1)
        x = self.merge_conv(x)
        for i in range(3):
            x = self.down_residual_units[i](x)
        x = self.classif_conv(x)
        return x
//  [python]
def forward(self, x):
        x = self.conv1(x)
        for i in range(3):
            x = self.up_residual_units[i](x)
        y = x
        z = self.split_conv(x)
        prev_channels = 48
        for n_blocks, channels, scale in self.encoder_frru_specs:
            y_pooled = F.max_pool2d(y, stride=2, kernel_size=2, padding=0)
            for block in range(n_blocks):
                key = '_'.join(map(str, ['encoding_frru', n_blocks, channels, scale, block]))
                y, z = getattr(self, key)(y_pooled, z)
            prev_channels = channels
        for n_blocks, channels, scale in self.decoder_frru_specs:
            upsample_size = torch.Size([(_s * 2) for _s in y.size()[-2:]])
            y_upsampled = F.interpolate(y, size=upsample_size, mode='bilinear', align_corners=True)
            for block in range(n_blocks):
                key = '_'.join(map(str, ['decoding_frru', n_blocks, channels, scale, block]))
                y, z = getattr(self, key)(y_upsampled, z)
            prev_channels = channels
        x = torch.cat([F.interpolate(y, scale_factor=2, mode='bilinear', align_corners=True), z], dim=1)
        x = self.merge_conv(x)
        for i in range(3):
            x = self.down_residual_units[i](x)
        x = self.classif_conv(x)
        return x
//  [python]
def forward(self, x):
        inp_shape = x.size()[2:]
        x = self.convbnrelu1_3(self.convbnrelu1_2(self.convbnrelu1_1(x)))
        x = F.max_pool2d(x, 3, 2, 1)
        x = self.res_block5(self.res_block4(self.res_block3(self.res_block2(x))))
        x = self.pyramid_pooling(x)
        x = F.dropout2d(self.cbr_final(x), p=0.1, inplace=True)
        x = self.classification(x)
        x = F.upsample(x, size=inp_shape, mode='bilinear')
        return x
//  [python]
def forward(self, x):
        inp_shape = x.size()[2:]
        x = self.convbnrelu1_3(self.convbnrelu1_2(self.convbnrelu1_1(x)))
        x = F.max_pool2d(x, 3, 2, 1)
        x = self.res_block5(self.res_block4(self.res_block3(self.res_block2(x))))
        x = self.pyramid_pooling(x)
        x = F.dropout2d(self.cbr_final(x), p=0.1, inplace=True)
        x = self.classification(x)
        x = F.interpolate(x, size=inp_shape, mode='bilinear')
        return x
//  [python]
def forward(self, x_cur, x_prev):
        x = self.upConv(x_cur)
        x = torch.cat([F.upsample_bilinear(x_prev, size=x.size()[2:]), x], 1)
        x = self.conv1(x)
        x = self.conv2(x)
        return x
//  [python]
def forward(self, x_cur, x_prev):
        x = self.upConv(x_cur)
        x = torch.cat([F.interpolate(x_prev, size=x.size()[2:], mode='bilinear'), x], 1)
        x = self.conv1(x)
        x = self.conv2(x)
        return x
//  [python]
def _upsample_like(src, tar):
    """upsample tensor 'src' to have the same spatial size with tensor 'tar'."""
    src = F.upsample(src, size=tar.shape[2:], mode='bilinear')
    return src
//  [python]
def _upsample_like(src, tar):
    """upsample tensor 'src' to have the same spatial size with tensor 'tar'."""
    src = F.interpolate(src, size=tar.shape[2:], mode='bilinear')
    return src