# 假设只有大于0的值是有效值
#方法1: 手动求(目标值: target, 预测值:pred);
tmask = target > 0
#统计depth图中非0元素个数
tmp_depth = target.copy()
tmp_depth[tmp_depth != 0 ] = 1
tmp_depth[tmp_depth == 0] = 0
num = tmp_depth.sum()
difmap = abs(target[tmask] - pred[tmask])
L1 = difmap.sum()/num
L1Dif = 'L1 difference: ' + str(L1) + '\r\n'
print(L1Dif)
#方法2:使用 np.sum;num.abs
def get_L1Loss(self, pred, target):
'''
pred: numpy
target: numpy
'''
valid_mask = target>0
diff = target - pred
diff = diff[valid_mask]
loss = np.mean(np.abs(diff))
return loss