【问题标题】:how to use tf.contrib.image.rotate in loss function?如何在损失函数中使用 tf.contrib.image.rotate?
【发布时间】:2019-07-08 15:14:18
【问题描述】:

我在损失函数中使用了 tf.conbrib.image.rotate,出现错误:

No gradients provided for any variable, check your graph for ops that do not support gradients,

我的代码是:

import tensorflow as tf

image_tensor = tf.placeholder(dtype=tf.float32, shape=[None,320,320,1])
target_tensor = tf.placeholder(dtype=tf.float32, shape=[None,320,320,1])
s = tf.concat([image_tensor, target_tensor],axis=3)
s = tf.layers.flatten(s)
w = tf.get_variable(initializer=tf.truncated_normal([204800,1], stddev=0.1),name='w')
b = tf.get_variable(initializer=tf.truncated_normal([1], stddev=0.1),name='b')
a = tf.matmul(s,w)+b
diff = tf.contrib.image.rotate(image_tensor, a[:,0], interpolation='BILINEAR') - target_tensor
loss = tf.reduce_sum(tf.square(diff))

optimizer = tf.train.GradientDescentOptimizer(0.001)
train = optimizer.minimize(loss)

我的tensorflow是:1.4.0,我的电脑是Win10。

顺便问一下,如何在 tensorflow 中旋转 3D 图像? tf.conbrib.image.rotate 仅适用于 2D 图像。

【问题讨论】:

    标签: tensorflow rotation loss


    【解决方案1】:

    tf.contrib.image.rotate 无法优化。我找到了空间变换网络的有用代码 (https://github.com/kevinzakka/spatial-transformer-network)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 1970-01-01
      • 1970-01-01
      • 2017-10-16
      • 2018-04-30
      • 1970-01-01
      • 2021-02-20
      相关资源
      最近更新 更多