jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def forward_seg_features(self, x, convnext_expansion_scale, range_limit=3):
        outs = []
        for i in range(range_limit):
            x = self.downsample_layers[i](x)
            if convnext_expansion_scale <= 0:
                outs.append(self.stages[i](x))
            else:
                outs.append(F.interpolate(self.stages[i](x), scale_factor=convnext_expansion_scale, mode='bilinear'))
        return outs
//  [python]
def forward(self, x):
        # if x: 512
        fm0 = self.layer0(x)  # 256
        fm1 = self.layer1(fm0)  # 128
        fm2 = self.layer2(fm1)  # 64
        fm3 = self.layer3(fm2)  # 32
        fm4 = self.layer4(fm3)  # 16

        gcfm1 = self.brm1(self.gcm1(fm4))  # 16
        gcfm2 = self.brm2(self.gcm2(fm3))  # 32
        gcfm3 = self.brm3(self.gcm3(fm2))  # 64
        gcfm4 = self.brm4(self.gcm4(fm1))  # 128

        fs1 = self.brm5(F.upsample_bilinear(gcfm1, fm3.size()[2:]) + gcfm2)  # 32
        fs2 = self.brm6(F.upsample_bilinear(fs1, fm2.size()[2:]) + gcfm3)  # 64
        fs3 = self.brm7(F.upsample_bilinear(fs2, fm1.size()[2:]) + gcfm4)  # 128
        fs4 = self.brm8(F.upsample_bilinear(fs3, fm0.size()[2:]))  # 256
        out = self.brm9(F.upsample_bilinear(fs4, self.input_size))  # 512

        return out
//  [python]
def forward(self, x):
        fm0 = self.layer0(x)
        fm1 = self.layer1(fm0)
        fm2 = self.layer2(fm1)
        fm3 = self.layer3(fm2)
        fm4 = self.layer4(fm3)

        gcfm1 = self.brm1(self.gcm1(fm4))
        gcfm2 = self.brm2(self.gcm2(fm3))
        gcfm3 = self.brm3(self.gcm3(fm2))
        gcfm4 = self.brm4(self.gcm4(fm1))

        fs1 = self.brm5(F.interpolate(gcfm1, fm3.size()[2:], mode='bilinear') + gcfm2)
        fs2 = self.brm6(F.interpolate(fs1, fm2.size()[2:], mode='bilinear') + gcfm3)
        fs3 = self.brm7(F.interpolate(fs2, fm1.size()[2:], mode='bilinear') + gcfm4)
        fs4 = self.brm8(F.interpolate(fs3, fm0.size()[2:], mode='bilinear'))
        out = self.brm9(F.interpolate(fs4, self.input_size, mode='bilinear'))

        return out
//  [python]
def forward(self, ad1, ad2, ad3, ad4, ad5):

        # 512 256 128 64 32
        ad5 = self.GC5(ad5)
        ad4 = self.GC4(torch.cat([F.upsample_bilinear(ad5, scale_factor=2), ad4], 1))
        ad3 = self.GC3(torch.cat([F.upsample_bilinear(ad4, scale_factor=2), ad3], 1))
        ad2 = self.GC2(torch.cat([F.upsample_bilinear(ad3, scale_factor=2), ad2], 1))
        ad1 = self.GC1(torch.cat([F.upsample_bilinear(ad2, scale_factor=1), ad1], 1))
        out = self.predection(ad1)
        return ad1, out
//  [python]
def forward(self, ad1, ad2, ad3, ad4, ad5):

        # 512 256 128 64 32
        ad5 = self.GC5(ad5)
        ad4 = self.GC4(torch.cat([F.interpolate(ad5, scale_factor=2, mode='bilinear'), ad4], 1))
        ad3 = self.GC3(torch.cat([F.interpolate(ad4, scale_factor=2, mode='bilinear'), ad3], 1))
        ad2 = self.GC2(torch.cat([F.interpolate(ad3, scale_factor=2, mode='bilinear'), ad2], 1))
        ad1 = self.GC1(torch.cat([F.interpolate(ad2, scale_factor=1, mode='bilinear'), ad1], 1))
        out = self.predection(ad1)
        return ad1, out
//  [python]
def test_upsample(self):
        input1 = torch.empty(3, 3, 4, 2)
        npu_input = input1.npu()

        cpu_output = F.upsample(input1, 4)
        npu_output = F.upsample(npu_input, 4)

        self.assertRtolEqual(cpu_output.detach().numpy(), npu_output.detach().cpu().numpy())
//  [python]
def test_upsample(self):
        input1 = torch.empty(3, 3, 4, 2)
        npu_input = input1.npu()

        cpu_output = F.interpolate(input1, scale_factor=4)
        npu_output = F.interpolate(npu_input, scale_factor=4)

        self.assertRtolEqual(cpu_output.detach().numpy(), npu_output.detach().cpu().numpy())
//  [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 test_upsample_nearest(self):
        input1 = torch.empty(3, 3, 4, 2)
        npu_input = input1.npu()

        cpu_output = F.upsample_nearest(input1, 4)
        npu_output = F.upsample_nearest(npu_input, 4)

        self.assertRtolEqual(cpu_output.detach().numpy(), npu_output.detach().cpu().numpy())
//  [python]
def test_upsample_nearest(self):
        input1 = torch.empty(3, 3, 4, 2)
        npu_input = input1.npu()

        cpu_output = F.interpolate(input1, scale_factor=4, mode='nearest')
        npu_output = F.interpolate(npu_input, scale_factor=4, mode='nearest')

        self.assertRtolEqual(cpu_output.detach().numpy(), npu_output.detach().cpu().numpy())
//  [python]
def forward(self, x):
        out = self.conv1(self.relu(self.bn1(x)))
        if self.droprate > 0:
            out = F.dropout(out, p=self.droprate, inplace=False, training=self.training)
        out = F.upsample_bilinear(out, scale_factor=2)
        return self.conv2(out)
