Can the Resnet50 output a 2d label?

nikiguo93: <p>I want to use resnet50 to predict something and I hope that the resnet50 can output a label with a dimension of 17*100. how can I change the fc layer to match this dimension? it is confusing.</p>

ptrblck: <p>Could you explain your use case a bit and what these dimensions would represent?<br>
The standard ResNet would already output a 2D tensor in the shape <code>[batch_size, nb_classes]</code>, but I assume you want to use another additional dimension?</p>

nikiguo93: <p>Sure. I want to use Resnet50 to predict the EEGResponse to image stimuli. The input to the DNN is image data (500<em>500</em>3), and the output should be the EEGResponse (17*100). I don’t know how to modify the fc layer to make it output something like that?</p>

nikiguo93: <p>the image data is 500 *500 *3</p>

ptrblck: <p>I’m still unsure about the output shape. If you would like to get an output in the shape <code>[batch_size, 17*100=1700]</code>, you could define the <code>out_features</code> of the last linear layer to be <code>1700</code>.<br>
The input shape should work, since the resnets in <code>torchvision</code> use adaptive pooling layers before feeding the activation to the linear layer which makes the input shape more flexible.<br>
Note, however, that the input should have the shape <code>[batch_size, channels, height, width]</code>, so you might need to <code>permute</code> it.</p>

nikiguo93: <p>Thanks for your reply. Sorry for the unclear description. Actually I am a beginner of Pytorch and DNN.</p>
<ol>
<li>
<p>In the image classfication problem, I would have 1654*10 images and 1654 labels. Images are fed into the Resnet50 and label would be predicted. The batch size is 64.</p>
</li>
<li>
<p>Then the problem is changed to replace the label with EEG data (something recording the neural activity and the EEG data corresponding to a image is of size 17 *100, a matrix  which is quite different from that of label in (1).</p>
</li>
<li>
<p>in 1) the output feature of fc should be something like 1000? But in 2) how to modify the out_feature size of fc layer? I am confused.</p>
</li>
</ol>
<p>p.s the image size is 500 *500 *3 （height *width *channel). And I would incorparate all the images into a matrix 16540 * 500 *500 *3. The corresponding EEG data matrix would be 16540 * 17 *100. Then I do batch on the image with batch size of 64. In my case how to permute the input and output?</p>

ptrblck: <ol>
<li>Are the posted numbers representing the number of samples for the images and targets? If so, are 10 images corresponding to a single label?</li>
<li>I still don’t know how the output would be treated, but one approach would be to use a linear layer with <code>out_features=1700</code> and reshape the output to <code>[batch_size, 17, 100]</code>. However, it depends on your actual use case to know, if this would be the right approach.</li>
<li>The <code>out_features</code> are passed as the second argument in the <code>nn.Linear</code> as described in the <a href="https://pytorch.org/docs/stable/generated/torch.nn.Linear.html?highlight=linear#torch.nn.Linear">docs</a>.</li>
</ol>
<p>To permute the input from <code>[16540, 500, 500, 3]</code> to a channels-first format you could use <code>x = x.permute(0, 3, 1, 2)</code>.</p>

nikiguo93: <ol>
<li>
<p>Yes there are 1654 categories and each category has 10 images</p>
</li>
<li>
<p>yeah this also make me confused.</p>
</li>
<li>
<p>thank you for telling me about that.</p>
</li>
</ol>