目前,我正在使用两类数据训练网络…但在第一次迭代后准确率恒定为1!
输入数据是灰度图像。在创建HDF5Data时,两类图像都是随机选择的。
为什么会发生这种情况?哪里出了问题或有什么错误!
network.prototxt :
name: "brainMRI"layer { name: "data" type: "HDF5Data" top: "data" top: "label" include: { phase: TRAIN } hdf5_data_param { source: "/home/shivangpatel/caffe/brainMRI1/train_file_location.txt" batch_size: 10 }}layer { name: "data" type: "HDF5Data" top: "data" top: "label" include: { phase: TEST } hdf5_data_param { source: "/home/shivangpatel/caffe/brainMRI1/test_file_location.txt" batch_size: 10 }}layer { name: "conv1" type: "Convolution" bottom: "data" top: "conv1" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 20 kernel_size: 5 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "pool1" type: "Pooling" bottom: "conv1" top: "pool1" pooling_param { pool: MAX kernel_size: 2 stride: 2 }}layer { name: "conv2" type: "Convolution" bottom: "pool1" top: "conv2" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 50 kernel_size: 5 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "pool2" type: "Pooling" bottom: "conv2" top: "pool2" pooling_param { pool: MAX kernel_size: 2 stride: 2 }}layer { name: "ip1" type: "InnerProduct" bottom: "pool2" top: "ip1" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 500 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "relu1" type: "ReLU" bottom: "ip1" top: "ip1"}layer { name: "ip2" type: "InnerProduct" bottom: "ip1" top: "ip2" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 2 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "softmax" type: "Softmax" bottom: "ip2" top: "smip2"}layer { name: "loss" type: "SoftmaxWithLoss" bottom: "ip2" bottom: "label" top: "loss"}layer { name: "accuracy" type: "Accuracy" bottom: "smip2" bottom: "label" top: "accuracy" include { phase: TEST }}
输出 :
I0217 17:41:07.912580 2913 net.cpp:270] This network produces output lossI0217 17:41:07.912607 2913 net.cpp:283] Network initialization done.I0217 17:41:07.912739 2913 solver.cpp:60] Solver scaffolding done.I0217 17:41:07.912789 2913 caffe.cpp:212] Starting OptimizationI0217 17:41:07.912813 2913 solver.cpp:288] Solving brainMRII0217 17:41:07.912832 2913 solver.cpp:289] Learning Rate Policy: invI0217 17:41:07.920737 2913 solver.cpp:341] Iteration 0, Testing net (#0)I0217 17:41:08.235076 2913 solver.cpp:409] Test net output #0: accuracy = 0.98I0217 17:41:08.235194 2913 solver.cpp:409] Test net output #1: loss = 0.0560832 (* 1 = 0.0560832 loss)I0217 17:41:35.831647 2913 solver.cpp:341] Iteration 100, Testing net (#0)I0217 17:41:36.140849 2913 solver.cpp:409] Test net output #0: accuracy = 1I0217 17:41:36.140949 2913 solver.cpp:409] Test net output #1: loss = 0.00757247 (* 1 = 0.00757247 loss)I0217 17:42:05.465395 2913 solver.cpp:341] Iteration 200, Testing net (#0)I0217 17:42:05.775877 2913 solver.cpp:409] Test net output #0: accuracy = 1I0217 17:42:05.776000 2913 solver.cpp:409] Test net output #1: loss = 0.0144996 (* 1 = 0.0144996 loss)..........................
回答:
总结评论中的一些信息:
– 您每隔test_interval:100
次迭代进行一次测试。
– 每次测试间隔处理test_iter:5
* batch_size:10
= 50个样本。
– 您的训练集和测试集似乎非常整齐:所有负样本(标签=0)在所有正样本之前被分组在一起。
考虑您的SGD迭代求解器,您在训练期间以batch_size:10
的批次喂入数据。您的训练集有14,746个负样本(即1474个批次),在任何正样本之前。因此,在前1474次迭代中,您的求解器只“看到”负样本,而没有正样本。
您期望这个求解器学到什么?
问题
您的求解器只看到负样本,因此学会了无论输入是什么都应该输出“0”。您的测试集也是按相同方式排序的,因此在每次test_interval只测试50个样本时,您只在测试集中的负样本上进行测试,结果准确率为完美的1。
但正如您所指出的,您的网络实际上什么也没学到。
解决方案
我想您现在已经猜到解决方案是什么了。您需要打乱您的训练集,并在您的整个测试集上测试您的网络。