//  [python]
def forward(self, x):
        out = self.conv1(self.relu(self.bn1(x)))
        if self.droprate > 0:
            out = F.dropout(out, p=self.droprate, inplace=False, training=self.training)
        out = F.interpolate(out, scale_factor=2, mode='bilinear')
        return self.conv2(out)
//  [python]
def forward(self, x, y):
    
        x1, x2, x3 = self.ccp_G(x)
        y1, y2, y3 = self.ccp_G(y)

        pr1 = self.pr1(abs(x1-y1))
        pr2 = self.pr2(abs(x2-y2))
        pr3 = self.pr3(abs(x3-y3))
        ccp = self.sgp(torch.cat([
            F.upsample_bilinear(pr1, scale_factor=0.5),
            pr2,
            F.upsample_bilinear(pr3, scale_factor=2)
        ],1))
       
        return ccp
//  [python]
def forward(self, x, y):
    
        x1, x2, x3 = self.ccp_G(x)
        y1, y2, y3 = self.ccp_G(y)

        pr1 = self.pr1(abs(x1-y1))
        pr2 = self.pr2(abs(x2-y2))
        pr3 = self.pr3(abs(x3-y3))
        ccp = self.sgp(torch.cat([
            F.interpolate(pr1, scale_factor=0.5, mode='bilinear'),
            pr2,
            F.interpolate(pr3, scale_factor=2, mode='bilinear')
        ],1))
       
        return ccp
//  [python]
def forward(self, x):
		main_x = self.main_branch(x)
		lite_residual_x = self.lite_residual(x)
		if self.lite_residual_config['downsample_ratio'] is not None:
			lite_residual_x = F.upsample(lite_residual_x, main_x.shape[2:],
			                             mode=self.lite_residual_config['upsample_type'])
		return main_x + lite_residual_x
//  [python]
def forward(self, x):
		main_x = self.main_branch(x)
		lite_residual_x = self.lite_residual(x)
		if self.lite_residual_config['downsample_ratio'] is not None:
			lite_residual_x = F.interpolate(lite_residual_x, main_x.shape[2:],
			                             mode=self.lite_residual_config['upsample_type'])
		return main_x + lite_residual_x
//  [python]
def forward(self, input, upscale = False):
        if input.size(1) > 1:
            feats = self.features(self.input_norm(input.mean(dim = 1, keepdim = True)))
        else:
            feats = self.features(self.input_norm(input))
        if upscale:
            return F.upsample(feats, (input.size(2), input.size(3)),mode='bilinear')
        return feats
//  [python]
def forward(self, input, upscale = False):
        if input.size(1) > 1:
            feats = self.features(self.input_norm(input.mean(dim = 1, keepdim = True)))
        else:
            feats = self.features(self.input_norm(input))
        if upscale:
            return F.interpolate(feats, (input.size(2), input.size(3)),mode='bilinear')
        return feats
//  [python]
def _network(self, x, scale):
        if scale != 1:
            scaled_size = [round(s * scale) for s in x.shape[-2:]]
            x_up = functional.upsample(x, size=scaled_size, mode="bilinear")
        else:
            x_up = x

        x_up = self.body(x_up)
        x_up = self.head(x_up)
        sem_logits = self.cls(x_up)

        del x_up
        return sem_logits
//  [python]
def _network(self, x, scale):
        if scale != 1:
            scaled_size = [round(s * scale) for s in x.shape[-2:]]
            x_up = functional.interpolate(x, size=scaled_size, mode="bilinear")
        else:
            x_up = x

        x_up = self.body(x_up)
        x_up = self.head(x_up)
        sem_logits = self.cls(x_up)

        del x_up
        return sem_logits
//  [python]
def upsample_position_embedding(embed, new_size):
  """Upsample the pretrained embedding to a higher resolution.

  Args:
      embed (torch.Tensor): the pretrained embedding.
      new_size (Tuple[int, int]): the new size of the embedding.

  Returns:
      torch.Tensor: the upsampled embedding.
  """
  # emb size NxD
  first = embed[:1, :]
  embed = embed[1:, :]
  n = embed.size(0)
  d = embed.size(1)
  size = int(np.sqrt(n))
  if size * size != n:
    raise ValueError(f'The size of embed {n} is not a perfect square number.')
  # new_size = size * self.upsample
  embed = embed.permute(1, 0)
  embed = embed.view(1, d, size, size).contiguous()
  embed = F.upsample(
      embed,
      size=new_size,
      mode='bilinear',
  )
  embed = embed.view(d, -1).contiguous()
  embed = embed.permute(1, 0)
  embed = torch.cat([first, embed], 0)
  embed = nn.parameter.Parameter(embed.half())
  return embed
//  [python]
def upsample_position_embedding(embed, new_size):
  """Upsample the pretrained embedding to a higher resolution.

  Args:
      embed (torch.Tensor): the pretrained embedding.
      new_size (Tuple[int, int]): the new size of the embedding.

  Returns:
      torch.Tensor: the upsampled embedding.
  """
  # emb size NxD
  first = embed[:1, :]
  embed = embed[1:, :]
  n = embed.size(0)
  d = embed.size(1)
  size = int(np.sqrt(n))
  if size * size != n:
    raise ValueError(f'The size of embed {n} is not a perfect square number.')
  # new_size = size * self.upsample
  embed = embed.permute(1, 0)
  embed = embed.view(1, d, size, size).contiguous()
  embed = F.interpolate(
      embed,
      size=new_size,
      mode='bilinear',
  )
  embed = embed.view(d, -1).contiguous()
  embed = embed.permute(1, 0)
  embed = torch.cat([first, embed], 0)
  embed = nn.parameter.Parameter(embed.half())
  return embed
