【问题标题】:Tensorflow compute image gradient lossTensorFlow 计算图像梯度损失
【发布时间】:2018-04-13 05:41:09
【问题描述】:

我正在尝试根据重建图像的梯度和地面实况优化我的网络,但收到此错误

InvalidArgumentError:输入不可逆。

我认为这是因为 tensorflow 想要通过图像转换进行反向传播。我该如何解决这个问题?

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)

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

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

    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)
    

    【讨论】:

    • 当我尝试这样做时,它显示了一个错误,因为 tf.image.image_gradients(y_true) 说 AttributeError: 'Tensor' object has no attribute 'get_shape'
    猜你喜欢
    • 2018-06-28
    • 2020-03-16
    • 2023-02-26
    • 2016-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-02
    • 2022-01-04
    相关资源
    最近更新 更多