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()
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()
def mpe(y_pred, target) -> Tensor: y_pred, target = flatten_check(y_pred, target) loss = (y_pred - target) / (target + 1e-8) return loss.mean()
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()
def huber(inp, targ): """Huber error between `inp` and `targ`.""" return F.smooth_l1_loss(*flatten_check(inp, targ))
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()