//  [python]
def forward(self, x, scales, do_flip=True):
        out_size = x.shape[-2:]
        fusion = self.fusion_cls(x, self.classes)

        for scale in scales:
            # Main orientation
            sem_logits = self._network(x, scale)
            sem_logits = functional.upsample(sem_logits, size=out_size, mode="bilinear")
            fusion.update(sem_logits)

            # Flipped orientation
            if do_flip:
                # Main orientation
                sem_logits = self._network(flip(x, -1), scale)
                sem_logits = functional.upsample(
                    sem_logits, size=out_size, mode="bilinear"
                )
                fusion.update(flip(sem_logits, -1))

        return fusion.output()
//  [python]
def forward(self, x, scales, do_flip=True):
        out_size = x.shape[-2:]
        fusion = self.fusion_cls(x, self.classes)

        for scale in scales:
            # Main orientation
            sem_logits = self._network(x, scale)
            sem_logits = functional.interpolate(sem_logits, size=out_size, mode="bilinear")
            fusion.update(sem_logits)

            # Flipped orientation
            if do_flip:
                # Main orientation
                sem_logits = self._network(flip(x, -1), scale)
                sem_logits = functional.interpolate(
                    sem_logits, size=out_size, mode="bilinear"
                )
                fusion.update(flip(sem_logits, -1))

        return fusion.output()
//  [python]
def __call__(
        self,
        features: torch.Tensor,
        schedule=[1.0, 0.5],
        generator=None,
    ):
        features = self.ldm_transform_latent(features)
        ts = self.round_timesteps(
            torch.arange(0, 1024),
            1024,
            self.n_distilled_steps,
            truncate_start=False,
        )
        shape = (
            features.size(0),
            3,
            8 * features.size(2),
            8 * features.size(3),
        )
        x_start = torch.zeros(shape, device=features.device, dtype=features.dtype)
        schedule_timesteps = [int((1024 - 1) * s) for s in schedule]
        for i in schedule_timesteps:
            t = ts[i].item()
            t_ = torch.tensor([t] * features.shape[0]).to(self.device)
            # noise = torch.randn_like(x_start)
            noise = torch.randn(x_start.shape, dtype=x_start.dtype, generator=generator).to(device=x_start.device)
            x_start = (
                _extract_into_tensor(self.sqrt_alphas_cumprod, t_, x_start.shape) * x_start
                + _extract_into_tensor(self.sqrt_one_minus_alphas_cumprod, t_, x_start.shape) * noise
            )
            c_in = _extract_into_tensor(self.c_in, t_, x_start.shape)

            import torch.nn.functional as F

            from MuseVdiffusers import UNet2DModel

            if isinstance(self.ckpt, UNet2DModel):
                input = torch.concat([c_in * x_start, F.upsample_nearest(features, scale_factor=8)], dim=1)
                model_output = self.ckpt(input, t_).sample
            else:
                model_output = self.ckpt(c_in * x_start, t_, features=features)

            B, C = x_start.shape[:2]
            model_output, _ = torch.split(model_output, C, dim=1)
            pred_xstart = (
                _extract_into_tensor(self.c_out, t_, x_start.shape) * model_output
                + _extract_into_tensor(self.c_skip, t_, x_start.shape) * x_start
            ).clamp(-1, 1)
            x_start = pred_xstart
        return x_start
//  [python]
def __call__(
        self,
        features: torch.Tensor,
        schedule=[1.0, 0.5],
        generator=None,
    ):
        features = self.ldm_transform_latent(features)
        ts = self.round_timesteps(
            torch.arange(0, 1024),
            1024,
            self.n_distilled_steps,
            truncate_start=False,
        )
        shape = (
            features.size(0),
            3,
            8 * features.size(2),
            8 * features.size(3),
        )
        x_start = torch.zeros(shape, device=features.device, dtype=features.dtype)
        schedule_timesteps = [int((1024 - 1) * s) for s in schedule]
        for i in schedule_timesteps:
            t = ts[i].item()
            t_ = torch.tensor([t] * features.shape[0]).to(self.device)
            # noise = torch.randn_like(x_start)
            noise = torch.randn(x_start.shape, dtype=x_start.dtype, generator=generator).to(device=x_start.device)
            x_start = (
                _extract_into_tensor(self.sqrt_alphas_cumprod, t_, x_start.shape) * x_start
                + _extract_into_tensor(self.sqrt_one_minus_alphas_cumprod, t_, x_start.shape) * noise
            )
            c_in = _extract_into_tensor(self.c_in, t_, x_start.shape)

            import torch.nn.functional as F

            from MuseVdiffusers import UNet2DModel

            if isinstance(self.ckpt, UNet2DModel):
                input = torch.concat([c_in * x_start, F.interpolate(features, scale_factor=8, mode='nearest')], dim=1)
                model_output = self.ckpt(input, t_).sample
            else:
                model_output = self.ckpt(c_in * x_start, t_, features=features)

            B, C = x_start.shape[:2]
            model_output, _ = torch.split(model_output, C, dim=1)
            pred_xstart = (
                _extract_into_tensor(self.c_out, t_, x_start.shape) * model_output
                + _extract_into_tensor(self.c_skip, t_, x_start.shape) * x_start
            ).clamp(-1, 1)
            x_start = pred_xstart
        return x_start
//  [python]
def fuse_context_feature(self, x):
        context_target_feature_size = x[0].shape[2:]
        context_features=[]
        for l in range(len(x)):
            context_features.append(F.upsample_bilinear(x[l], context_target_feature_size))
        return self.context_fusion_convs(torch.cat(context_features,dim=1))
//  [python]
def fuse_context_feature(self, x):
        context_target_feature_size = x[0].shape[2:]
        context_features=[]
        for l in range(len(x)):
            context_features.append(F.interpolate(x[l], size=context_target_feature_size, mode='bilinear'))
        return self.context_fusion_convs(torch.cat(context_features,dim=1))
