def forward(self, preds, target):
    (h, w) = (target.size(1), target.size(2))
    assert ('seg' in preds)
    assert ('seg_aux' in preds)
    seg = preds['seg']
    seg_aux = preds['seg_aux']
    embedding = (preds['embedding'] if ('embedding' in preds) else None)
    pred = F.interpolate(input=seg, size=(h, w), mode='bilinear', align_corners=True)
    pred_aux = F.interpolate(input=seg_aux, size=(h, w), mode='bilinear', align_corners=True)
    loss = self.seg_criterion([pred_aux, pred], target)
    if (embedding is not None):
        (_, predict) = torch.max(seg, 1)
        loss_contrast = self.contrast_criterion(embedding, target, predict)
        return (loss + (self.loss_weight * loss_contrast))
    return loss
def forward(self, preds, target):
    (h, w) = (target.size(1), target.size(2))
    assert ('seg' in preds)
    assert ('seg_aux' in preds)
    seg = preds['seg']
    seg_aux = preds['seg_aux']
    embedding = (preds['embedding'] if ('embedding' in preds) else None)
    pred = F.interpolate(input=seg, size=(h, w), mode='bilinear', align_corners=True)
    pred_aux = F.interpolate(input=seg_aux, size=(h, w), mode='bilinear', align_corners=True)
    loss = self.seg_criterion([pred_aux, pred], target)
    if (embedding is not None):
        (_, predict) = torch.max(seg, 1)
        loss_contrast = self.contrast_criterion(embedding, target, predict)
        return (loss + (self.loss_weight * loss_contrast))
    return loss