addons icon indicating copy to clipboard operation
addons copied to clipboard

tfa.image.gaussian_filter2d doesn't support tensor inputs for "filter_shape" and "sigma" args

Open charles92 opened this issue 2 years ago • 3 comments

Issue

The tfa.image.gaussian_filter2d function doesn't seem to support tensors for its filter_shape and sigma arguments. Instead it only accepts ints and floats respectively, severely limiting the use case.

https://github.com/tensorflow/addons/blob/8cec33fcaaf1cf90aec7bdd55a0fcdbb251ce5c2/tensorflow_addons/image/filters.py#L221-L222

In graph mode, when you pass a tf.Tensor-typed sigma into the function, it will emit the following error:

    File ".../tensorflow_addons/image/filters.py", line 269, in gaussian_filter2d  *
        if any(s < 0 for s in sigma):

    OperatorNotAllowedInGraphError: using a `tf.Tensor` as a Python `bool` is not allowed:
      AutoGraph did convert this function. This might indicate you are trying to use an unsupported feature.

Request

Add support for tensor-typed filter_shape and sigma arguments. They are useful when the arguments can't be determined statically (e.g., when a random sigma is needed for data augmentation).

The bulk of the implementation seems to support this already. It may simply require rewriting some of the sanity checking code, like the one below:

https://github.com/tensorflow/addons/blob/8cec33fcaaf1cf90aec7bdd55a0fcdbb251ce5c2/tensorflow_addons/image/filters.py#L262-L263

charles92 avatar Dec 03 '21 01:12 charles92

Any news about this?

felmiran avatar Feb 10 '22 14:02 felmiran

Nothing still... It is a must for image augmentation pipelines:

image = tfa.image.gaussian_filter2d(
  image,
  sigma=tf.random.uniform([2], 0, 5, dtype=tf.float32),
)

edumotya avatar Mar 09 '22 09:03 edumotya

If you are interested there is another gaussian blur api under review at https://github.com/keras-team/keras-cv/pull/143

bhack avatar Mar 11 '22 18:03 bhack