addons icon indicating copy to clipboard operation
addons copied to clipboard

No gradients to transforms in tfa.image.transform

Open fengyang0317 opened this issue 3 years ago • 1 comments

Describe the feature and the current behavior/state. back prop the gradient to transforms.

Relevant information

  • Are you willing to contribute it (yes/no): no
  • Are you willing to maintain it going forward? (yes/no): no
  • Is there a relevant academic paper? (if so, where): no
  • Does the relavent academic paper exceed 50 citations? (yes/no): no
  • Is there already an implementation in another framework? (if so, where):
  1. https://tensorlayer.readthedocs.io/en/latest/_modules/tensorlayer/layers/spatial_transformer.html
  2. http://pytorch.org/vision/main/generated/torchvision.transforms.functional.affine.html
  • Was it part of tf.contrib? (if so, where): no

Which API type would this fall under (layer, metric, optimizer, etc.) tfa.image.transform

Who will benefit with this feature? Implement spatial transformer networks.

fengyang0317 avatar Feb 02 '22 08:02 fengyang0317

A test code

import tensorflow as tf
import tensorflow_addons as tfa

im = tf.zeros([100, 100, 3])
mat = tf.constant([1, 0, 0, 0, 1, 0, 0, 0], dtype=tf.float32)

with tf.GradientTape() as tape:
  tape.watch(im)
  tape.watch(mat)
  out = tfa.image.transform(im, mat)
  loss = tf.reduce_mean(out)

grads = tape.gradient(loss, [im, mat])
print(grads)

fengyang0317 avatar Feb 02 '22 08:02 fengyang0317