//  [python]
def VMRN_obj_pair_feat_extractor(self, input_imgs, obj_rois, batch_size, obj_num):
        bbox_imgs = torch.Tensor([]).type_as(input_imgs)
        union_bbox_imgs = torch.Tensor([]).type_as(input_imgs)
        for i in range(obj_num.size(0)):
            img_index = i % batch_size
            cur_img = input_imgs[img_index]
            if obj_num[i] <=1 :
                continue
            begin_ind = torch.sum(obj_num[:i])
            cur_obj_bboxes = obj_rois[begin_ind:(begin_ind+obj_num[i])]
            for o1ind in range(obj_num[i]):
                o1_bbox = cur_obj_bboxes[o1ind][1:5].long()
                o1_img = cur_img[:, o1_bbox[1]:o1_bbox[3], o1_bbox[0]:o1_bbox[2]].unsqueeze(0)
                o1_img = F.upsample_bilinear(o1_img, size = [224,224])
                bbox_imgs = torch.cat((bbox_imgs, o1_img), dim = 0)
                for o2ind in range(o1ind + 1, obj_num[i]):
                    o2_bbox = cur_obj_bboxes[o2ind][1:5].long()
                    union_bbox = torch.cat((torch.min(o1_bbox[0:2],o2_bbox[0:2]),
                                            torch.max(o1_bbox[2:4],o2_bbox[2:4])), 0)
                    # 1 x 3 x H x W
                    union_img = cur_img[:, union_bbox[1]:union_bbox[3],
                                union_bbox[0]:union_bbox[2]].unsqueeze(0)
                    union_img = F.upsample_bilinear(union_img, size = [224,224])
                    union_bbox_imgs = torch.cat((union_bbox_imgs, union_img), dim=0)

        bbox_num = bbox_imgs.size(0)
        union_bbox_num = union_bbox_imgs.size(0)
        if isinstance(self.rel_base, nn.ModuleList):
            for k,v in enumerate(self.rel_base):
                bbox_imgs = self.rel_base(bbox_imgs)
                union_bbox_imgs = self.rel_base(union_bbox_imgs)
        else:
            bbox_imgs = self.rel_base(bbox_imgs).reshape(bbox_num, -1)
            union_bbox_imgs = self.rel_base(union_bbox_imgs).reshape(union_bbox_num, -1)

        obj_pair_feats = torch.Tensor([]).type_as(input_imgs)

        union_counter = 0
        for i in range(obj_num.size(0)):
            for o1ind in range(obj_num[i]):
                for o2ind in range(o1ind + 1, obj_num[i]):
                    cur_pair_feat = torch.cat((bbox_imgs[o1ind], bbox_imgs[o2ind],
                                               union_bbox_imgs[union_counter]),dim = 0).unsqueeze(0)
                    obj_pair_feats = torch.cat((obj_pair_feats, cur_pair_feat), dim = 0)
                    if self._isex:
                        cur_pair_feat = torch.cat((bbox_imgs[o2ind], bbox_imgs[o1ind],
                                                   union_bbox_imgs[union_counter]), dim=0).unsqueeze(0)
                        obj_pair_feats = torch.cat((obj_pair_feats, cur_pair_feat), dim=0)
                    union_counter += 1
        return obj_pair_feats
//  [python]
def VMRN_obj_pair_feat_extractor(self, input_imgs, obj_rois, batch_size, obj_num):
        bbox_imgs = torch.Tensor([]).type_as(input_imgs)
        union_bbox_imgs = torch.Tensor([]).type_as(input_imgs)
        for i in range(obj_num.size(0)):
            img_index = i % batch_size
            cur_img = input_imgs[img_index]
            if obj_num[i] <=1 :
                continue
            begin_ind = torch.sum(obj_num[:i])
            cur_obj_bboxes = obj_rois[begin_ind:(begin_ind+obj_num[i])]
            for o1ind in range(obj_num[i]):
                o1_bbox = cur_obj_bboxes[o1ind][1:5].long()
                o1_img = cur_img[:, o1_bbox[1]:o1_bbox[3], o1_bbox[0]:o1_bbox[2]].unsqueeze(0)
                o1_img = F.interpolate(o1_img, size = [224,224], mode='bilinear')
                bbox_imgs = torch.cat((bbox_imgs, o1_img), dim = 0)
                for o2ind in range(o1ind + 1, obj_num[i]):
                    o2_bbox = cur_obj_bboxes[o2ind][1:5].long()
                    union_bbox = torch.cat((torch.min(o1_bbox[0:2],o2_bbox[0:2]),
                                            torch.max(o1_bbox[2:4],o2_bbox[2:4])), 0)
                    # 1 x 3 x H x W
                    union_img = cur_img[:, union_bbox[1]:union_bbox[3],
                                union_bbox[0]:union_bbox[2]].unsqueeze(0)
                    union_img = F.interpolate(union_img, size = [224,224], mode='bilinear')
                    union_bbox_imgs = torch.cat((union_bbox_imgs, union_img), dim=0)

        bbox_num = bbox_imgs.size(0)
        union_bbox_num = union_bbox_imgs.size(0)
        if isinstance(self.rel_base, nn.ModuleList):
            for k,v in enumerate(self.rel_base):
                bbox_imgs = self.rel_base(bbox_imgs)
                union_bbox_imgs = self.rel_base(union_bbox_imgs)
        else:
            bbox_imgs = self.rel_base(bbox_imgs).reshape(bbox_num, -1)
            union_bbox_imgs = self.rel_base(union_bbox_imgs).reshape(union_bbox_num, -1)

        obj_pair_feats = torch.Tensor([]).type_as(input_imgs)

        union_counter = 0
        for i in range(obj_num.size(0)):
            for o1ind in range(obj_num[i]):
                for o2ind in range(o1ind + 1, obj_num[i]):
                    cur_pair_feat = torch.cat((bbox_imgs[o1ind], bbox_imgs[o2ind],
                                               union_bbox_imgs[union_counter]),dim = 0).unsqueeze(0)
                    obj_pair_feats = torch.cat((obj_pair_feats, cur_pair_feat), dim = 0)
                    if self._isex:
                        cur_pair_feat = torch.cat((bbox_imgs[o2ind], bbox_imgs[o1ind],
                                                   union_bbox_imgs[union_counter]), dim=0).unsqueeze(0)
                        obj_pair_feats = torch.cat((obj_pair_feats, cur_pair_feat), dim=0)
                    union_counter += 1
        return obj_pair_feats
//  [python]
def simpleforward(self, x):
        x1 = F.leaky_relu(self.conv12(F.leaky_relu(self.conv11(x))))
        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)
        
        x = F.leaky_relu(self.final2(F.leaky_relu(self.final1(x1))))
        return x
//  [python]
def simpleforward(self, x):
        x1 = F.leaky_relu(self.conv12(F.leaky_relu(self.conv11(x))))
        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)
        
        x = F.leaky_relu(self.final2(F.leaky_relu(self.final1(x1))))
        return x
//  [python]
def forward(self, x):
        size = x.size()[2:]
        #x = self.down(x)  # [1,512,48,48]
        x = self.GA(x)  # [1,512,48,48]
        # local attention
        x = F.upsample(x, size=size, mode="bilinear", align_corners=True)  # [1,512,97,97]
        res = x
        x = self.LD(x)  # [1,512,97,97]
        return x + res
//  [python]
def forward(self, x):
        size = x.size()[2:]
        #x = self.down(x)  # [1,512,48,48]
        x = self.GA(x)  # [1,512,48,48]
        # local attention
        x = F.interpolate(x, size=size, mode="bilinear", align_corners=True)  # [1,512,97,97]
        res = x
        x = self.LD(x)  # [1,512,97,97]
        return x + res
//  [python]
def forward(self, x):
        b, c, h, w = x.size()#[1,512,97,97]
        res1 = x
        res2 = x
        x = self.dconv1(x)#[1,512,48,48]
        x = self.dconv2(x)#[1,512,23,23]
        x = self.dconv3(x)#[1,512,11,11]
        x = F.upsample(x, size=(h, w), mode="bilinear", align_corners=True)#[1,512,97,97]
        x_mask = self.sigmoid_spatial(x)#[1,512,97,97]

        res1 = res1 * x_mask#[1,512,97,97]

        return res2 + res1
//  [python]
def forward(self, x):
        b, c, h, w = x.size()#[1,512,97,97]
        res1 = x
        res2 = x
        x = self.dconv1(x)#[1,512,48,48]
        x = self.dconv2(x)#[1,512,23,23]
        x = self.dconv3(x)#[1,512,11,11]
        x = F.interpolate(x, size=(h, w), mode="bilinear", align_corners=True)#[1,512,97,97]
        x_mask = self.sigmoid_spatial(x)#[1,512,97,97]

        res1 = res1 * x_mask#[1,512,97,97]

        return res2 + res1
//  [python]
def forward(self, x):
        '''
        using sigle conv , thus the ROF is 1, 7, 15,31 for d=1,3,7,15
        :param x:
        :return:
        '''
        size = x.shape[2:]

        image_features = self.mean(x)
        image_features = self.conv(image_features)
        image_features = F.upsample(image_features, size=size, mode='bilinear')

        atrous_block1 = self.ReLU(self.atrous_block1(x))

        atrous_block2 = self.ReLU(self.atrous_block2(x))

        atrous_block4 = self.ReLU(self.atrous_block4(x))

        atrous_block8 = self.ReLU(self.atrous_block8(x))
        # if self.att:
        #     image_features = self.pam(image_features) * image_features
        #     astrous_block1 = self.pam(atrous_block1) * atrous_block1
        #     astrous_block2 = self.pam(atrous_block2) * atrous_block2
        #     astrous_block4 = self.pam(atrous_block4) * atrous_block4
        #     astrous_block8 = self.pam(atrous_block8) * atrous_block8

        net = self.conv_1x1_output(torch.cat([image_features, atrous_block1, atrous_block2,
                                              atrous_block4, atrous_block8], dim=1))
        return net
//  [python]
def forward(self, x):
        '''
        using sigle conv , thus the ROF is 1, 7, 15,31 for d=1,3,7,15
        :param x:
        :return:
        '''
        size = x.shape[2:]

        image_features = self.mean(x)
        image_features = self.conv(image_features)
        image_features = F.interpolate(image_features, size=size, mode='bilinear')

        atrous_block1 = self.ReLU(self.atrous_block1(x))

        atrous_block2 = self.ReLU(self.atrous_block2(x))

        atrous_block4 = self.ReLU(self.atrous_block4(x))

        atrous_block8 = self.ReLU(self.atrous_block8(x))
        # if self.att:
        #     image_features = self.pam(image_features) * image_features
        #     astrous_block1 = self.pam(atrous_block1) * atrous_block1
        #     astrous_block2 = self.pam(atrous_block2) * atrous_block2
        #     astrous_block4 = self.pam(atrous_block4) * atrous_block4
        #     astrous_block8 = self.pam(atrous_block8) * atrous_block8

        net = self.conv_1x1_output(torch.cat([image_features, atrous_block1, atrous_block2,
                                              atrous_block4, atrous_block8], dim=1))
        return net
//  [python]
def forward(self, x):
        # x shape: 512, 16, 16
        x_glob = self.glob(x)  # 256, 1, 1
        x_glob = F.upsample(x_glob, scale_factor=16, mode='bilinear', align_corners=True)  # 256, 16, 16

        d2 = self.down2_1(x)  # 512, 8, 8
        d3 = self.down3_1(d2)  # 512, 4, 4

        d2 = self.down2_2(d2)  # 256, 8, 8
        d3 = self.down3_2(d3)  # 256, 4, 4

        d3 = F.upsample(d3, scale_factor=2, mode='bilinear', align_corners=True)  # 256, 8, 8
        d2 = d2 + d3

        d2 = F.upsample(d2, scale_factor=2, mode='bilinear', align_corners=True)  # 256, 16, 16
        x = self.conv1(x)  # 256, 16, 16
        x = x * d2

        x = x + x_glob

        return x
