我是神经网络和 keras 的新手,在编写这个自定义损失函数时遇到了麻烦:
我使用 TensorFlow 作为后端。我看到了其他的例子,并以这种方式编写了损失函数:
from keras import backend as K
def depth_loss_func(pred_depth,actual_depth):
n = pred_depth.shape[0]
di = K.log(pred_depth)-K.log(actual_depth)
di_sq = K.square(di)
sum_d = K.sum(di)
sum_d_sq = K.sum(di_sq)
loss = ((1/n)*sum_d_sq)-((1/(n*n))*sum_d*sum_d) # getting an error in this step
return loss
我得到的错误是:
TypeError: unsupported operand type(s) for /: 'int' and 'Dimension'
另外我不确定如何将学习率纳入损失函数。谢谢你的帮助。