def forward(self, feats, labels=None, predict=None):
    labels = labels.unsqueeze(1).float().clone()
    labels = torch.nn.functional.interpolate(labels, (feats.shape[2], feats.shape[3]), mode='nearest')
    labels = labels.squeeze(1).long()
    assert (labels.shape[(- 1)] == feats.shape[(- 1)]), '{} {}'.format(labels.shape, feats.shape)
    batch_size = feats.shape[0]
    labels = labels.contiguous().view(batch_size, (- 1))
    predict = predict.contiguous().view(batch_size, (- 1))
    feats = feats.permute(0, 2, 3, 1)
    feats = feats.contiguous().view(feats.shape[0], (- 1), feats.shape[(- 1)])
    (feats_, labels_) = self._hard_anchor_sampling(feats, labels, predict)
    loss = self._contrastive(feats_, labels_)
    return loss
def forward(self, feats, labels=None, predict=None):
    labels = labels.unsqueeze(1).float().clone()
    labels = torch.nn.functional.interpolate(labels, (feats.shape[2], feats.shape[3]), mode='nearest')
    labels = labels.squeeze(1).long()
    assert (labels.shape[(- 1)] == feats.shape[(- 1)]), '{} {}'.format(labels.shape, feats.shape)
    batch_size = feats.shape[0]
    labels = labels.contiguous().view(batch_size, (- 1))
    predict = predict.contiguous().view(batch_size, (- 1))
    feats = feats.permute(0, 2, 3, 1)
    feats = feats.contiguous().view(feats.shape[0], (- 1), feats.shape[(- 1)])
    (feats_, labels_) = self._hard_anchor_sampling(feats, labels, predict)
    loss = self._contrastive(feats_, labels_)
    return loss