在Caffe中测试回归网络 [英] Testing a regression network in caffe

查看:159
本文介绍了在Caffe中测试回归网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Alexnet计数图像中的对象.

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

我目前的图像中每个图像包含1、2、3或4个对象.对于初始检查,我每个班级有10张图像.例如,在训练集中,我有:

I have currently images containing 1, 2, 3 or 4 objects per image. For initial checkup, I have 10 images per class. For example in training set I have:

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

我使用imagenet创建脚本为此数据集创建了一个lmdb文件.这成功地将我的一组图像转换为lmdb. 例如,通过引入EucledeanLosslayer而不是Softmax Layer,将Alexnet转换为回归模型,以了解图像中的对象数量.正如许多人所建议的那样.网络的其余部分是相同的.

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

尽管进行了上述所有操作,但是在运行模型时,在测试阶段我仅收到零作为输出(如下所示).它什么也没学.但是,训练损失在每次迭代中都持续减少.

However, despite doing all the above, when I run the model, I received only zeros as output during testing phase(shown below). It did not learn any thing. However, the training loss decreased continuously in each iteration.

我不明白自己犯了什么错误.谁能指导我为什么预测值始终为0?在测试阶段如何检查回归值,以便检查多少个样本正确,每个图像的值是多少?

I don't understand what mistakes I have made. Can anybody guide me why the predicted values are always 0? And how can I check the regressed values in testing phase, so that to check how many samples are correct and what's the value for each of my image?

测试数据集的预测标签和实际标签为:

The predicted and the actual label of the test dataset is given 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
...

注意:我还按顺序创建了hdf5格式的文件,以使其具有浮动标签,即1.0、2.0、3.0和4.0.但是,当我将数据层更改为HDF5类型时,无法像在带有lmdb层的alexnet中进行的图像裁剪和规范化一样进行图像增强.我使用了" https://github.com/上给出的脚本nikogamulin/caffe-utils/blob/master/hdf5/demo.m "以获取hdf5数据,并按照他的步骤在模型中使用了该数据.

Note: I also created hdf5 format files in-order to have floating labels, i.e. 1.0, 2.0, 3.0 and 4.0. However, when i changed data layer to HDF5 type, i can not crop the image for data-augmentation as being done in alexnet with lmdb layer, as well as normalization. I used the script given on "https://github.com/nikogamulin/caffe-utils/blob/master/hdf5/demo.m" for hdf5 data and followed his steps for using it in my model.

我已经更新了最后一层:

I have updated 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"
 }

推荐答案

在不判断网络是否发散的情况下,您所犯的显而易见的错误是,您不应该使用Accuracy层来测试回归网络.它仅用于测试由SoftmaxWithLoss层训练的分类网络.

Without judging whether your network diverged or not, the obvious mistake you have made is that you shouldn't use a Accuracy layer to test a regression network. It is only for testing a classification network trained by a SoftmaxWithLoss Layer.

实际上,给定网络图像,网络中的Accuracy层将始终对其输入数组进行排序(此处为bottom: "fc8reg"),并选择数组中最大值的索引作为预测标签默认情况下.

In fact, given an image for a network, the Accuracy layer in the network will always sort its input array(here it is bottom: "fc8reg") and choose the index of the maximal value in the array as the predicted label by default.

由于fc8reg层中的num_output == 1accuracy层将始终将输入图像的索引0预测为预测图像,如您所见.

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

最后,您可以使用EuclideanLoss层来测试您的回归网络.这个类似的问题可能还会给您一些提示.

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

如果要在训练后打印和计算回归值,并计算回归网络的准确性,则可以简单地编写RegressionAccuracy层,例如 .

If you are to print and calculate the regressed values after training, and count the accuracy of the regression network, you can simply write a RegressionAccuracy layer like this.

或者,如果您的目标标签只有4个离散值{1,2,3,4},您仍然可以为您的任务训练分类网络.

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

这篇关于在Caffe中测试回归网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