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

My encoder-decoder shows asymmetrical architectures (using torchinfo package) #938

Open
bobetocalo opened this issue Oct 8, 2024 · 1 comment

Comments

@bobetocalo
Copy link

bobetocalo commented Oct 8, 2024

Using a ResNet-18 backbone (ResNetEncoder), I do not undestand why the decoder achieved using a UNet or FPN architecture is not symetrical ... I attach the summary of a UNetDecoder which only consists of 3M parameters, instead of the 11M related to the encoder. Where is the problem? How can I made the decoder completely symmetrical?

The input of the decoder should be the 8x8x512 feature maps ... but I receive the original image as input 256x256x3. Why?

======================================================================================================================================================
Layer (type:depth-idx)                             Input Shape               Output Shape              Param #                   Kernel Shape
======================================================================================================================================================
LitUNet                                            [8, 3, 256, 256]          [8, 98, 256, 256]         --                        --
├─Unet: 1-1                                        [8, 3, 256, 256]          [8, 98, 256, 256]         --                        --
│    └─ResNetEncoder: 2-1                          [8, 3, 256, 256]          [8, 3, 256, 256]          --                        --
│    │    └─Conv2d: 3-1                            [8, 3, 256, 256]          [8, 64, 128, 128]         9,408                     [7, 7]
│    │    └─BatchNorm2d: 3-2                       [8, 64, 128, 128]         [8, 64, 128, 128]         128                       --
│    │    └─ReLU: 3-3                              [8, 64, 128, 128]         [8, 64, 128, 128]         --                        --
│    │    └─MaxPool2d: 3-4                         [8, 64, 128, 128]         [8, 64, 64, 64]           --                        3
│    │    └─Sequential: 3-5                        [8, 64, 64, 64]           [8, 64, 64, 64]           147,968                   --
│    │    └─Sequential: 3-6                        [8, 64, 64, 64]           [8, 128, 32, 32]          525,568                   --
│    │    └─Sequential: 3-7                        [8, 128, 32, 32]          [8, 256, 16, 16]          2,099,712                 --
│    │    └─Sequential: 3-8                        [8, 256, 16, 16]          [8, 512, 8, 8]            8,393,728                 --
│    └─UnetDecoder: 2-2                            [8, 3, 256, 256]          [8, 16, 256, 256]         --                        --
│    │    └─Identity: 3-9                          [8, 512, 8, 8]            [8, 512, 8, 8]            --                        --
│    │    └─ModuleList: 3-10                       --                        --                        3,151,552                 --
│    └─SegmentationHead: 2-3                       [8, 16, 256, 256]         [8, 98, 256, 256]         --                        --
│    │    └─Conv2d: 3-11                           [8, 16, 256, 256]         [8, 98, 256, 256]         14,210                    [3, 3]
│    │    └─Identity: 3-12                         [8, 98, 256, 256]         [8, 98, 256, 256]         --                        --
│    │    └─Activation: 3-13                       [8, 98, 256, 256]         [8, 98, 256, 256]         --                        --
======================================================================================================================================================
@bobetocalo bobetocalo changed the title My encoder-decoder shows asymmetrical architectures My encoder-decoder shows asymmetrical architectures (using torchinfo package) Oct 8, 2024
@qubvel
Copy link
Collaborator

qubvel commented Oct 9, 2024

Hi! It's not an original Unet implementation. Orignal one uses VGG encoder as far as I remember, however, newer encoders provide much better results. You can increase the number of channels in decoder to increase the number of parameters with decoder_channels=(...), see https://smp.readthedocs.io/en/latest/models.html#unet

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

2 participants