jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def forward(self, x):
        
        input_spatial_dim = x.size()[2:]
        
        x = self.resnet50_32s(x)
        
        x = nn.functional.interpolate(input=x, size=input_spatial_dim, mode='bilinear')
        
        return x
//  [python]
def forward(self, x):
        
        input_spatial_dim = x.size()[2:]
        
        x = self.resnet50_8s(x)
        
        x = nn.functional.upsample_bilinear(input=x, size=input_spatial_dim)
        
        return x
//  [python]
def forward(self, x):
        
        input_spatial_dim = x.size()[2:]
        
        x = self.resnet50_8s(x)
        
        x = nn.functional.interpolate(input=x, size=input_spatial_dim, mode='bilinear')
        
        return x
//  [python]
def forward(self, x):
        
        input_spatial_dim = x.size()[2:]
        
        x = self.resnet18_8s.conv1(x)
        x = self.resnet18_8s.bn1(x)
        x = self.resnet18_8s.relu(x)
        x = self.resnet18_8s.maxpool(x)

        x = self.resnet18_8s.layer1[0](x)
        x = self.resnet18_8s.layer2[0](x)
        x = self.resnet18_8s.layer3[0](x)
        x = self.resnet18_8s.layer4[0](x)
        
        x = self.resnet18_8s.fc(x)
        
        x = nn.functional.upsample_bilinear(input=x, size=input_spatial_dim)
        
        return x
//  [python]
def forward(self, x):
        
        input_spatial_dim = x.size()[2:]
        
        x = self.resnet18_8s.conv1(x)
        x = self.resnet18_8s.bn1(x)
        x = self.resnet18_8s.relu(x)
        x = self.resnet18_8s.maxpool(x)

        x = self.resnet18_8s.layer1[0](x)
        x = self.resnet18_8s.layer2[0](x)
        x = self.resnet18_8s.layer3[0](x)
        x = self.resnet18_8s.layer4[0](x)
        
        x = self.resnet18_8s.fc(x)
        
        x = nn.functional.interpolate(input=x, size=input_spatial_dim, mode='bilinear')
        
        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(final, 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, x.size()[2:], mode='bilinear')
//  [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, input,lr_jacobian):
        lr_jacobian = F.softmin(lr_jacobian.mean(dim=1,keepdim=True), dim=2)
        #lr_jacobian = F.softmax(self.convs1(lr_jacobian), dim=1)
        features = self.feature_extractor(input)  #b,648,n # b,648,n
        #jocb = self.feature_extractor2(input*lr_jacobian)
        #print(lr_jacobian[0])
        upf = self.upsampling(features*lr_jacobian+features) # b,128,4*n

        coord = self.conv1(upf)
        coord = self.conv2(coord)
        return coord + F.upsample_nearest(input,scale_factor=8)
//  [python]
def forward(self, input,lr_jacobian):
        lr_jacobian = F.softmin(lr_jacobian.mean(dim=1,keepdim=True), dim=2)
        #lr_jacobian = F.softmax(self.convs1(lr_jacobian), dim=1)
        features = self.feature_extractor(input)  #b,648,n # b,648,n
        #jocb = self.feature_extractor2(input*lr_jacobian)
        #print(lr_jacobian[0])
        upf = self.upsampling(features*lr_jacobian+features) # b,128,4*n

        coord = self.conv1(upf)
        coord = self.conv2(coord)
        return coord + F.interpolate(input,scale_factor=8,mode='nearest')
//  [python]
def forward2(self, input,lr_jacobian):
        lr_jacobian = F.softmin(lr_jacobian.mean(dim=1,keepdim=True), dim=2)
        #lr_jacobian = F.softmax(self.convs1(lr_jacobian), dim=1)
        features = self.feature_extractor(input)  #b,648,n # b,648,n
        #jocb = self.feature_extractor2(input*lr_jacobian)
        #print(lr_jacobian[0])
        upf = self.upsampling(features*lr_jacobian+features) # b,128,4*n

        coord = self.conv1(upf)
        coord = self.conv2(coord)
        coord = coord + F.upsample_nearest(input, scale_factor=8)
        coord = coord.permute(0, 2, 1).contiguous()
        sampledidx = farthest_point_sample(coord, 1024)
        coord = index_points(coord,sampledidx)
        return coord.permute(0, 2, 1).contiguous()
//  [python]
def forward2(self, input,lr_jacobian):
        lr_jacobian = F.softmin(lr_jacobian.mean(dim=1,keepdim=True), dim=2)
        #lr_jacobian = F.softmax(self.convs1(lr_jacobian), dim=1)
        features = self.feature_extractor(input)  #b,648,n # b,648,n
        #jocb = self.feature_extractor2(input*lr_jacobian)
        #print(lr_jacobian[0])
        upf = self.upsampling(features*lr_jacobian+features) # b,128,4*n

        coord = self.conv1(upf)
        coord = self.conv2(coord)
        coord = coord + F.interpolate(input, scale_factor=8, mode='nearest')
        coord = coord.permute(0, 2, 1).contiguous()
        sampledidx = farthest_point_sample(coord, 1024)
        coord = index_points(coord,sampledidx)
        return coord.permute(0, 2, 1).contiguous()
//  [python]
def forward(self, Rf, Mf):
        Mf_size = Mf.size()
        # print('Rf.shape:', Rf.shape)
        # print('Mf.shape:', Mf.shape)
        mf = self.conv_M2m(Mf)
        # print('mf.shape:', mf.shape)
        # print('Rf.shape:', Rf.shape)
        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, 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.interpolate(rf, size=Mf_size[2:], mode='bilinear')
        return out
