Number of neurons before Softmax/Accuracy layer and meaning of some internal variables

209 views
Skip to first unread message

filipe mutz

unread,
Dec 10, 2015, 10:00:20 PM12/10/15
to Caffe Users
Hi Caffers! I'm developing an image classification application and I got stuck in a point. Some help would be fantastic. 

The images in my application are organized in 3 classes, so I thought that a coherent architecture should have a inner product layer with 3 neurons followed by a softmax loss layer at the end. Besides I added an accuracy layer only in the test phase, just like the lenet_train_test.prototxt in the MNIST example. 

The problem is that this architecture gives an accuracy of just 0.5. And even more curiously, when I changed the number of neurons in the inner product layer to a significantly bigger size such as 3000, the net began to give higher accuracy (0.9 to 0.97). It don't make any sense to me! 

Looking to the code of the accuracy layer, I could not figure out if this behaviour make sense or not. Mostly because I couldn't understand the meaning of some variables (although I've developed some caffe applications before, this is the first time I need to look the code under the hood). 

Could someone clarify for me if this behaviour make sense, and the meaning of the following variables that seem to exist in most of the layers?

1. label_axis_ (dimension where the labels are stored? if yes, then is this the number of neurons in the inner product layer?)
2. outer_num_ (number of neurons or number of cols in a layer?)
3. inner_num_ (1 for inner product layers. Is this the height of the layer?)

A final question: the accuracy layer performs the following check. Are W the width of the previous layer (number of neurons in an inner product), H the height (1 in an inner product), C the number of channels (1 in an inner product) and N the number of images in the test set? If yes, should the number of neurons in the inner product layer be <number of images in the testing set> * <number of classes> (for example, if I have a testing set of 100 images, and 3 possible classes, should the number of neurons be 300?)? Sorry if this question is too dumb, but all I can do is hypothesize given my current knowledge of the caffe source, and it would explain why raising the number of neurons improved the accuracy.

CHECK_EQ(outer_num_ * inner_num_, bottom[1]->count())
<< "Number of labels must match number of predictions; "
<< "e.g., if label axis == 1 and prediction shape is (N, C, H, W), "
<< "label count (number of labels) must be N*H*W, "
<< "with integer values in {0, 1, ..., C-1}.";

Thank you!!

Shaunak De

unread,
Feb 15, 2017, 7:53:14 AM2/15/17
to Caffe Users
I noticed this also. And am completely unable to explain it. Did you ever find out what happened?
Reply all
Reply to author
Forward
0 new messages