Closed GFabien closed 2 years ago
Hi, @GFabien. Thanks for reporting this. I know I'm very late, but I discovered only today that I wasn't watching this repo! Sorry about that.
I do get the ID of each module twice (I replaced module.id
with id(module)
). It must be because of the lines you mention in the Fix section. However, I've debugged the code and the forward pass happens only once. Phew!
If you think it's an issue that modules are registered twice, please do let me know.
Description
Working on a function to generate a Keras-like summary for Pytoch models from pytorch-summary I came across an issue with the ConvolutionalBlock class: layers are registered twice in the model leading to weird consequences.
Indeed, in a forward pass, the model goes twice through every convolutional layer in a ConvolutionalBlock. Here is a code to illustrate this behaviour:
To run it, you need to add this small change to the ConvolutionalBlock class in order to assign a unique id to every convolutional layer:
The above snippet produces the following output where you can see that every id appears twice:
Fix
A simple fix seems to be to remove the following lines:
and add the
out_channels
variable as an attribute of the ConvolutionalBlock class to retrieve it in the EncodingBlock class throughself.conv2.out_channels
instead ofself.conv2.conv_layer.out_channels
.If this fix seems reasonable I can take care of the PR.