Histogramm loss func.
iperov opened this issue · 0 comments
iperov commented
tf.histogram_fixed_width is not differentiable to use in loss func.
I created differentiable version for image histogram.
def tf_image_histogram (tf, input):
x = input
x += 1 / 255.0
output = []
for i in range(256, 0, -1):
v = i / 255.0
y = (x - v) * 1000
y = tf.clip_by_value (y, -1.0, 0.0) + 1
output.append ( tf.reduce_sum (y) )
x -= y*v
return tf.stack ( output[::-1] )
^ result same as tf.histogram_fixed_width
and with mean square diff
hist_loss = tf.reduce_mean ( tf.square ( ( tf_image_histogram (tf, y_true) - tf_image_histogram(tf, y_pred) ) /65536 ) )
nn finds out nearest set of pixels from noise which represent same histogram
so how to use it to train image histogram ?