Value in output CNN network and transfer learning

Korsarz: <p>Hi,<br>
I make CNN network based on tutorial: <a href="https://ucfai.org/core/fa19/cnns/#introduction-to-the-dataset" rel="nofollow noopener">How We Can Give Our Computers Eyes and Ears</a>, because this topic resolve similar problem - in my program I try recognize people by ear picture from camera (I use OpenCV).<br>
So, I have first demo version, and I have a few questions about it:</p>
<p><strong>- In this tutorial was used transform:</strong></p>
<pre><code class="lang-auto">transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
</code></pre>
<p>if I use data from resnet I must transform frame by this ?</p>
<pre><code class="lang-auto">mean = [0.485, 0.456, 0.406] and std = [0.229, 0.224, 0.225]
</code></pre>
<p>-<strong>This is my prediction function. In output (score variable) I have other value between (~ -6: ~6)</strong>(I’m not sure)</p>
<pre><code class="lang-auto">def argmax(prediction):
    prediction = prediction.cpu()
    prediction = prediction.detach().numpy()
    top_1 = np.argmax(prediction, axis=1)
    score = np.amax(prediction)
    score = '{:6f}'.format(score)
    prediction = top_1[0]
    result = dog_breeds[prediction]

    return result,score
</code></pre>
<p>I expected value between (0,1), because in many examples, people use if(score &gt;0.5) to determine if the prediction is good.</p>
<p><strong>In tutorial the author uses transfer learning.</strong> After he don’t use his database, only database from resnet, so if I use pretrain network I don’t have to have own database? I don’t see the place in program where he connects his database and database from resnet. I don’t understand this.</p>
<p>Thanks for all answers !<br>
Have a nice day</p>

ptrblck: <p>If you are using a pretrained model, I would recommend to use the same preprocessing as was used to train this model.<br>
In your case, you should use the second normalization approach.<br>
Also, you might change the preprocessing but would probably need to fine tune the complete model.<br>
As always, it depends on the use case and you would have to try out different approaches.</p>
<aside class="quote no-group" data-username="Korsarz" data-post="1" data-topic="78496">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/k/ad7895/48.png" class="avatar"> Korsarz:</div>
<blockquote>
<p>I expected value between (0,1), because in many examples, people use if(score &gt;0.5) to determine if the prediction is good.</p>
</blockquote>
</aside>
<p>It seems you are working on a multi-class classification (with probably <code>nn.CrossEntropyLoss</code> as the criterion). If that’s the case, then your model will output class logits, which are not limited to the range <code>[0, 1]</code>. To get the predicted class, the <code>argmax</code> usage is correct.<br>
If you want to see the probabilities for e.g. debugging, you could apply <code>softmax</code> on your model output.<br>
Note that you should not pass the <code>softmax(output)</code> to <code>nn.CrossEntropyLoss</code>, as internally <code>F.log_softmax</code> will be applied!</p>
<aside class="quote no-group" data-username="Korsarz" data-post="1" data-topic="78496">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/k/ad7895/48.png" class="avatar"> Korsarz:</div>
<blockquote>
<p>After he don’t use his database, only database from resnet, so if I use pretrain network I don’t have to have own database? I don’t see the place in program where he connects his database and database from resnet. I don’t understand this.</p>
</blockquote>
</aside>
<p>I see a custom <code>Dataset</code> definition in the tutorial and it’s being used in the training loop via:</p>
<pre data-code-wrap="python"><code class="lang-python">for i, (inputs, labels) in enumerate(dataloaders[phase]):
    ...
</code></pre>