//  [python]
def forward(self, image1, image2, iters_lev0=6, iters_lev1=3, test_mode=False):
        image1 = 2 * (image1 / 255.0) - 1.0
        image2 = 2 * (image2 / 255.0) - 1.0
        image1 = image1.contiguous()
        image2 = image2.contiguous()

        with autocast(enabled=False):
            fmap1_32, fmap1_64 = self.fnet1(image1)
            fmap2_32, _ = self.fnet1(image2)
        fmap1 = fmap1_32.float()
        fmap2 = fmap2_32.float()

        corr_fn = CorrBlock(fmap1, fmap2, num_levels=2, radius=4, sz=32)
        coords0, coords1 = self.initialize_flow_4(image1)
        sz = fmap1_32.shape
        self.sz = sz
        four_point_disp = torch.zeros((sz[0], 2, 2, 2)).to(fmap1.device)

        disps = []
        for itr in range(iters_lev0):
            corr = corr_fn(coords1)
            flow = coords1 - coords0
            with autocast(enabled=False):
                delta_four_point = self.update_block_4(corr, flow)
            four_point_disp =  four_point_disp + delta_four_point
            coords1 = self.get_flow_now_4(four_point_disp)
            disps.append(four_point_disp)

        four_point_disp_med = four_point_disp
        flow_med = coords1 - coords0

        flow_med = F.upsample_bilinear(flow_med, None, [4, 4]) * 4
        image2 = warp(image2, flow_med)

        with autocast(enabled=False):
            _, fmap2_64 = self.fnet1(image2)
        fmap1 = fmap1_64.float()
        fmap2 = fmap2_64.float()

        corr_fn = CorrBlock(fmap1, fmap2, num_levels = 2, radius= 4, sz = 32)
        coords0, coords1 = self.initialize_flow_2(image1)
        sz = fmap1.shape
        self.sz = sz
        four_point_disp = torch.zeros((sz[0], 2, 2, 2)).to(fmap1.device)

        for itr in range(iters_lev1):
            corr = corr_fn(coords1)
            flow = coords1 - coords0
            with autocast(enabled=False):
                delta_four_point = self.update_block_2(corr, flow)
            four_point_disp = four_point_disp + delta_four_point
            coords1 = self.get_flow_now_2(four_point_disp)

            four_point_disp_med += delta_four_point
            disps.append(four_point_disp_med)

        return disps[-1], disps
//  [python]
def forward(self, image1, image2, iters_lev0=6, iters_lev1=3, test_mode=False):
        image1 = 2 * (image1 / 255.0) - 1.0
        image2 = 2 * (image2 / 255.0) - 1.0
        image1 = image1.contiguous()
        image2 = image2.contiguous()

        with autocast(enabled=False):
            fmap1_32, fmap1_64 = self.fnet1(image1)
            fmap2_32, _ = self.fnet1(image2)
        fmap1 = fmap1_32.float()
        fmap2 = fmap2_32.float()

        corr_fn = CorrBlock(fmap1, fmap2, num_levels=2, radius=4, sz=32)
        coords0, coords1 = self.initialize_flow_4(image1)
        sz = fmap1_32.shape
        self.sz = sz
        four_point_disp = torch.zeros((sz[0], 2, 2, 2)).to(fmap1.device)

        disps = []
        for itr in range(iters_lev0):
            corr = corr_fn(coords1)
            flow = coords1 - coords0
            with autocast(enabled=False):
                delta_four_point = self.update_block_4(corr, flow)
            four_point_disp =  four_point_disp + delta_four_point
            coords1 = self.get_flow_now_4(four_point_disp)
            disps.append(four_point_disp)

        four_point_disp_med = four_point_disp
        flow_med = coords1 - coords0

        flow_med = F.interpolate(flow_med, scale_factor=[4, 4], mode='bilinear') * 4
        image2 = warp(image2, flow_med)

        with autocast(enabled=False):
            _, fmap2_64 = self.fnet1(image2)
        fmap1 = fmap1_64.float()
        fmap2 = fmap2_64.float()

        corr_fn = CorrBlock(fmap1, fmap2, num_levels = 2, radius= 4, sz = 32)
        coords0, coords1 = self.initialize_flow_2(image1)
        sz = fmap1.shape
        self.sz = sz
        four_point_disp = torch.zeros((sz[0], 2, 2, 2)).to(fmap1.device)

        for itr in range(iters_lev1):
            corr = corr_fn(coords1)
            flow = coords1 - coords0
            with autocast(enabled=False):
                delta_four_point = self.update_block_2(corr, flow)
            four_point_disp = four_point_disp + delta_four_point
            coords1 = self.get_flow_now_2(four_point_disp)

            four_point_disp_med += delta_four_point
            disps.append(four_point_disp_med)

        return disps[-1], disps
//  [python]
def forward(self, input):
        x, low_level_features = self.xception_features(input)
        # print(x.size())
        x1 = self.aspp1(x)
        x2 = self.aspp2(x)
        x3 = self.aspp3(x)
        x4 = self.aspp4(x)
        x5 = self.global_avg_pool(x)
        x5 = F.upsample(x5, size=x4.size()[2:], mode="bilinear", align_corners=True)

        x = torch.cat((x1, x2, x3, x4, x5), dim=1)

        x = self.concat_projection_conv1(x)
        x = self.concat_projection_bn1(x)
        x = self.relu(x)
        # print(x.size())

        low_level_features = self.feature_projection_conv1(low_level_features)
        low_level_features = self.feature_projection_bn1(low_level_features)
        low_level_features = self.relu(low_level_features)

        x = F.upsample(
            x, size=low_level_features.size()[2:], mode="bilinear", align_corners=True
        )
        # print(low_level_features.size())
        # print(x.size())
        x = torch.cat((x, low_level_features), dim=1)
        x = self.decoder(x)
        x = self.semantic(x)
        x = F.upsample(x, size=input.size()[2:], mode="bilinear", align_corners=True)

        return x
//  [python]
def forward(self, input):
        x, low_level_features = self.xception_features(input)
        # print(x.size())
        x1 = self.aspp1(x)
        x2 = self.aspp2(x)
        x3 = self.aspp3(x)
        x4 = self.aspp4(x)
        x5 = self.global_avg_pool(x)
        x5 = F.interpolate(x5, size=x4.size()[2:], mode="bilinear", align_corners=True)

        x = torch.cat((x1, x2, x3, x4, x5), dim=1)

        x = self.concat_projection_conv1(x)
        x = self.concat_projection_bn1(x)
        x = self.relu(x)
        # print(x.size())

        low_level_features = self.feature_projection_conv1(low_level_features)
        low_level_features = self.feature_projection_bn1(low_level_features)
        low_level_features = self.relu(low_level_features)

        x = F.interpolate(
            x, size=low_level_features.size()[2:], mode="bilinear", align_corners=True
        )
        # print(low_level_features.size())
        # print(x.size())
        x = torch.cat((x, low_level_features), dim=1)
        x = self.decoder(x)
        x = self.semantic(x)
        x = F.interpolate(x, size=input.size()[2:], mode="bilinear", align_corners=True)

        return x
