我遇到类似this question的问题。我试图给出keras制定一个损失函数:基于在this question给出了答案自定义丢失函数中的重整张量
def depth_loss_func(lr):
def loss(actual_depth,pred_depth):
actual_shape = actual_depth.get_shape().as_list()
dim = np.prod(actual_shape[1:])
actual_vec = K.reshape(actual_depth,[-1,dim])
pred_vec = K.reshape(pred_depth,[-1,dim])
di = K.log(pred_vec)-K.log(actual_vec)
di_mean = K.mean(di)
sq_mean = K.mean(K.square(di))
return (sq_mean - (lr*di_mean*di_mean))
return loss
。不过,我得到一个错误:
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'
具体来说这一说法提供了以下输出
(Pdb) actual_depth.get_shape()
TensorShape([Dimension(None), Dimension(None), Dimension(None)])
后端是TensorFlow。谢谢你的帮助。
很高兴看到这解决了你的问题,祝你好运与你的编码。如果你发现这个答案有用,也可以考虑提高它。 – DarkCygnus
非常感谢@GrayCygnus! – shunyo