Testing regression network in coffee

I am trying to count objects in an image using Alexnet.

I have images containing 1, 2, 3 or 4 objects per image. For initial verification, I have 10 images for each class. For example, in a training set, I have:

image label image1 1 image2 1 image3 1 ... image39 4 image40 4 

I used imagenet to create a script file to create an lmdb file for this dataset. Which successfully converted my image set to lmdb. As an example, Alexnet is converted to a regression model to examine the number of objects in an image by introducing EucledeanLosslayer instead of Softmax Layer. As many believe. The rest of the network is the same.

However, despite all of the above, when I run the model, I received only zeros as the result at the testing stage (shown below). He did not know anything. However, learning loss was constantly decreasing at each iteration.

I don’t understand what mistakes I made. Can someone explain to me why the predicted values ​​are always 0? And how can I check the regressed values ​​at the testing stage to check how many samples are correct and what is the value for each of my images?

The predicted and actual label of the test data set is specified as:

 I0928 17:52:45.585160 18302 solver.cpp:243] Iteration 1880, loss = 0.60498 I0928 17:52:45.585212 18302 solver.cpp:259] Train net output #0: loss = 0.60498 (* 1 = 0.60498 loss) I0928 17:52:45.585225 18302 solver.cpp:592] Iteration 1880, lr = 1e-06 I0928 17:52:48.397922 18302 solver.cpp:347] Iteration 1900, Testing net (#0) I0928 17:52:48.499543 18302 accuracy_layer.cpp:88] Predicted_Value: 0 Actual Label: 1 I0928 17:52:48.499641 18302 accuracy_layer.cpp:88] Predicted_Value: 0 Actual Label: 2 I0928 17:52:48.499660 18302 accuracy_layer.cpp:88] Predicted_Value: 0 Actual Label: 3 I0928 17:52:48.499681 18302 accuracy_layer.cpp:88] Predicted_Value: 0 Actual Label: 4 ... 

Note. I also created hdf5 files to have floating labels, i.e. 1.0, 2.0, 3.0 and 4.0. However, when I changed the data level to type HDF5, I can not crop the image to increase data as performed in alexnet with the lmdb level, as well as normalization. I used the script specified at https://github.com/nikogamulin/caffe-utils/blob/master/hdf5/demo.m "for hdf5 data and followed its steps to use it in my model.

I updated the last layers as such:

 layer { name: "fc8reg" type: "InnerProduct" bottom: "fc7" top: "fc8reg" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } inner_product_param { num_output: 1 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } } } layer { name: "accuracy" type: "Accuracy" bottom: "fc8reg" bottom: "label" top: "accuracy" include { phase: TEST } } layer { name: "loss" type: "EuclideanLoss" bottom: "fc8reg" bottom: "label" top: "loss" } 
0
source share
2 answers

Without judging whether your network has been scattered or not, the obvious mistake you made is that you should not use the Accuracy layer to check the regression network. It is intended only for testing the classification network trained by the SoftmaxWithLoss layer.

In fact, given the network image, the Accuracy level in the network will always sort its input array (here it is bottom: "fc8reg" ) and select the index of the maximum value in the array, since the predicted label is by default.

Since num_output == 1 in the fc8reg layer, the Accuracy layer will always predict index 0 for the input image as its predicted label, as you saw.

Finally, you can use the EuclideanLoss layer to test your regression network. This similar problem may also give you some hint.


If you are going to print and calculate regression values ​​after training and calculate the accuracy of the regression network, you can simply write a RegressionAccuracy layer, for example this .

Or, if your target label has only 4 discrete values {1,2,3,4} , you can still train the classification network for your task.

+2
source

In my opinion, everything is correct, but your network does not converge, which is not a rare thing. Your network actually converges to zero outputs! Perhaps most of your samples have 0 as a label.

Also remember to enable the loss layer only during TRAIN; otherwise, he will study the test data as hello.

0
source

All Articles