//  [python]
def forward(self, x):
        output      = self.firstconv(x)
        output      = self.layer1(output)
        output_raw  = self.layer2(output)
        output      = self.layer3(output_raw)
        output_skip = self.layer4(output)


        output_branch1 = self.branch1(output_skip)
        output_branch1 = F.upsample(output_branch1, (output_skip.size()[2],output_skip.size()[3]),mode='bilinear')

        output_branch2 = self.branch2(output_skip)
        output_branch2 = F.upsample(output_branch2, (output_skip.size()[2],output_skip.size()[3]),mode='bilinear')

        output_branch3 = self.branch3(output_skip)
        output_branch3 = F.upsample(output_branch3, (output_skip.size()[2],output_skip.size()[3]),mode='bilinear')

        output_branch4 = self.branch4(output_skip)
        output_branch4 = F.upsample(output_branch4, (output_skip.size()[2],output_skip.size()[3]),mode='bilinear')

        output_feature = torch.cat((output_raw, output_skip, output_branch4, output_branch3, output_branch2, output_branch1), 1)
        output_feature = self.lastconv(output_feature)

        return output_feature
//  [python]
def forward(self, x):
        output      = self.firstconv(x)
        output      = self.layer1(output)
        output_raw  = self.layer2(output)
        output      = self.layer3(output_raw)
        output_skip = self.layer4(output)


        output_branch1 = self.branch1(output_skip)
        output_branch1 = F.interpolate(output_branch1, (output_skip.size()[2],output_skip.size()[3]),mode='bilinear')

        output_branch2 = self.branch2(output_skip)
        output_branch2 = F.interpolate(output_branch2, (output_skip.size()[2],output_skip.size()[3]),mode='bilinear')

        output_branch3 = self.branch3(output_skip)
        output_branch3 = F.interpolate(output_branch3, (output_skip.size()[2],output_skip.size()[3]),mode='bilinear')

        output_branch4 = self.branch4(output_skip)
        output_branch4 = F.interpolate(output_branch4, (output_skip.size()[2],output_skip.size()[3]),mode='bilinear')

        output_feature = torch.cat((output_raw, output_skip, output_branch4, output_branch3, output_branch2, output_branch1), 1)
        output_feature = self.lastconv(output_feature)

        return output_feature
//  [python]
def align_parallel(calib, scale, im_left, im_right, \
		  			box_left, keypoints, poses):
	''' Dense alignment for multiple objects in parallel for depth enumeration

	Inputs:
		scale: H_im_left/H_origin_img
		im_left, im_right: 1 x 3 x H x W
		box_left: rois x 4 in origin image
		keypoints: rois x 5 (kpt, kpt_type, prob, left_border, right_border in origin image
		poses: rois x 7 (x, y, z, w, h, l, theta)
	Return:
		solve_status: 1 denotes success, 0 denotes faild due to no valid pixel (rois x 1)
		best_dis: aligned disparity in origin image (rois x 1)

	'''
	scale = scale * 2
	im_left = F.upsample(im_left, scale_factor=2, mode='bilinear')
	im_right = F.upsample(im_right, scale_factor=2, mode='bilinear')

	f = calib.p2[0,0]*scale
	bl = (calib.p2[0,3] - calib.p3[0,3])*scale/f
	box_left = box_left*scale
	keypoints = keypoints*scale
	poses = poses
	dis_init = box_left.new(box_left.size(0)).zero_()  # in 1/4 feature map 
	dis_init = f*bl/poses[:,2]
	dis_init = dis_init.cuda()

	# rois x pixels x 3, rois x pixels
	all_uvz, all_weight = sample(calib, scale, im_left.size(2), im_left.size(3), \
									box_left, poses, keypoints[:,3:5])

	solve_status = box_left.new(box_left.size(0)).zero_()
	if torch.sum(all_weight) == 0:
		return solve_status, dis_init

	solve_status = solve_status + 1.0
	solve_status[torch.sum(all_weight,1)==0] = 0

	# initial enumeration
	iter_num = 50
	depth_interval = 0.5
	depth_enum = box_left.new(iter_num, box_left.size(0)).zero_() # 50 x rois
	for i in range(iter_num):
		depth_enum[i] = dis_init.reciprocal()*f*bl - iter_num*depth_interval/2 + depth_interval*i

	depth_enum[depth_enum<1.5] = 1.5
	best_depth = enumeration_depth(im_left, im_right, all_uvz, all_weight, depth_enum, f*bl)
	
	# depth tune
	tune_num = 20
	tune_interval = depth_interval*2.0/tune_num
	tune_depth_enum = box_left.new(tune_num, box_left.size(0)).zero_() # 50 x rois
	for i in range(tune_num):
		tune_depth_enum[i] = best_depth - tune_num*tune_interval/2 + tune_interval*i
		
	best_depth = enumeration_depth(im_left, im_right, all_uvz, all_weight, tune_depth_enum, f*bl)
	
	best_dis = f*bl/(best_depth*scale) + 0.5

	return solve_status, best_dis
