keras icon indicating copy to clipboard operation
keras copied to clipboard

Conv2D with Torch Creates Wrong Shape

Open i418c opened this issue 1 year ago • 2 comments

While trying to move from Keras 2 to Keras 3 with PyTorch, I ran into a problem in my model where a Conv2D layer outputs a shape wider in one dimension and shorter in another. It behaves appropriately when using the Tensorflow backend.

A reproducing gist is here.

i418c avatar Oct 18 '24 00:10 i418c

Hi @i418c -

Thanks for reporting the issue. Here for torch backend running on keras3 for comparing output shape need to change kernel_size and stride like this conv2d = Conv2D(output_size, kernel_size=(4,4),strides=(2, 2),padding='same',activation='relu', kernel_initializer='ones',use_bias=False). And also input_2d need to transpose to feed input to conv2d inputs_2d = inputs_2d.transpose(1,2,3,0)

Attached gist here for the reference.

mehtamansi29 avatar Oct 24 '24 06:10 mehtamansi29

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar Nov 08 '24 02:11 github-actions[bot]

This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.

github-actions[bot] avatar Nov 22 '24 02:11 github-actions[bot]

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

google-ml-butler[bot] avatar Nov 22 '24 02:11 google-ml-butler[bot]