def forward(self, x):
    (b, h, w) = (x.size(0), x.size(2), x.size(3))
    value = self.reduce_conv(x)
    intra_similarity_map = self.intra_similarity_branch(value)
    intra_similarity_map = intra_similarity_map.view(b, (h * w), (- 1))
    intra_similarity_map = intra_similarity_map.permute(0, 2, 1)
    intra_similarity_map = torch.sigmoid(intra_similarity_map)
    inter_similarity_map = (1 - intra_similarity_map)
    value = value.view(b, self.inner_channel, (- 1))
    value = value.permute(0, 2, 1)
    intra_context = torch.bmm(intra_similarity_map, value)
    intra_mask = torch.ge(intra_similarity_map, 0.5).float()
    intra_mask_count = intra_mask.sum(dim=(- 1), keepdim=True)
    intra_mask_count = intra_mask_count.masked_fill_(intra_mask_count.eq(0), 1)
    intra_context = intra_context.div(intra_mask_count)
    intra_context = intra_context.permute(0, 2, 1).contiguous()
    intra_context = intra_context.view(b, self.inner_channel, *x.size()[2:])
    intra_context = self.intra_post_conv(intra_context)
    inter_context = torch.bmm(inter_similarity_map, value)
    inter_mask = torch.ge(inter_similarity_map, 0.5).float()
    inter_mask_count = inter_mask.sum(dim=(- 1), keepdim=True)
    inter_mask_count = inter_mask_count.masked_fill_(inter_mask_count.eq(0), 1)
    inter_context = inter_context.div(inter_mask_count)
    inter_context = inter_context.permute(0, 2, 1).contiguous()
    inter_context = inter_context.view(b, self.inner_channel, *x.size()[2:])
    inter_context = self.inter_post_conv(inter_context)
    output = torch.cat([x, intra_context, inter_context], dim=1)
    return (output, intra_similarity_map)
def forward(self, x):
    (b, h, w) = (x.size(0), x.size(2), x.size(3))
    value = self.reduce_conv(x)
    intra_similarity_map = self.intra_similarity_branch(value)
    intra_similarity_map = intra_similarity_map.view(b, (h * w), (- 1))
    intra_similarity_map = intra_similarity_map.permute(0, 2, 1)
    intra_similarity_map = torch.sigmoid(intra_similarity_map)
    inter_similarity_map = (1 - intra_similarity_map)
    value = value.view(b, self.inner_channel, (- 1))
    value = value.permute(0, 2, 1)
    intra_context = torch.bmm(intra_similarity_map, value)
    intra_mask = torch.ge(intra_similarity_map, 0.5).float()
    intra_mask_count = intra_mask.sum(dim=(- 1), keepdim=True)
    intra_mask_count = intra_mask_count.masked_fill_(intra_mask_count.eq(0), 1)
    intra_context = intra_context.div(intra_mask_count)
    intra_context = intra_context.permute(0, 2, 1).contiguous()
    intra_context = intra_context.view(b, self.inner_channel, *x.size()[2:])
    intra_context = self.intra_post_conv(intra_context)
    inter_context = torch.bmm(inter_similarity_map, value)
    inter_mask = torch.ge(inter_similarity_map, 0.5).float()
    inter_mask_count = inter_mask.sum(dim=(- 1), keepdim=True)
    inter_mask_count = inter_mask_count.masked_fill_(inter_mask_count.eq(0), 1)
    inter_context = inter_context.div(inter_mask_count)
    inter_context = inter_context.permute(0, 2, 1).contiguous()
    inter_context = inter_context.view(b, self.inner_channel, *x.size()[2:])
    inter_context = self.inter_post_conv(inter_context)
    output = torch.cat([x, intra_context, inter_context], dim=1)
    return (output, intra_similarity_map)