//  [python]
def align_parallel(calib, scale, im_left, im_right, \
		  			box_left, keypoints, poses):
	''' Dense alignment for multiple objects in parallel for depth enumeration

	Inputs:
		scale: H_im_left/H_origin_img
		im_left, im_right: 1 x 3 x H x W
		box_left: rois x 4 in origin image
		keypoints: rois x 5 (kpt, kpt_type, prob, left_border, right_border in origin image
		poses: rois x 7 (x, y, z, w, h, l, theta)
	Return:
		solve_status: 1 denotes success, 0 denotes faild due to no valid pixel (rois x 1)
		best_dis: aligned disparity in origin image (rois x 1)

	'''
	scale = scale * 2
	im_left = F.interpolate(im_left, scale_factor=2, mode='bilinear')
	im_right = F.interpolate(im_right, scale_factor=2, mode='bilinear')

	f = calib.p2[0,0]*scale
	bl = (calib.p2[0,3] - calib.p3[0,3])*scale/f
	box_left = box_left*scale
	keypoints = keypoints*scale
	poses = poses
	dis_init = box_left.new(box_left.size(0)).zero_()  # in 1/4 feature map 
	dis_init = f*bl/poses[:,2]
	dis_init = dis_init.cuda()

	# rois x pixels x 3, rois x pixels
	all_uvz, all_weight = sample(calib, scale, im_left.size(2), im_left.size(3), \
									box_left, poses, keypoints[:,3:5])

	solve_status = box_left.new(box_left.size(0)).zero_()
	if torch.sum(all_weight) == 0:
		return solve_status, dis_init

	solve_status = solve_status + 1.0
	solve_status[torch.sum(all_weight,1)==0] = 0

	# initial enumeration
	iter_num = 50
	depth_interval = 0.5
	depth_enum = box_left.new(iter_num, box_left.size(0)).zero_() # 50 x rois
	for i in range(iter_num):
		depth_enum[i] = dis_init.reciprocal()*f*bl - iter_num*depth_interval/2 + depth_interval*i

	depth_enum[depth_enum<1.5] = 1.5
	best_depth = enumeration_depth(im_left, im_right, all_uvz, all_weight, depth_enum, f*bl)
	
	# depth tune
	tune_num = 20
	tune_interval = depth_interval*2.0/tune_num
	tune_depth_enum = box_left.new(tune_num, box_left.size(0)).zero_() # 50 x rois
	for i in range(tune_num):
		tune_depth_enum[i] = best_depth - tune_num*tune_interval/2 + tune_interval*i
		
	best_depth = enumeration_depth(im_left, im_right, all_uvz, all_weight, tune_depth_enum, f*bl)
	
	best_dis = f*bl/(best_depth*scale) + 0.5

	return solve_status, best_dis
