XiaXuehai
(Xia Xuehai)
June 28, 2018, 9:44am
1
I am new about pytorch.
the example like this
inputs = torch.rand(1,1,10,10)
mod = nn.Conv2d(1,32,3,2,1)
out = mod(inputs)
print(out.shape)
the output is torch.Size([1, 32, 5, 5])
I think new_width = (old_width+2*padding-kernal_size)/stride +1.
but it cann’t divisible.
So how to calculate it in pytorch?
2 Likes
The complete formula for the output size is given in the docs . If it’s not divisible, the output size seems to be rounded down.
EDIT: new link to the Conv2d docs .
5 Likes
jw3126
(Jan Weidner)
May 26, 2021, 2:24pm
3
Is there a built in way to compute the output size of layers, without actually running the layer? I am looking for something like:
output_tensor_size = compute_output_size(layer, input_tensor_size)
You could take a look at the different approaches in this thread .
yuezuegu
(Yuezuegu)
April 4, 2022, 6:38pm
5
Following package calculates the output dimensions of common torch.nn operations:
You can install it by:
pip install torchshape
Disclaimer: I’m the creator of this package.
2 Likes