# How to understand Softmax layer activations for pretrained CNN?

4 Ansichten (letzte 30 Tage)
AK am 21 Apr. 2021
Kommentiert: AK am 27 Apr. 2021
Hello,
I was able to get softmax layer probabilities for the squeezenet network. Using
act1 = activations(net,i,'prob','OutputAs','rows');
However, Im unsure exactly what the probabilities represent, or how to identify what class they correspond with. Could you please explain what these probabilities mean? And how to get the corresponding class?
Thank you!
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Jon Cherrie am 22 Apr. 2021
How to identify what class they correspond with?
We can get this from the class names property of the output layer.
What these probabilities mean?
They are the probability that the given image is in the corresponding class.
Here's an example
net = squeezenet;
img = imresize(img,net.Layers(1).InputSize(1:2));
We can get the names of the classes from the output layer, which happens to bne the last layer for this network:
c = net.Layers(end).Classes;
Then get the activations from the softmax layer
p = activations(net,img,'prob','OutputAs','rows');
Note that these sum to 1
sum(p)
ans = single
1
We can then find the maximum probability and which class that corresponds to
[pm, i] = max(p)
pm = single
0.4172
i = 946
c(i)
ans = categorical
bell pepper
This is the same information that comes from the classify command:
[cc, pp] = classify(net,img);
cc
cc = categorical
bell pepper
isequal(pp, p)
ans = logical
1
##### 4 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
AK am 22 Apr. 2021
Yes! This is perfect! Thank you!
AK am 27 Apr. 2021
How do i get the probability of a particular index (i) ? As in, I know the index and want the associated probability. Thanks!

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by