Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Difference between segmentation_models and segmentations_models_pytorch #735

Unanswered
ouioui199 asked this question in Q&A
Discussion options

Hello, I've been using segmentation_model developped by qubvel (thanks a lot!), written in tensorflow and keras. Recently, I've switched to Pytorch and been using segmentation_models_pytorch. When I do model.summary() on tensorflow version, the UNet with efficientnetb4 has 25M parameters, when in Pytorch version there is only 19M parameters. Why is this difference ? Thank you!

Here is the code in tensorflow:
model = sm.Unet(backbone_name = 'efficientnetb4',
input_shape = shape,
classes = 4,
activation = 'relu',
encoder_weights = 'imagenet')
model.summary()

Here is the code in Pytorch:
model = smp.Unet(encoder_name = 'efficientnet-b4'
encoder_weights = 'imagenet',
activation = nn.ReLU,
classes = 4,
decoder_attention_type = None)

You must be logged in to vote

Replies: 1 comment · 3 replies

Comment options

Hi, EfficientNetb4 for image classification is around 19M parameters, the fully connected layer is around 1.8M parameters which gets removed and then the decoder parameters are added. My guess is that tensorflow uses a different (larger) decoder and possibly doesnt remove the fully connected layer.

You must be logged in to vote
3 replies
@ouioui199
Comment options

Hi, thanks for your answer. It seems to me that the difference of the number of parameters comes from the fact that skip connections are located differently from the tensorflow version to pytorch version. I come to this conclusion when checking the number of input channels of each decoder block.

@S-Lykles
Comment options

Hi I changed my answer a bit (before I saw your reply) because I realized the fully connected layer itself was not big enough to account for the difference. It is indeed the decoder part that is different. Did you notice a performance difference between smp and tensorflow?

@ouioui199
Comment options

No problem ;) From my experience, there is a performance difference between smp and tensorflow, so I ended up using the smp with efficientnet-B5 backbone (to match up with the number of parameters) and the result is better than tf with backbone efficientnet-B4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.