I am new to pytorch. I am constructing simple pytorch model using with nn.sequential and using layers. I am getting different number of parameters. Can someone guide or explain the reason for different number of parameters in model. My implementation is as
import torch.nn as nn
from pytorch_model_summary import summary
nn.Conv2d(in_channels=3, out_channels=32, kernel_size=3, stride=2, padding= 1, bias=False),
self.conv=nn.Conv2d(in_channels=3, out_channels=32, kernel_size=(3,3),
self.bn = nn.BatchNorm2d(32)
self.relu = nn.ReLU()
print(summary(Net1(), x, show_input=True))
# Yield Total params: 928
print(summary(Net2(), x, show_input=True))
# Yield Total params: 960
It’s because you do not use bias in conv2d in
Just out of curiosity: why should the
from import be preferred?
Perhaps I was a bit commanding in my way of formulating things. Note that my. Comment is about “as” not about “import” VS “from… import”. AFAIK there is no noticeable usage difference if you assign ‘as’ nn or just import the submodule. However, ‘as’ is intended to specify an identifier for the loaded module. Therefore it is quite silly to assign it to the same name it already has.
Yeah, I think you are right and I have to admit that I never questiond it as I automatically type it in the “as nn” way based on the first official tutorials (e.g. ImageNet example, MNIST example).
Well perhaps it comes down to preference anyway! I was too strong in my statement. I don’t think there is one right or wrong answer. To me, my way seems “cleaner” but that’s subjective.
I removed it from my comment.
Oh no, I really don’t want to say you are wrong and I think the “as nn” import is really not necessary.
After you’ve mentioned it it was probably the first time I thought about it.
Sorry, don’t want to hijack this topic for this discussion.