//  [python]
def forward(self,x):
        x = self.frontend(x)
        x = self.backend(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.backend(x)
        x = self.output_layer(x)
        x = F.interpolate(x,scale_factor=8)
        return x
//  [python]
def forward(self,x):

        input_size = x.size()
        x = self.layer0(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)

        x = self.ppm(x)
        x = self.final(x)

        upsample = F.upsample_bilinear(x, input_size[2:])


        return self.activation(upsample)
//  [python]
def forward(self,x):

        input_size = x.size()
        x = self.layer0(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)

        x = self.ppm(x)
        x = self.final(x)

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


        return self.activation(upsample)
//  [python]
def forward(self, x):
        dec1 = self.dec1(x)
        dec2 = self.dec2(dec1)
        dec3 = self.dec3(dec2)
        dec4 = self.dec4(dec3)
        dec5 = self.dec5(dec4)
        enc5 = self.enc5(dec5)
        enc4 = self.enc4(torch.cat([dec4, enc5], 1))
        enc3 = self.enc3(torch.cat([dec3, enc4], 1))
        enc2 = self.enc2(torch.cat([dec2, enc3], 1))
        enc1 = self.enc1(torch.cat([dec1, enc2], 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)
        dec5 = self.dec5(dec4)
        enc5 = self.enc5(dec5)
        enc4 = self.enc4(torch.cat([dec4, enc5], 1))
        enc3 = self.enc3(torch.cat([dec3, enc4], 1))
        enc2 = self.enc2(torch.cat([dec2, enc3], 1))
        enc1 = self.enc1(torch.cat([dec1, enc2], 1))

        return F.interpolate(self.final(enc1), x.size()[2:], mode='bilinear', align_corners=True)
//  [python]
def forward(self, x, aleatoric=False):
        x = self.features(x)
        x = F.upsample_bilinear(x, scale_factor=2)
        x = self.reg_layer(x)
        pred = torch.abs(self.pred_layer(x))
        if aleatoric:
            logvar = F.softplus(self.conv_logvar(x))
            return pred, logvar
        return pred
//  [python]
def forward(self, x, aleatoric=False):
        x = self.features(x)
        x = F.interpolate(x, scale_factor=2, mode='bilinear')
        x = self.reg_layer(x)
        pred = torch.abs(self.pred_layer(x))
        if aleatoric:
            logvar = F.softplus(self.conv_logvar(x))
            return pred, logvar
        return pred
//  [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, y):
        '''
            Attention, input size should be the 32x.
        '''
        dec1 = self.feat1(torch.cat([x, y], 1))
        dec2 = self.feat2(dec1)
        dec3 = self.feat3(dec2)
        dec4 = self.feat4(dec3)
        dec5 = self.feat5(dec4)
        enc5 = self.enc5(dec5)
        dec4d = self.enc4D(dec4)
        dec3d = self.enc3D(dec3)
        dec2d = self.enc2D(dec2)

        enc5_up = self.enc5_up(enc5)
        enc4 = self.enc4(torch.cat([enc5_up, dec4d], 1))
        enc4_up = self.enc4_up(enc4)
        enc3 = self.enc3(torch.cat([enc4_up, dec3d], 1))
        enc3_up = self.enc3_up(enc3)
        enc2 = torch.cat([enc3_up, dec2d], 1)

        p1 = self.p1(dec1, enc2)
        p1f = F.upsample_bilinear(p1, x.size()[2:])
        p2 = self.p2(dec1, enc2)
        p2f = F.upsample_bilinear(p2, x.size()[2:])
        p3 = self.p3(dec1, enc2)
        p3f = F.upsample_bilinear(p3, x.size()[2:])
        p4 = self.p4(dec1, enc2)
        p4f = F.upsample_bilinear(p4, x.size()[2:])
        p5 = self.p5(dec1, enc2)
        p5f = F.upsample_bilinear(p5, x.size()[2:])

        return p1f, p2f, p3f, p4f, p5f
//  [python]
def forward(self, x, y):
        '''
            Attention, input size should be the 32x.
        '''
        dec1 = self.feat1(torch.cat([x, y], 1))
        dec2 = self.feat2(dec1)
        dec3 = self.feat3(dec2)
        dec4 = self.feat4(dec3)
        dec5 = self.feat5(dec4)
        enc5 = self.enc5(dec5)
        dec4d = self.enc4D(dec4)
        dec3d = self.enc3D(dec3)
        dec2d = self.enc2D(dec2)

        enc5_up = self.enc5_up(enc5)
        enc4 = self.enc4(torch.cat([enc5_up, dec4d], 1))
        enc4_up = self.enc4_up(enc4)
        enc3 = self.enc3(torch.cat([enc4_up, dec3d], 1))
        enc3_up = self.enc3_up(enc3)
        enc2 = torch.cat([enc3_up, dec2d], 1)

        p1 = self.p1(dec1, enc2)
        p1f = F.interpolate(p1, size=x.size()[2:], mode='bilinear')
        p2 = self.p2(dec1, enc2)
        p2f = F.interpolate(p2, size=x.size()[2:], mode='bilinear')
        p3 = self.p3(dec1, enc2)
        p3f = F.interpolate(p3, size=x.size()[2:], mode='bilinear')
        p4 = self.p4(dec1, enc2)
        p4f = F.interpolate(p4, size=x.size()[2:], mode='bilinear')
        p5 = self.p5(dec1, enc2)
        p5f = F.interpolate(p5, size=x.size()[2:], mode='bilinear')

        return p1f, p2f, p3f, p4f, p5f
//  [python]
def forward(self, x):
        x = F.upsample_nearest(x, size=(12,12))
        x = F.upsample_nearest(x, scale_factor=2)
        return x
//  [python]
def forward(self, x):
        x = F.interpolate(x, size=(12,12), mode='nearest')
        x = F.interpolate(x, scale_factor=2, mode='nearest')
        return x
//  [python]
def rrn_postprocess(self, refined_crops, crop_indices, xyz_img):
        """ Resize the masks to original size.
            Paint the masks in ordered by distance from camera.

            @param refined_crops: a [num_masks x resized_H x resized_W] torch.FloatTensor
            @param crop_indices: a dictionary {str(mask_id) : [x_min, y_min, x_max, y_max] for each mask_id}
            @param xyz_img: a [3 x H x W] torch.FloatTensor

            @return: a [H x W] torch tensor of resized masks
        """
        refined_masks = torch.zeros_like(xyz_img[0,...]) # Shape: [H x W]
        mask_ids = crop_indices.keys()

        sorted_mask_ids = []
        for index, mask_id in enumerate(mask_ids):

            # Resize back to original size
            x_min, y_min, x_max, y_max = crop_indices[mask_id]
            orig_H = y_max - y_min + 1
            orig_W = x_max - x_min + 1
            mask = refined_crops[index].unsqueeze(0).unsqueeze(0).float()
            resized_mask = F.upsample_nearest(mask, (orig_H, orig_W))[0,0]

            # Calculate average depth
            h_idx, w_idx = torch.nonzero(resized_mask).t()
            avg_depth = torch.mean(xyz_img[2, y_min:y_max+1, x_min:x_max+1][h_idx, w_idx])
            sorted_mask_ids.append((index, mask_id, avg_depth))

        sorted_mask_ids = sorted(sorted_mask_ids, key=lambda x : x[2], reverse=True)
        sorted_mask_ids = [x[:2] for x in sorted_mask_ids] # list of tuples: (index, mask_id)

        for index, mask_id in sorted_mask_ids:

            # Resize back to original size
            x_min, y_min, x_max, y_max = crop_indices[mask_id]
            orig_H = y_max - y_min + 1
            orig_W = x_max - x_min + 1
            mask = refined_crops[index].unsqueeze(0).unsqueeze(0).float()
            resized_mask = F.upsample_nearest(mask, (orig_H, orig_W))[0,0]

            # Set refined mask
            h_idx, w_idx = torch.nonzero(resized_mask).t()
            refined_masks[y_min:y_max+1, x_min:x_max+1][h_idx, w_idx] = mask_id

        return refined_masks
//  [python]
def rrn_postprocess(self, refined_crops, crop_indices, xyz_img):
        """ Resize the masks to original size.
            Paint the masks in ordered by distance from camera.

            @param refined_crops: a [num_masks x resized_H x resized_W] torch.FloatTensor
            @param crop_indices: a dictionary {str(mask_id) : [x_min, y_min, x_max, y_max] for each mask_id}
            @param xyz_img: a [3 x H x W] torch.FloatTensor

            @return: a [H x W] tensor of resized masks
        """
        refined_masks = torch.zeros_like(xyz_img[0,...]) # Shape: [H x W]
        mask_ids = crop_indices.keys()

        sorted_mask_ids = []
        for index, mask_id in enumerate(mask_ids):

            # Resize back to original size
            x_min, y_min, x_max, y_max = crop_indices[mask_id]
            orig_H = y_max - y_min + 1
            orig_W = x_max - x_min + 1
            mask = refined_crops[index].unsqueeze(0).unsqueeze(0).float()
            resized_mask = F.interpolate(mask, (orig_H, orig_W), mode='nearest')[0,0]

            # Calculate average depth
            h_idx, w_idx = torch.nonzero(resized_mask).t()
            avg_depth = torch.mean(xyz_img[2, y_min:y_max+1, x_min:x_max+1][h_idx, w_idx])
            sorted_mask_ids.append((index, mask_id, avg_depth))

        sorted_mask_ids = sorted(sorted_mask_ids, key=lambda x : x[2], reverse=True)
        sorted_mask_ids = [x[:2] for x in sorted_mask_ids] # list of tuples: (index, mask_id)

        for index, mask_id in sorted_mask_ids:

            # Resize back to original size
            x_min, y_min, x_max, y_max = crop_indices[mask_id]
            orig_H = y_max - y_min + 1
            orig_W = x_max - x_min + 1
            mask = refined_crops[index].unsqueeze(0).unsqueeze(0).float()
            resized_mask = F.interpolate(mask, (orig_H, orig_W), mode='nearest')[0,0]

            # Set refined mask
            h_idx, w_idx = torch.nonzero(resized_mask).t()
            refined_masks[y_min:y_max+1, x_min:x_max+1][h_idx, w_idx] = mask_id

        return refined_masks
//  [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)

        out = F.upsample_bilinear(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)

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

        return out
//  [python]
def add_noise(x):
    # I use 16x16 to generate noise for 128x128 original resolution. 
    ns = torch.normal(mean=torch.zeros(x.shape[0], x.shape[1], 16, 16)).to(x.device)
    res = F.upsample_bilinear(ns, size=(128, 128))
    # Smoothing after makes the noise look nicer/more natural but might not be necessary
    res = F.avg_pool2d(res, kernel_size=9, stride=1, padding=4) 
    # Roll randomly so the distribution of the noise "centers" is not so regular after upsamling.
    # Also might be unnecessary.
    roll_x = random.choice(range(128))
    roll_y = random.choice(range(128))
    ns = torch.roll(ns, shifts=[roll_x, roll_y], dims=[-2, -1])
    # Normalise to whatever std you want, 0.1 works well for me.
    # Also shouldn't do .mean .std across
    # the batch if applying noise to the whole batch.
    ns = (ns - ns.mean()) / ns.std() * 0.1
    # I only apply the noise in the foreground (brain) since adding noise
    # to the black background is detrimental to the model I think.
    mask = x.sum(dim=1, keepdim=True) > 0
    ns *= mask
    return x + ns
//  [python]
def add_noise(x):
    # I use 16x16 to generate noise for 128x128 original resolution. 
    ns = torch.normal(mean=torch.zeros(x.shape[0], x.shape[1], 16, 16)).to(x.device)
    res = F.interpolate(ns, size=(128, 128), mode='bilinear')
    # Smoothing after makes the noise look nicer/more natural but might not be necessary
    res = F.avg_pool2d(res, kernel_size=9, stride=1, padding=4) 
    # Roll randomly so the distribution of the noise "centers" is not so regular after upsamling.
    # Also might be unnecessary.
    roll_x = random.choice(range(128))
    roll_y = random.choice(range(128))
    ns = torch.roll(ns, shifts=[roll_x, roll_y], dims=[-2, -1])
    # Normalise to whatever std you want, 0.1 works well for me.
    # Also shouldn't do .mean .std across
    # the batch if applying noise to the whole batch.
    ns = (ns - ns.mean()) / ns.std() * 0.1
    # I only apply the noise in the foreground (brain) since adding noise
    # to the black background is detrimental to the model I think.
    mask = x.sum(dim=1, keepdim=True) > 0
    ns *= mask
    return x + ns
//  [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)
        score_pool4 = self.score_pool4(conv4)

        score = F.upsample_bilinear(score, score_pool4.size()[2:])
        score += score_pool4
        out = F.upsample_bilinear(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)
        score_pool4 = self.score_pool4(conv4)

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

        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)
        score_pool4 = self.score_pool4(conv4)
        score_pool3 = self.score_pool3(conv3)

        score = F.upsample_bilinear(score, score_pool4.size()[2:])
        score += score_pool4
        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.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)
        score_pool4 = self.score_pool4(conv4)
        score_pool3 = self.score_pool3(conv3)

        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
        out = F.interpolate(score, size=x.size()[2:], mode='bilinear')

        return out
