Tensorflow计算图像梯度损失

时间:2017-10-31 23:09:52

标签: tensorflow

我正在尝试通过重建图像和地面实况的渐变来优化我的网络,但是我收到了这个错误

  

InvalidArgumentError:输入不可逆。

我认为这是因为张量流想通过图像变换反向传播。我该如何解决这个问题?

def image_gradient_loss(y_prediction, y):
    gradient_loss = tf.abs(tf.abs(y_prediction - tf.contrib.image.transform(y_prediction, [1, 0, 1, 0, 0, 0, 0, 0])) - tf.abs(y - tf.contrib.image.transform(y, [1, 0, 1, 0, 0, 0, 0, 0]))) + \
    tf.abs(tf.abs(y_prediction - tf.contrib.image.transform(y_prediction, [0, 0, 0, 0, 1, 1, 0, 0])) - tf.abs(y - tf.contrib.image.transform(y, [0, 0, 0, 0, 1, 1, 0, 0])))
    return tf.reduce_mean(gradient_loss)



loss = image_gradient_loss(y_pred, y)
optimizer = tf.train.RMSPropOptimizer(learning_rate=0.001).minimize(loss)

1 个答案:

答案 0 :(得分:0)

我做了这些步骤,对我有用:

dy_true, dx_true = tf.image.image_gradients(y_true)
dy_pred, dx_pred = tf.image.image_gradients(y_pred)
term3 = K.mean(K.abs(dy_pred - dy_true) + K.abs(dx_pred - dx_true), axis=-1)
相关问题