'Keras loss function on color histogram returns ValueError: None values not supported. error

I try to implement a keras loss function based on the MSE of color histogram.

def histoLoss(y_true, y_pred):
    hist_true = tf.histogram_fixed_width(y_true, [-1.0, 1.0], nbins=256, dtype=K.floatx())
    hist_pred = tf.histogram_fixed_width(y_pred, [-1.0, 1.0], nbins=256, dtype=K.floatx())

    hist_true = hist_true / (33*33.0*2)
    hist_pred = hist_pred / (33*33.0*2)

    hist_true = K.clip(hist_true, K.epsilon(), 1)
    hist_pred = K.clip(hist_pred, K.epsilon(), 1)
    return K.mean(K.square(hist_pred - hist_true), axis=-1)

I am getting the following error:

"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 110, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name)

File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 99, in constant tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))

File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 360, in make_tensor_proto raise ValueError("None values not supported.") ValueError: None values not supported.

What did I did wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source