Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A checker is needed in Conv layers #19457

Closed
Shuo-Sun20 opened this issue Apr 7, 2024 · 3 comments
Closed

A checker is needed in Conv layers #19457

Shuo-Sun20 opened this issue Apr 7, 2024 · 3 comments
Assignees

Comments

@Shuo-Sun20
Copy link

As disscussed in tensorflow/tensorflow#64396, it should be considered as an abnormal input when kernel_size > input_size, while currently the Conv layers will silently generate an unexpected output, therefore maybe a checker is needed here.

The code to reproduce this issue:

from keras.layers import Conv2D
import numpy as np

x=np.random.rand(1,2,2,1)
l=Conv2D(1,3,(1,1),'valid','channels_last', [1,1],1, 'linear', True)
print(l(x).shape)
print(l.compute_output_shape(x.shape))

In my opinion, this code should not generate an output, a warning or error is expected since the kernel(3x3) is larger than input (2x2).

@fchollet
Copy link
Member

fchollet commented Apr 7, 2024

Thanks for the suggestion. When the size of the inputs is statically known before calling the layer, we can add such a check (like in your code example).

However, when the size is only known at runtime, it would not be practical to add ops to the graph to include this check. Instead, it should be up to the backend framework to raise an exception is the operation is invalid.

@Shuo-Sun20
Copy link
Author

You are right. I'll close this issue and report this issue to Tensorflow.

@fchollet
Copy link
Member

fchollet commented Apr 8, 2024

If you're interested, you can also add a check in the base Conv layer's build() method for the static shape case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants