How to use custom model for classification?

username: ProGamerGov
cooked: <p>I used <a href="https://github.com/Microsoft/MMdnn" rel="nofollow noopener">MMdnn</a> to convert the places205 GoogLeNet to PyTorch from Caffe, and upon testing I’m not sure how to get it to perform classification correctly.</p>
<p>The model file can be found here: <a href="https://github.com/ProGamerGov/pytorch-places205" rel="nofollow noopener">https://github.com/ProGamerGov/pytorch-places205</a>, and it’s approximately 40.9 MB. The last few layers are:</p>
<pre><code class="lang-auto">        inception_5b_5x5 = self.inception_5b_5x5(inception_5b_5x5_pad)
        inception_5b_relu_3x3 = F.relu(inception_5b_3x3)
        inception_5b_relu_5x5 = F.relu(inception_5b_5x5)
        inception_5b_output = torch.cat((inception_5b_relu_1x1, inception_5b_relu_3x3, inception_5b_relu_5x5, inception_5b_relu_pool_proj), 1)
        pool5_7x7_s1    = F.avg_pool2d(inception_5b_output, kernel_size=(7, 7), stride=(1, 1), padding=(0,), ceil_mode=False, count_include_pad=False)
        pool5_drop_7x7_s1 = F.dropout(input = pool5_7x7_s1, p = 0.4000000059604645, training = self.training, inplace = True)
        return pool5_drop_7x7_s1
</code></pre>
<p>I’m not quite sure how to get an output value that can be used to determine which of the 205 categories the input is?</p>
<p>Some example input sizes:</p>
<pre><code class="lang-auto">---------------------------------------------
torch.Size([1, 3, 512, 429]):
---------------------------------------------
inception_5b_5x5 torch.Size([1, 128, 16, 13])
inception_5b_relu_3x3 torch.Size([1, 384, 16, 13])
inception_5b_relu_5x5 torch.Size([1, 128, 16, 13])
inception_5b_output torch.Size([1, 1024, 16, 13])
pool5_7x7_s1 torch.Size([1, 1024, 10, 7])
pool5_drop_7x7_s1 torch.Size([1, 1024, 10, 7])

---------------------------------------------
torch.Size([1, 3, 720, 603]):
---------------------------------------------
inception_5b_5x5 torch.Size([1, 128, 22, 18])
inception_5b_relu_3x3 torch.Size([1, 384, 22, 18])
inception_5b_relu_5x5 torch.Size([1, 128, 22, 18])
inception_5b_output torch.Size([1, 1024, 22, 18])
pool5_7x7_s1 torch.Size([1, 1024, 16, 12])
pool5_drop_7x7_s1 torch.Size([1, 1024, 16, 12])

---------------------------------------------
torch.Size([1, 3, 1280, 1072]):
---------------------------------------------
inception_5b_5x5 torch.Size([1, 128, 40, 33])
inception_5b_relu_3x3 torch.Size([1, 384, 40, 33])
inception_5b_relu_5x5 torch.Size([1, 128, 40, 33])
inception_5b_output torch.Size([1, 1024, 40, 33])
pool5_7x7_s1 torch.Size([1, 1024, 34, 27])
pool5_drop_7x7_s1 torch.Size([1, 1024, 34, 27])
---------------------------------------------
</code></pre>
<p>Any help would be appreciated!</p>

username: ProGamerGov
cooked: <p>This seems to work? But I have no idea if it actually does work, or if I am doing something wrong?</p>
<pre><code class="lang-auto">cnn = GoogLeNetPlaces205()
cnn.load_state_dict(torch.load("googlenet_places205.pth"))
cnn.eval()

input = torch.randn(1, 3, 512, 384)
x = cnn(input)

test_avgpool = nn.AdaptiveAvgPool2d((7, 7))
x = test_avgpool(x)
x = torch.flatten(x, 1)
test_fc = nn.Linear(1024 * 7 * 7, 204)
x = test_fc(x)
</code></pre>

username: ProGamerGov
cooked: <p>The model seems to work correctly with DeepDream, so at least it’s put together correctly:</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/e/8e4754f305c87e37ea7c7d0ad9b5ed21c2dea3a5.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/8e4754f305c87e37ea7c7d0ad9b5ed21c2dea3a5" title="inception4c_out"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/8/e/8e4754f305c87e37ea7c7d0ad9b5ed21c2dea3a5_2_418x500.jpeg" alt="inception4c_out" data-base62-sha1="kiECY9s2LG5eVbwb3QHwejFZ7rT" width="418" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/8/e/8e4754f305c87e37ea7c7d0ad9b5ed21c2dea3a5_2_418x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/8/e/8e4754f305c87e37ea7c7d0ad9b5ed21c2dea3a5_2_627x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/8/e/8e4754f305c87e37ea7c7d0ad9b5ed21c2dea3a5_2_836x1000.jpeg 2x" data-dominant-color="707677"><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">inception4c_out</span><span class="informations">1005×1200 1.33 MB</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>