有没有办法从tf.keras.preprocessing.image.apply_affine_transform获取渐变?

时间:2020-06-30 14:48:48

标签: python tensorflow math linear-algebra calculus

问题

如何在张量流中找到矩阵与其仿射变换之间的梯度?或者,我在下面的代码中使用哪个不可微运算?当我尝试找到矩阵与其仿射变换之间的梯度时,将返回None

我所知道的

仿射变换是可微的。因此,应该有一种计算矩阵与其变换后的对应物之间的梯度的方法。

代码

这是一个例子。在此代码的末尾,渐变为None。我希望它是imagetransformation之间的梯度。

image = tf.constant([[[1.0], [2.0], [3.0]], 
                     [[1.0], [2.0], [3.0]], 
                     [[1.0], [2.0], [3.0]]])

with tf.GradientTape() as gTape:
    gTape.watch(image)
    transformation = tf.constant(tf.keras.preprocessing.image.apply_affine_transform(x=image.numpy(), theta=5, fill_mode="reflect"))

gradients = gTape.gradient(image, transformation)

0 个答案:

没有答案