//  [python]
def forward(self, x):
        # x shape: 512, 16, 16
        x_glob = self.glob(x)  # 256, 1, 1
        x_glob = F.interpolate(x_glob, scale_factor=16, mode='bilinear', align_corners=True)  # 256, 16, 16

        d2 = self.down2_1(x)  # 512, 8, 8
        d3 = self.down3_1(d2)  # 512, 4, 4

        d2 = self.down2_2(d2)  # 256, 8, 8
        d3 = self.down3_2(d3)  # 256, 4, 4

        d3 = F.interpolate(d3, scale_factor=2, mode='bilinear', align_corners=True)  # 256, 8, 8
        d2 = d2 + d3

        d2 = F.interpolate(d2, scale_factor=2, mode='bilinear', align_corners=True)  # 256, 16, 16
        x = self.conv1(x)  # 256, 16, 16
        x = x * d2

        x = x + x_glob

        return x
//  [python]
def forward(self, left_tower, right_tower, input_img, full_res_disparity):

        output = torch.cat([left_tower, right_tower], dim=1)

        for block in self.residual_blocks1:
            
            output = block(output)
        
        Low_Res_invalidation_small = self.conv_end1(output)
        
        pred = Low_Res_invalidation_small * input_img.size()[-1] / Low_Res_invalidation_small.size()[-1]

        Low_Res_invalidation = F.upsample(
                pred,
                size=input_img.size()[-2:],
                mode='bilinear',
                align_corners=False)


        output = torch.cat([input_img, Low_Res_invalidation,full_res_disparity], dim=1)
        output = self.conv_begin(output)
        for block in self.residual_blocks2:
            output = block(output)
        Invalidation_Residual = self.conv_end2(output)

        return Invalidation_Residual + Low_Res_invalidation
//  [python]
def forward(self, left_tower, right_tower, input_img, full_res_disparity):

        output = torch.cat([left_tower, right_tower], dim=1)

        for block in self.residual_blocks1:
            
            output = block(output)
        
        Low_Res_invalidation_small = self.conv_end1(output)
        
        pred = Low_Res_invalidation_small * input_img.size()[-1] / Low_Res_invalidation_small.size()[-1]

        Low_Res_invalidation = F.interpolate(
                pred,
                size=input_img.size()[-2:],
                mode='bilinear',
                align_corners=False)


        output = torch.cat([input_img, Low_Res_invalidation,full_res_disparity], dim=1)
        output = self.conv_begin(output)
        for block in self.residual_blocks2:
            output = block(output)
        Invalidation_Residual = self.conv_end2(output)

        return Invalidation_Residual + Low_Res_invalidation
//  [python]
def forward(self, x):
        skip1 = self.ConvBlock1_1(x)
        down1 = F.avg_pool2d(x, 2)
        down1 = self.ConvBlock1_2(down1)

        skip2 = self.ConvBlock2_1(down1)
        down2 = F.avg_pool2d(down1, 2)
        down2 = self.ConvBlock2_2(down2)

        skip3 = self.ConvBlock3_1(down2)
        down3 = F.avg_pool2d(down2, 2)
        down3 = self.ConvBlock3_2(down3)

        skip4 = self.ConvBlock4_1(down3)
        down4 = F.avg_pool2d(down3, 2)
        down4 = self.ConvBlock4_2(down4)

        center = self.ConvBlock5(down4)

        up4 = self.ConvBlock6(center)
        up4 = F.upsample(up4, scale_factor=2)
        up4 = skip4 + up4

        up3 = self.ConvBlock7(up4)
        up3 = F.upsample(up3, scale_factor=2)
        up3 = skip3 + up3

        up2 = self.ConvBlock8(up3)
        up2 = F.upsample(up2, scale_factor=2)
        up2 = skip2 + up2

        up1 = self.ConvBlock9(up2)
        up1 = F.upsample(up1, scale_factor=2)
        up1 = skip1 + up1

        return up1
//  [python]
def forward(self, x):
        skip1 = self.ConvBlock1_1(x)
        down1 = F.avg_pool2d(x, 2)
        down1 = self.ConvBlock1_2(down1)

        skip2 = self.ConvBlock2_1(down1)
        down2 = F.avg_pool2d(down1, 2)
        down2 = self.ConvBlock2_2(down2)

        skip3 = self.ConvBlock3_1(down2)
        down3 = F.avg_pool2d(down2, 2)
        down3 = self.ConvBlock3_2(down3)

        skip4 = self.ConvBlock4_1(down3)
        down4 = F.avg_pool2d(down3, 2)
        down4 = self.ConvBlock4_2(down4)

        center = self.ConvBlock5(down4)

        up4 = self.ConvBlock6(center)
        up4 = F.interpolate(up4, scale_factor=2)
        up4 = skip4 + up4

        up3 = self.ConvBlock7(up4)
        up3 = F.interpolate(up3, scale_factor=2)
        up3 = skip3 + up3

        up2 = self.ConvBlock8(up3)
        up2 = F.interpolate(up2, scale_factor=2)
        up2 = skip2 + up2

        up1 = self.ConvBlock9(up2)
        up1 = F.interpolate(up1, scale_factor=2)
        up1 = skip1 + up1

        return up1
