我尝试基于颜色直方图的MSE实现keras损失函数。
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)
我收到以下错误:
>“/ Library / Frameworks / Python.framework / Versions / 3.6 / lib / python3.6 / site-packages / tensorflow / python / framework / constant_op.py”,第110行,在_constant_tensor_conversion_function中 返回常量(v,dtype = dtype,name = name)文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py”,第99行,常量 tensor_util.make_tensor_proto(value,dtype = dtype,shape = shape,verify_shape = verify_shape))
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py”,第360行,在make_tensor_proto中 提高ValueError(“不支持的值。”) ValueError:不支持任何值。
我做错了什么?