2D conv and linear activation function

username: paozaf
cooked: <p>Hi all,<br>
I’m pretty new to pytorch, so I apologize if the question is very basic.</p>
<p>I have a model where, for each layer, I set the number of features, but the input image size is not fixed (it can change among trainings).</p>
<p>The last layer of my model is a 2D convolution that converts n input features to 1 value per pixel. To do this I would use a linear activation function.</p>
<p>The question is:<br>
how to dynamically set the input/output number of features of a linear function considering that the input image can change among trainings and only the number of features is fixed?</p>
<p>Thanks a lot.</p>
<p>Paolo</p>

username: JuanFMontesinos
cooked: <p>Output size can be computed. You just need to pick outgoing size formula and to calculate it when you create your model. Check convolution docs.</p>

username: Balamurali_M
cooked: <p>From my opinion, it is better to have a fixed input shape. If the layers you are mentioned is convolution layers. Then it can generally handle multiple shapes. Can you provide more information on this question ? The convolution parameters are generally fixed and it doesn’t change on the input shape.</p>

username: paozaf
cooked: <p>Hi,<br>
thanks for replying.</p>
<p>I use the same code to train different models over different set of images having different shapes (among datasets, of course).</p>
<p>So, if the final 2D convolution has 32 features as output, and the image has shape 512x512, I have to initialize the linear module to 32x512x512 input features and 1x512x512 a output features?<br>
Do I need also a “view” to reshape the output to 512x512 shape?</p>
<p>What if I do not set any activation function for a 2D convolution?<br>
Which is the default one?</p>
<p>Thanks a lot.</p>
<p>Paolo</p>

username: Balamurali_M
cooked: <p>Can you share the architecture ? The linear module has only two parameters. Input and output dimensions. Ideally the fully connected ( linear ) will not have input dimension 32<em>512</em>512 (single number) because the number is huge. So repeated convolution and max pooling is carried before using linear layer. View command is used to flatten the convolution layer features into a single dimension by handling batch size. So if it is used the feature map (4x32x512x512) will become (4x(32x512x512)). Here 4 denotes batch size.</p>

username: paozaf
cooked: <p>The class of my last convolution layer is this (basically I use it for converting a n features layer to a single feature (intensity) image):</p>
<blockquote>
<p>class SingleConv1x1(nn.Module):<br>
def <strong>init</strong>(self, in_feat, dropout):<br>
super(SingleConv1x1, self).<strong>init</strong>()</p>
<pre><code>    self.conv1 = nn.Sequential(nn.Conv2d(in_feat, 1,
                               kernel_size=1,
                               stride=1,
                               padding=0),
                               nn.Dropout2d(dropout))

def forward(self, inputs):
    outputs = self.conv1(inputs)

    return outputs
</code></pre>
</blockquote>
<p>After the dropout I would put the linear activation function.</p>
<p>Thank you.</p>
<p>Paolo</p>

username: paozaf
cooked: <p>Any hint?<br>
Thanks.</p>
<p>Paolo</p>