//  [python]
def forward(self,x):
        x= self.conv1(x) # [16,2,128,128]==>[16,32,65,65]
        x = self.relu1(x)
        x= self.conv2(x) # [16,32,65,65]==>[16,64,33,33]
        x = self.relu2(x)
        x= self.conv3(x) # [16,64,33,33]==>[16,128,17,17]
        x = self.relu3(x)
        x= self.conv4(x) # [16,128,17,17]==>[16,256,9,9]
        x = self.relu4(x)
        x = self.conv5(x) # [16,256,9,9]==>[16,2,5,5]
        # upsample
        x = F.upsample_bilinear(x,scale_factor=2)#[16,2,5,5]==>[16,2,10,10]
        x = x[:,:,:-1,:-1] # #[16,2,10,10]==>[16,2,9,9]

        x = F.upsample_bilinear(x,scale_factor=2)#[16,2,9,9]==>[16,2,18,18]
        x = x[:,:,:-1,:-1] # [16,2,18,18]==>[16,2,17,17]

        x = F.upsample_bilinear(x,scale_factor=2)
        x = x[:,:,:-1,:-1] #[16,2,34,34]==>[16,2,33,33]

        x = F.upsample_bilinear(x,scale_factor=2)
        x = x[:,:,:-1,:-1] #[16,2,66,66]==>[16,2,65,65]

        x = F.upsample_bilinear(x,scale_factor=2)
        x = x[:,:,:-1,:-1] # [16,2,130,130]==>[16,2,129,129]

        return x
//  [python]
def forward(self,x):
        x= self.conv1(x) # [16,2,128,128]==>[16,32,65,65]
        x = self.relu1(x)
        x= self.conv2(x) # [16,32,65,65]==>[16,64,33,33]
        x = self.relu2(x)
        x= self.conv3(x) # [16,64,33,33]==>[16,128,17,17]
        x = self.relu3(x)
        x= self.conv4(x) # [16,128,17,17]==>[16,256,9,9]
        x = self.relu4(x)
        x = self.conv5(x) # [16,256,9,9]==>[16,2,5,5]
        # upsample
        x = F.interpolate(x,scale_factor=2,mode='bilinear')#[16,2,5,5]==>[16,2,10,10]
        x = x[:,:,:-1,:-1] # #[16,2,10,10]==>[16,2,9,9]

        x = F.interpolate(x,scale_factor=2,mode='bilinear')#[16,2,9,9]==>[16,2,18,18]
        x = x[:,:,:-1,:-1] # [16,2,18,18]==>[16,2,17,17]

        x = F.interpolate(x,scale_factor=2,mode='bilinear')
        x = x[:,:,:-1,:-1] #[16,2,34,34]==>[16,2,33,33]

        x = F.interpolate(x,scale_factor=2,mode='bilinear')
        x = x[:,:,:-1,:-1] #[16,2,66,66]==>[16,2,65,65]

        x = F.interpolate(x,scale_factor=2,mode='bilinear')
        x = x[:,:,:-1,:-1] # [16,2,130,130]==>[16,2,129,129]

        return x
