I ask a question about input size

Is that pytorch only deal with the same size of every image in one batch.If in a batch ,the input have different size, there is a error:RuntimeError: inconsistent tensor sizes . I do not want to adjust the input size .Have any body help me?Thanks

When initialize a network, you need specify the corresponding input size in advance, such as

net = nn.Conv2d(3, 64)
net = nn.Linear(256, 64)

for Conv2d, you don’t need to specify the input image size except for channel depth. However, for Linear layer, you need to specify the input size, which means, the input size should be fixed.

Another problem is that, since Linear layer o = w*x+b, when your x dimension changes, you need change the dimension of weights. I don’t know whether you can deal with this.

You could deal with different shaped input using adaptive pooling layers, e.g. AdaptiveMaxPool1d.
You could place this layer before a Linear layer, which needs a fixed input shape like @dragen explained.

1 Like