Reshape tensor in custom loss function

Viewed 832

I have a problem similar to this question. I am trying to devise a loss function in keras given as:

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

based on the answer given in this question. However, I am getting an error:

 TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

Specifically this statement gives the following output

(Pdb) actual_depth.get_shape()
TensorShape([Dimension(None), Dimension(None), Dimension(None)])

The backend is TensorFlow. Thanks for your help.

1 Answers
Related