//  [python]
def run_layer(self, xyz, feature, layer, skips, os, flag=True):
        new_xyz = xyz
        if flag == True:
            xyz, new_xyz, y = layer[:-3]([xyz, new_xyz, feature])
            y = layer[-3:](y)
            xyz = F.upsample_bilinear(xyz, size=[xyz.size()[2] // 2, xyz.size()[3] // 2])
        else:
            xyz, new_xyz, y = layer([xyz, new_xyz, feature])
        if y.shape[2] < feature.shape[2] or y.shape[3] < feature.shape[3]:
            skips[os] = feature.detach()
            os *= 2
        feature = self.dropout(y)
        return xyz, feature, skips, os
//  [python]
def run_layer(self, xyz, feature, layer, skips, os, flag=True):
        new_xyz = xyz
        if flag == True:
            xyz, new_xyz, y = layer[:-3]([xyz, new_xyz, feature])
            y = layer[-3:](y)
            xyz = F.interpolate(xyz, size=[xyz.size()[2] // 2, xyz.size()[3] // 2], mode='bilinear')
        else:
            xyz, new_xyz, y = layer([xyz, new_xyz, feature])
        if y.shape[2] < feature.shape[2] or y.shape[3] < feature.shape[3]:
            skips[os] = feature.detach()
            os *= 2
        feature = self.dropout(y)
        return xyz, feature, skips, os
//  [python]
def forward(self, left, right):
        disp = (self.maxdisp + 1) // 8
        refimg_feature = self.Siamese_Tower(left)
        targetimg_feature = self.Siamese_Tower(right)
        
        def calculate(refimg_feature, targetimg_feature, img, type):

            # matching
            cost = torch.FloatTensor(refimg_feature.size()[0],
                                    refimg_feature.size()[1],
                                    disp,
                                    refimg_feature.size()[2],
                                    refimg_feature.size()[3]).zero_().cuda()

            if type == 'left':
                for i in range(disp):
                    if i > 0:
                        cost[:, :, i, :, i:] = refimg_feature[ :, :, :, i:] - targetimg_feature[:, :, :, :-i]
                    else: 
                        cost[:, :, i, :, :] = refimg_feature - targetimg_feature

            if type == 'right':
                for i in range(disp):
                    if i > 0:
                        cost[:, :, i, :, :-i] = refimg_feature[ :, :, :, :-i] - targetimg_feature[:, :, :, i:]
                    else: 
                        cost[:, :, i, :, :] = refimg_feature - targetimg_feature
            cost = cost.contiguous()

            for f in self.filter:
                cost = f(cost)
            cost = self.conv3d_alone(cost)
            cost = torch.squeeze(cost, 1)
            pred = F.softmax(cost, dim=1)
            pred = disparityregression(disp)(pred)

            pred = pred * img.size()[-1] / pred.size()[-1]

            res_disparity = F.upsample(
                    torch.unsqueeze(pred, dim=1),
                    size=img.size()[-2:],
                    mode='bilinear',
                    align_corners=False)

            return res_disparity

        res_disparityL = calculate(refimg_feature, targetimg_feature, left, 'left')
        res_disparityR = calculate(targetimg_feature, refimg_feature, right, 'right')

        Full_res_disparityL = self.Disparity_Refinement(res_disparityL, left)
        Full_res_disparityR = self.Disparity_Refinement(res_disparityR, right)
        
        
        # Full_res_invalidation = self.Invalidation_Net(refimg_feature, targetimg_feature, left, Full_res_disparityL)



        return Full_res_disparityL, Full_res_disparityR,  Full_res_disparityR
//  [python]
def forward(self, left, right):
        disp = (self.maxdisp + 1) // 8
        refimg_feature = self.Siamese_Tower(left)
        targetimg_feature = self.Siamese_Tower(right)
        
        def calculate(refimg_feature, targetimg_feature, img, type):

            # matching
            cost = torch.FloatTensor(refimg_feature.size()[0],
                                    refimg_feature.size()[1],
                                    disp,
                                    refimg_feature.size()[2],
                                    refimg_feature.size()[3]).zero_().cuda()

            if type == 'left':
                for i in range(disp):
                    if i > 0:
                        cost[:, :, i, :, i:] = refimg_feature[ :, :, :, i:] - targetimg_feature[:, :, :, :-i]
                    else: 
                        cost[:, :, i, :, :] = refimg_feature - targetimg_feature

            if type == 'right':
                for i in range(disp):
                    if i > 0:
                        cost[:, :, i, :, :-i] = refimg_feature[ :, :, :, :-i] - targetimg_feature[:, :, :, i:]
                    else: 
                        cost[:, :, i, :, :] = refimg_feature - targetimg_feature
            cost = cost.contiguous()

            for f in self.filter:
                cost = f(cost)
            cost = self.conv3d_alone(cost)
            cost = torch.squeeze(cost, 1)
            pred = F.softmax(cost, dim=1)
            pred = disparityregression(disp)(pred)

            pred = pred * img.size()[-1] / pred.size()[-1]

            res_disparity = F.interpolate(
                    torch.unsqueeze(pred, dim=1),
                    size=img.size()[-2:],
                    mode='bilinear',
                    align_corners=False)

            return res_disparity

        res_disparityL = calculate(refimg_feature, targetimg_feature, left, 'left')
        res_disparityR = calculate(targetimg_feature, refimg_feature, right, 'right')

        Full_res_disparityL = self.Disparity_Refinement(res_disparityL, left)
        Full_res_disparityR = self.Disparity_Refinement(res_disparityR, right)
        
        
        # Full_res_invalidation = self.Invalidation_Net(refimg_feature, targetimg_feature, left, Full_res_disparityL)



        return Full_res_disparityL, Full_res_disparityR,  Full_res_disparityR
//  [python]
def forward(self, im_data):
        x1 = self.branch1(im_data)
        x2 = self.branch2(im_data)
        x3 = self.branch3(im_data)
        x = torch.cat((x1,x2,x3),1)
        x = self.fuse(x)
        x = F.upsample(x,scale_factor=4)
        return x
//  [python]
def forward(self, im_data):
        x1 = self.branch1(im_data)
        x2 = self.branch2(im_data)
        x3 = self.branch3(im_data)
        x = torch.cat((x1,x2,x3),1)
        x = self.fuse(x)
        x = F.interpolate(x,scale_factor=4)
        return x
//  [python]
def forward(self, x):
        input = x
        x = self.conv1(x)
        x = self.bn0(x)
        x = self.relu(x)
        conv_x = x
        x = self.maxpool(x)
        pool_x = x

        fm1 = self.layer1(x)
        fm2 = self.layer2(fm1)
        fm3 = self.layer3(fm2)
        fm4 = self.layer4(fm3)

        gcfm1 = self.refine1(self.gcn1(fm4))
        gcfm2 = self.refine2(self.gcn2(fm3))
        gcfm3 = self.refine3(self.gcn3(fm2))
        gcfm4 = self.refine4(self.gcn4(fm1))
        gcfm5 = self.refine5(self.gcn5(pool_x))

        fs1 = self.refine6(F.upsample_bilinear(gcfm1, fm3.size()[2:]) + gcfm2)
        fs2 = self.refine7(F.upsample_bilinear(fs1, fm2.size()[2:]) + gcfm3)
        fs3 = self.refine8(F.upsample_bilinear(fs2, fm1.size()[2:]) + gcfm4)
        fs4 = self.refine9(F.upsample_bilinear(fs3, pool_x.size()[2:]) + gcfm5)
        out = self.refine10(F.upsample_bilinear(fs4, input.size()[2:]))

        return out
//  [python]
def forward(self, x):
        input = x
        x = self.conv1(x)
        x = self.bn0(x)
        x = self.relu(x)
        conv_x = x
        x = self.maxpool(x)
        pool_x = x

        fm1 = self.layer1(x)
        fm2 = self.layer2(fm1)
        fm3 = self.layer3(fm2)
        fm4 = self.layer4(fm3)

        gcfm1 = self.refine1(self.gcn1(fm4))
        gcfm2 = self.refine2(self.gcn2(fm3))
        gcfm3 = self.refine3(self.gcn3(fm2))
        gcfm4 = self.refine4(self.gcn4(fm1))
        gcfm5 = self.refine5(self.gcn5(pool_x))

        fs1 = self.refine6(F.interpolate(gcfm1, size=fm3.size()[2:], mode='bilinear') + gcfm2)
        fs2 = self.refine7(F.interpolate(fs1, size=fm2.size()[2:], mode='bilinear') + gcfm3)
        fs3 = self.refine8(F.interpolate(fs2, size=fm1.size()[2:], mode='bilinear') + gcfm4)
        fs4 = self.refine9(F.interpolate(fs3, size=pool_x.size()[2:], mode='bilinear') + gcfm5)
        out = self.refine10(F.interpolate(fs4, size=input.size()[2:], mode='bilinear'))

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

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

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

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

            if idx == self.last_needed_block:
                break

        return outp