//  [python]
def forward(self, x,x1,x2,x3):
        ## 256x256
       
        ## Classifier  ##
        
        x4=(self.dense_block4(x))
        x4=self.trans_block4(x4)
        x_4=func.upsample_nearest(x4, scale_factor=2)
        x_4=torch.cat([x_4,x3],1)

        x5=(self.dense_block5(x_4))
        x5=self.trans_block5(x5)
        x_5=func.upsample_nearest(x5, scale_factor=2)
        x_5=torch.cat([x_5,x2],1)

        x6=(self.dense_block6(x_5))
        x6=(self.trans_block6(x6))
        x_6=func.upsample_nearest(x6, scale_factor=2)
        x_6=torch.cat([x_6,x1],1)
       
        return x_5,x_6
//  [python]
def forward(self, x,x1,x2,x3):
        ## 256x256
       
        ## Classifier  ##
        
        x4=(self.dense_block4(x))
        x4=self.trans_block4(x4)
        x_4=func.interpolate(x4, scale_factor=2, mode='nearest')
        x_4=torch.cat([x_4,x3],1)

        x5=(self.dense_block5(x_4))
        x5=self.trans_block5(x5)
        x_5=func.interpolate(x5, scale_factor=2, mode='nearest')
        x_5=torch.cat([x_5,x2],1)

        x6=(self.dense_block6(x_5))
        x6=(self.trans_block6(x6))
        x_6=func.interpolate(x6, scale_factor=2, mode='nearest')
        x_6=torch.cat([x_6,x1],1)
       
        return x_5,x_6
//  [python]
def forward(self, x1):
        globalresize = nn.AdaptiveAvgPool2d((x1.shape[2],x1.shape[3]))

        tmp = F.max_pool2d(x1, kernel_size=2, stride=2)

        x2 = F.leaky_relu(self.conv21(tmp))
        x2 = F.leaky_relu(self.conv22(x2))
        tmp = F.max_pool2d(x2, kernel_size=2, stride=2)

        x3 = F.leaky_relu(self.conv31(tmp))
        x3 = F.leaky_relu(self.conv32(x3))
        x3 = F.leaky_relu(self.conv33(x3))
        tmp = F.max_pool2d(x3, kernel_size=2, stride=2)

        x4 = F.leaky_relu(self.conv41(tmp))
        x4 = F.leaky_relu(self.conv42(x4))
        x4 = F.leaky_relu(self.conv43(x4))
        tmp = F.max_pool2d(x4, kernel_size=2, stride=2)

        x5 = F.leaky_relu(self.conv51(tmp))
        x5 = F.leaky_relu(self.conv52(x5))
        x5 = F.leaky_relu(self.conv53(x5))

        tmp = F.upsample_nearest(x5, scale_factor=2)
        x5 = self.compress5(x5)
        x5 = globalresize(x5)

        x4 = torch.cat((tmp, x4), 1)
        x4 = F.leaky_relu(self.conv43d(x4))
        x4 = F.leaky_relu(self.conv42d(x4))
        x4 = F.leaky_relu(self.conv41d(x4))

        tmp = F.upsample_nearest(x4, scale_factor=2)
        x4 = self.compress4(x4)
        x4 = globalresize(x4)

        x3 = torch.cat((tmp, x3), 1)
        x3 = F.leaky_relu(self.conv33d(x3))
        x3 = F.leaky_relu(self.conv32d(x3))
        x3 = F.leaky_relu(self.conv31d(x3))

        tmp = F.upsample_nearest(x3, scale_factor=2)
        x3 = self.compress3(x3)
        x3 = globalresize(x3)

        x2 = torch.cat((tmp, x2), 1)
        x2 = F.leaky_relu(self.conv22d(x2))
        x2 = F.leaky_relu(self.conv21d(x2))
        x2 = globalresize(x2)

        x1 = torch.cat((x1, x2, x3, x4, x5), 1)
        return x1
