addons
addons copied to clipboard
tfa.image.gaussian_filter2d doesn't support tensor inputs for "filter_shape" and "sigma" args
Issue
The tfa.image.gaussian_filter2d
function doesn't seem to support tensors for its filter_shape
and sigma
arguments. Instead it only accepts int
s and float
s 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
Any news about this?
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),
)
If you are interested there is another gaussian blur api under review at https://github.com/keras-team/keras-cv/pull/143