deepfakes / faceswap-model

Tweaking the generative model
147 stars 133 forks source link

Histogramm loss func. #27

Closed iperov closed 6 years ago

iperov commented 6 years ago

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 python_2018-05-13_09-37-28

so how to use it to train image histogram ?