//  [python]
def forward(self, x1):
        globalresize = nn.AdaptiveAvgPool2d((x1.shape[2],x1.shape[3]))

        tmp = F.max_pool2d(x1, kernel_size=2, stride=2)

        x2 = F.leaky_relu(self.conv21(tmp))
        x2 = F.leaky_relu(self.conv22(x2))
        tmp = F.max_pool2d(x2, kernel_size=2, stride=2)

        x3 = F.leaky_relu(self.conv31(tmp))
        x3 = F.leaky_relu(self.conv32(x3))
        x3 = F.leaky_relu(self.conv33(x3))
        tmp = F.max_pool2d(x3, kernel_size=2, stride=2)

        x4 = F.leaky_relu(self.conv41(tmp))
        x4 = F.leaky_relu(self.conv42(x4))
        x4 = F.leaky_relu(self.conv43(x4))
        tmp = F.max_pool2d(x4, kernel_size=2, stride=2)

        x5 = F.leaky_relu(self.conv51(tmp))
        x5 = F.leaky_relu(self.conv52(x5))
        x5 = F.leaky_relu(self.conv53(x5))

        tmp = F.interpolate(x5, scale_factor=2, mode='nearest')
        x5 = self.compress5(x5)
        x5 = globalresize(x5)

        x4 = torch.cat((tmp, x4), 1)
        x4 = F.leaky_relu(self.conv43d(x4))
        x4 = F.leaky_relu(self.conv42d(x4))
        x4 = F.leaky_relu(self.conv41d(x4))

        tmp = F.interpolate(x4, scale_factor=2, mode='nearest')
        x4 = self.compress4(x4)
        x4 = globalresize(x4)

        x3 = torch.cat((tmp, x3), 1)
        x3 = F.leaky_relu(self.conv33d(x3))
        x3 = F.leaky_relu(self.conv32d(x3))
        x3 = F.leaky_relu(self.conv31d(x3))

        tmp = F.interpolate(x3, scale_factor=2, mode='nearest')
        x3 = self.compress3(x3)
        x3 = globalresize(x3)

        x2 = torch.cat((tmp, x2), 1)
        x2 = F.leaky_relu(self.conv22d(x2))
        x2 = F.leaky_relu(self.conv21d(x2))
        x2 = globalresize(x2)

        x1 = torch.cat((x1, x2, x3, x4, x5), 1)
        return x1
//  [python]
def forward(self, x):
        x_size = x.size()
        resl = x
        for i in range(len(self.pools_sizes)):
            y = self.convs[i](self.pools[i](x))
            resl = torch.add(resl, F.upsample_bilinear(y, x_size[2:]))
        resl = self.relu(resl)
        return resl
//  [python]
def forward(self, x):
        x_size = x.size()
        resl = x
        for i in range(len(self.pools_sizes)):
            y = self.convs[i](self.pools[i](x))
            resl = torch.add(resl, F.interpolate(y, x_size[2:], mode='bilinear'))
        resl = self.relu(resl)
        return resl
//  [python]
def forward(self, x,x1,x2,x3):
        ## 256x256
      
        x4=(self.dense_block4(x))
        x4=self.trans_block4(x4)
        x_4=func.upsample_nearest(x4, scale_factor=2)
        x_4=torch.cat([x_4,x3],1)

        x5=(self.dense_block5(x_4))
        x5=self.trans_block5(x5)
        x_5=func.upsample_nearest(x5, scale_factor=2)
        x_5=torch.cat([x_5,x2],1)

        x6=(self.dense_block6(x_5))
        x6=(self.trans_block6(x6))
        x_6=func.upsample_nearest(x6, scale_factor=2)
        x_6=torch.cat([x_6,x1],1)
       
        return x_5,x_6
//  [python]
def forward(self, x,x1,x2,x3):
        ## 256x256
      
        x4=(self.dense_block4(x))
        x4=self.trans_block4(x4)
        x_4=func.interpolate(x4, scale_factor=2, mode='nearest')
        x_4=torch.cat([x_4,x3],1)

        x5=(self.dense_block5(x_4))
        x5=self.trans_block5(x5)
        x_5=func.interpolate(x5, scale_factor=2, mode='nearest')
        x_5=torch.cat([x_5,x2],1)

        x6=(self.dense_block6(x_5))
        x6=(self.trans_block6(x6))
        x_6=func.interpolate(x6, scale_factor=2, mode='nearest')
        x_6=torch.cat([x_6,x1],1)
       
        return x_5,x_6
//  [python]
def forward(self, x):
        x1=self.relu(self.norm(self.conv1(x)))
        x1=self.dense_block1(x1)
        x1=self.trans_block1(x1)
        x_1=func.avg_pool2d(x1, 2)
        ###  32x32
        x2=(self.dense_block2(x_1))
        x2=self.trans_block2(x2)
        x_2=func.avg_pool2d(x2, 2)
        ### 16 X 16
        x3=(self.dense_block3(x_2))
        x3=self.trans_block3(x3)
        x_3=func.avg_pool2d(x3, 2)
        ## Classifier  ##
        
        x4=(self.dense_block4(x_3))
        x4=self.trans_block4(x4)
        x_4=func.upsample_nearest(x4, scale_factor=2)
        x_4=torch.cat([x_4,x3],1)

        x5=(self.dense_block5(x_4))
        x5=self.trans_block5(x5)
        x_5=func.upsample_nearest(x5, scale_factor=2)
        x_5=torch.cat([x_5,x2],1)

        x6=(self.dense_block6(x_5))
        x6=(self.trans_block6(x6))
        x_6=func.upsample_nearest(x6, scale_factor=2)
        x_6=torch.cat([x_6,x1],1)
        x_6=(self.dense_block7(x_6))
        x_6=(self.trans_block7(x_6))
        x_6=(self.dense_block8(x_6))
        x_6=(self.trans_block8(x_6))
        x_6=(self.dense_block9(x_6))
        x_6=(self.trans_block9(x_6))
        residual = self.relu(self.refine3(x_6))

        return residual
