如何在张量流中找到矩阵与其仿射变换之间的梯度?或者,我在下面的代码中使用哪个不可微运算?当我尝试找到矩阵与其仿射变换之间的梯度时,将返回None
。
仿射变换是可微的。因此,应该有一种计算矩阵与其变换后的对应物之间的梯度的方法。
这是一个例子。在此代码的末尾,渐变为None
。我希望它是image
和transformation
之间的梯度。
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)