How to get Kernel, Stride,Padding details from a model object?

I want to print the Kernel ,Padding, And Stide only from a model object for Conv layers, Maxpool layers .

For example:

model = models.resnet18(pretrainded = True)

output:
layer1 : kernel = 7,Stride= 2,Padding = 3

You can access anything using the argument name that you have used during model creation.
For Example
Model = net()
model.conv1.kernal_size will give kernel size

so in your case it would be print(“layer1:”, model.conv1.kernel_size, model.conv1.stride, model.conv1.padding)

Thanks you.

My requirement here is Just to get the Kernel,Stride , and padding information without knowing the model archicature details. So that i dont have to mention the layer details.
Looking for some iterative way to extract all the info at one go.

You could use @Kapil_Rana 's approach and combine it with iterating all modules:

for name, module in model.named_modules():
    if isinstance(module, nn.Conv2d):
        print(name, module.kernel_size)
        ...
1 Like

Than you can print whole model
print(model)

And one more you can iterate over all model modules and print kernel, stride and padding only.

1 Like

It assists us with keeping a greater amount of the data at the boundary of a picture. Without cushioning, not many qualities at the following layer would be influenced by pixels as the edges of a picture.

1 Like