keras icon indicating copy to clipboard operation
keras copied to clipboard

Why can I set both dilation_rate and strides '>1' in Conv1DTranspose?

Open Zhaopudark opened this issue 4 years ago • 8 comments

System information.

  • Have I written custom code (as opposed to using a stock example script provided in Keras): no
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 11
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): 2.8.0
  • Python version: 3.9.7
  • Bazel version (if compiling from source): no
  • GPU model and memory: RTX3090 24GB
  • Exact command to reproduce:
>>> import tensorflow as tf
>>> x = tf.random.normal(shape=[1,5,1])
>>> y = tf.keras.layers.Conv1DTranspose(filters=3,kernel_size=[3,],strides=(2,),dilation_rate=(2,),padding="same",)
>>> print(y(x).shape)
(1, 10, 3)
>>> print(y.strides)
(2,)
>>> print(y.dilation_rate)
(2,)

Describe the problem.

When using Conv1DTranspose y = tf.keras.layers.Conv1DTranspose(filters=3,kernel_size=[3,],strides=(2,),dilation_rate=(2,),padding="same",)
havn't thrown an exception when stride and dilation_rate are both ">1".

It's different from the description in https://github.com/keras-team/keras/blob/v2.8.0/keras/layers/convolutional.py#L880-L884 and AIP docs in https://tensorflow.google.cn/api_docs/python/tf/keras/layers/Conv1DTranspose.

I have no idea whever this is a docs's bug or a code's bug.

Zhaopudark avatar Feb 17 '22 12:02 Zhaopudark

have a similar issue https://github.com/keras-team/tf-keras/issues/79 seems like I am not alone with it :)

pokecheater avatar Feb 18 '22 13:02 pokecheater

@Zhaopudark Dilation basically means to leave out features (tokens or pixels) in between two features which will be convolved together. If you keep both dilation_rate and strides greater than 1 then some features will nevr be taken into account which is illegal. Hope this helps!

old-school-kid avatar Feb 20 '22 11:02 old-school-kid

@old-school-kid Thanks, I totally agree with you. That answers my doubts. I really felt confused about the code of Conv1DTranspose that different from its' documentation description before. But now, I think it just lacks mandatory restrictions, but does not affect correct use if I understand the effects on dilation_rate and strides.

Zhaopudark avatar Feb 20 '22 12:02 Zhaopudark

When we run the code on the CPU, we get InvalidArgumentError as shown below

import tensorflow as tf
x = tf.random.normal(shape=[1,5,1])
y = tf.keras.layers.Conv1DTranspose(filters=3,kernel_size=[3,],strides=(2,),dilation_rate=(2,),padding="same",)

print(y(x).shape)

Output:


---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
[<ipython-input-2-155ce2f8a75e>](https://localhost:8080/#) in <module>()
----> 1 print(y(x).shape)

1 frames
[/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py](https://localhost:8080/#) in raise_from_not_ok_status(e, name)
   7184 def raise_from_not_ok_status(e, name):
   7185   e.message += (" name: " + name if name is not None else "")
-> 7186   raise core._status_to_exception(e) from None  # pylint: disable=protected-access
   7187 
   7188 

InvalidArgumentError: Exception encountered when calling layer "conv1d_transpose" (type Conv1DTranspose).

Current libxsmm and customized CPU implementations do not yet support dilation rates larger than 1. [Op:Conv2DBackpropInput]

Call arguments received:
  • inputs=tf.Tensor(shape=(1, 5, 1), dtype=float32)
 

Where as on the GPU, it is not throwing any exception as shown below

print(y(x).shape) (1, 10, 3)

Please find the gist here for reference. Thanks!

chunduriv avatar Apr 04 '22 14:04 chunduriv

@chunduriv In the documentation it clearly mentions under dilation

Currently, specifying a dilation_rate value != 1 is incompatible with specifying a stride value != 1.

And this should also be the ideal case. But while executing with GPU it accepts value which I think is a bug. Can you please look into it? TIA

old-school-kid avatar Apr 04 '22 18:04 old-school-kid

@old-school-kid,

Yes, it is working as expected on CPU, but it is a bug on GPU.

chunduriv avatar Apr 25 '22 12:04 chunduriv

This is working as expected in the latest version of tf-nightly. Please find the gist here. Thanks!

gowthamkpr avatar Jul 21 '22 18:07 gowthamkpr

@gowthamkpr On CPU it throws Invalid Argument Error which is right imo. But on GPU it throws Unimplemented Error which is confusing IMO.

old-school-kid avatar Jul 21 '22 19:07 old-school-kid

@Zhaopudark, I tried to execute the code on tensorflow v2.13(both cpu and gpu), and it was working as expected by throwing the error strides > 1 not supported in conjunction with dilation_rate > 1. Received: strides=(2,) and dilation_rate=(2,) which was informative for the user. Kindly find the gist of it here.

CPU and GPU. Thank you!

tilakrayal avatar Jul 28 '23 16:07 tilakrayal

@tilakrayal Thanks. Since it has been solved in the latest version of TensorFlow, should I close this issue?

Zhaopudark avatar Aug 06 '23 03:08 Zhaopudark

@Zhaopudark, As the issue got resolved, Could you please feel free to move this issue to the closed status. Thank you!

tilakrayal avatar Aug 07 '23 06:08 tilakrayal

@tilakrayal OK! Thanks a lot

Zhaopudark avatar Aug 07 '23 08:08 Zhaopudark

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Aug 07 '23 08:08 google-ml-butler[bot]