//  [python]
def forward(self, x):
        x1=self.relu(self.norm(self.conv1(x)))
        x1=self.dense_block1(x1)
        x1=self.trans_block1(x1)
        x_1=func.avg_pool2d(x1, 2)
        ###  32x32
        x2=(self.dense_block2(x_1))
        x2=self.trans_block2(x2)
        x_2=func.avg_pool2d(x2, 2)
        ### 16 X 16
        x3=(self.dense_block3(x_2))
        x3=self.trans_block3(x3)
        x_3=func.avg_pool2d(x3, 2)
        ## Classifier  ##
        
        x4=(self.dense_block4(x_3))
        x4=self.trans_block4(x4)
        x_4=func.interpolate(x4, scale_factor=2, mode='nearest')
        x_4=torch.cat([x_4,x3],1)

        x5=(self.dense_block5(x_4))
        x5=self.trans_block5(x5)
        x_5=func.interpolate(x5, scale_factor=2, mode='nearest')
        x_5=torch.cat([x_5,x2],1)

        x6=(self.dense_block6(x_5))
        x6=(self.trans_block6(x6))
        x_6=func.interpolate(x6, scale_factor=2, mode='nearest')
        x_6=torch.cat([x_6,x1],1)
        x_6=(self.dense_block7(x_6))
        x_6=(self.trans_block7(x_6))
        x_6=(self.dense_block8(x_6))
        x_6=(self.trans_block8(x_6))
        x_6=(self.dense_block9(x_6))
        x_6=(self.trans_block9(x_6))
        residual = self.relu(self.refine3(x_6))

        return residual
//  [python]
def forward(self, x,x1,x2,x3):
        ## 256x256
     
        ## Classifier  ##
        
        x4=(self.dense_block4(x))
        x4=self.trans_block4(x4)
        x_4=func.upsample_nearest(x4, scale_factor=2)
        x_4=torch.cat([x_4,x3],1)

        x5=(self.dense_block5(x_4))
        x5=self.trans_block5(x5)
        x_5=func.upsample_nearest(x5, scale_factor=2)
        x_5=torch.cat([x_5,x2],1)

        x6=(self.dense_block6(x_5))
        x6=(self.trans_block6(x6))
        x_6=func.upsample_nearest(x6, scale_factor=2)
        x_6=torch.cat([x_6,x1],1)
       
        return x_5,x_6
//  [python]
def forward(self, x,x1,x2,x3):
        ## 256x256
     
        ## Classifier  ##
        
        x4=(self.dense_block4(x))
        x4=self.trans_block4(x4)
        x_4=func.interpolate(x4, scale_factor=2, mode='nearest')
        x_4=torch.cat([x_4,x3],1)

        x5=(self.dense_block5(x_4))
        x5=self.trans_block5(x5)
        x_5=func.interpolate(x5, scale_factor=2, mode='nearest')
        x_5=torch.cat([x_5,x2],1)

        x6=(self.dense_block6(x_5))
        x6=(self.trans_block6(x6))
        x_6=func.interpolate(x6, scale_factor=2, mode='nearest')
        x_6=torch.cat([x_6,x1],1)
       
        return x_5,x_6
//  [python]
def cropBox(img, ul, br, resH, resW):
    ul = ul.int()
    br = br.int()
    lenH = max(br[1] - ul[1], (br[0] - ul[0]) * resH / resW)
    lenW = lenH * resW / resH
    if img.dim() == 2:
        img = img[np.newaxis, :]

    newDim = torch.IntTensor((img.size(0), int(lenH), int(lenW)))
    newImg = img[:, ul[1]:, ul[0]:].clone()
    # Crop and Padding
    size = torch.IntTensor((int(br[1] - ul[1]), int(br[0] - ul[0])))
    newImg = SpecialCrop(size, 1)(newImg)
    newImg = Pad(newDim)(newImg)
    # Resize to output
    v_Img = torch.autograd.Variable(newImg)
    v_Img = torch.unsqueeze(v_Img, 0)
    # newImg = F.upsample_bilinear(v_Img, size=(int(resH), int(resW))).data[0]
    if torch.__version__ == '0.4.0a0+32f3bf7' or torch.__version__ == '0.4.0':
        newImg = F.upsample(v_Img, size=(int(resH), int(resW)),
                            mode='bilinear', align_corners=True).data[0]
    else:
        newImg = F.interpolate(v_Img, size=(int(resH), int(resW)),
                               mode='bilinear', align_corners=True).data[0]
    return newImg
//  [python]
def cropBox(img, ul, br, resH, resW):
    ul = ul.int()
    br = br.int()
    lenH = max(br[1] - ul[1], (br[0] - ul[0]) * resH / resW)
    lenW = lenH * resW / resH
    if img.dim() == 2:
        img = img[np.newaxis, :]

    newDim = torch.IntTensor((img.size(0), int(lenH), int(lenW)))
    newImg = img[:, ul[1]:, ul[0]:].clone()
    # Crop and Padding
    size = torch.IntTensor((int(br[1] - ul[1]), int(br[0] - ul[0])))
    newImg = SpecialCrop(size, 1)(newImg)
    newImg = Pad(newDim)(newImg)
    # Resize to output
    v_Img = torch.autograd.Variable(newImg)
    v_Img = torch.unsqueeze(v_Img, 0)
    newImg = F.interpolate(v_Img, size=(int(resH), int(resW)),
                               mode='bilinear', align_corners=True).data[0]
    return newImg