What does the .fc.in_feature mean?

11115: <p>Can anyone tell me what does the following code mean in the <a href="http://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html" rel="nofollow noopener">Transfer learning tutorial</a>?</p>
<pre><code class="lang-auto">model_ft = models.resnet18(pretrained=True)
num_ftrs = model_ft.fc.in_features
model_ft.fc = nn.Linear(num_ftrs, 2)
</code></pre>
<p>I can see that this code is use to adjuest the last fully connected  layer to the ‘ant’ and ‘bee’ poblem. But I can’t find anything in the pytorch documents about <code>.fc.in_feature</code>, So what to do if I wants to transfer another pre-trained model, say <code>.vgg19_bn</code>, to another classification problem?</p>

alexis-jacq: <p>in_feature is the number of inputs for your linear layer:</p>
<pre><code class="lang-python"># constructor of nn.Lienar
def __init__(self, in_features, out_features, bias=True):
    super(Linear, self).__init__()
    self.in_features = in_features # num inputs
    self.out_features = out_features # num outputs
    self.weight = Parameter(torch.Tensor(out_features, in_features))
    if bias:
        self.bias = Parameter(torch.Tensor(out_features))
</code></pre>
<p>You can still check in the sources: <a href="https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/linear.py">https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/linear.py</a></p>

11115: <aside class="quote no-group" data-username="alexis-jacq" data-post="2" data-topic="4889">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/alexis-jacq/48/180_2.png" class="avatar"> alexis-jacq:</div>
<blockquote>
<p><a href="https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/linear.py" rel="noopener nofollow ugc">https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/linear.py</a></p>
</blockquote>
</aside>
<p>Thank you very much! You helped a lot!</p>

FrankZLuffy: <p>model_ft is a type of  &lt;class ‘torchvision.models.resnet.ResNet’&gt;.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/d/d0d72cfb9a9d8714ed804c33231abfbc50898299.png" data-download-href="https://discuss.pytorch.org/uploads/default/d0d72cfb9a9d8714ed804c33231abfbc50898299" title="resnet"><img src="https://discuss.pytorch.org/uploads/default/original/2X/d/d0d72cfb9a9d8714ed804c33231abfbc50898299.png" alt="resnet" data-base62-sha1="tNukbYcztOwMC7uk3codfN5bYU1" width="690" height="96" data-dominant-color="EFECEE"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">resnet</span><span class="informations">736×103 7.68 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

FrankZLuffy: <p>model_ft.fc is a type of &lt;class ‘torch.nn.modules.linear.Linear’&gt;.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/c/ce5fbdae24f16b63510726a42c118b50533bb148.png" data-download-href="https://discuss.pytorch.org/uploads/default/ce5fbdae24f16b63510726a42c118b50533bb148" title="linear"><img src="https://discuss.pytorch.org/uploads/default/original/2X/c/ce5fbdae24f16b63510726a42c118b50533bb148.png" alt="linear" data-base62-sha1="trFtWn4gllO84rbWF1mFxp0QGeY" width="690" height="168" data-dominant-color="EFEEF0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">linear</span><span class="informations">728×178 9.32 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>