Esempio n. 1
0
    def accumulate(self, learn):
        for i in range(len(learn.pred)):
            pred = learn.pred[i]["masks"]

            targ = learn.yb[i]["masks"].squeeze(1)
            # In case not predicted mask. Set all pixels to background
            if pred.shape[0] > 0:
                pred = pred[0]
            else:
                pred = torch.zeros(targ.shape).to(targ.device)
            pred, targ = flatten_check(pred, targ)
            self.inter += (pred * targ).float().sum().item()
            self.union += (pred + targ).float().sum().item()
Esempio n. 2
0
def medae(inp, targ):
    "Mean absolute error between `inp` and `targ`."
    inp, targ = flatten_check(inp, targ)
    e = torch.abs(inp - targ)
    return torch.median(e).item()
Esempio n. 3
0
def mpe(y_pred, target) -> Tensor:
    y_pred, target = flatten_check(y_pred, target)
    loss = (y_pred - target) / (target + 1e-8)
    return loss.mean()
Esempio n. 4
0
def smape(y_pred: Tensor, target: Tensor) -> Tensor:
    y_pred, target = flatten_check(y_pred, target)
    loss = 2 * (y_pred - target).abs() / (y_pred.abs() + target.abs() + 1e-8)
    return loss.mean()
Esempio n. 5
0
def huber(inp, targ):
    """Huber error between `inp` and `targ`."""
    return F.smooth_l1_loss(*flatten_check(inp, targ))
Esempio n. 6
0
 def accumulate(self, learn):
     pred, targ = flatten_check(learn.pred, learn.y)
     self.inter += (pred * targ).float().sum().item()
     self.union += (pred + targ).float().sum().item()