Caffe:火车网络精度= 1常数!准确性问题 [英] Caffe : train network accuracy = 1 constant ! Accuracy issue

查看:68
本文介绍了Caffe:火车网络精度= 1常数!准确性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在训练带有2个类数据的网络...但是在第一次迭代后精度为1!

Right now, I am train network with with 2 class data... but accuracy is constant 1 after first iteration !

输入数据是灰度图像。创建HDF5Data时,将随机选择两个类图像。

Input data is grayscale images. both class images are randomly selected when HDF5Data creation.

为什么会这样?哪里出了问题或哪里出了问题!

Why is that happened ? What's wrong or where is mistake !

network.prototxt:

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 loss
I0217 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 Optimization
I0217 17:41:07.912813  2913 solver.cpp:288] Solving brainMRI
I0217 17:41:07.912832  2913 solver.cpp:289] Learning Rate Policy: inv
I0217 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.98
I0217 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 = 1
I0217 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 = 1
I0217 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个样本。

-您的训练和测试集似乎可以请注意:将所有阴性样本(label = 0)分组到所有阳性样本之前。

Summarizing some information from the comments:
- You run test at intervals of test_interval:100 iterations.
- Each test interval goes over test_iter:5 * batch_size:10 = 50 samples.
- Your train and test sets seems to be very nit: all the negative samples (label=0) are grouped together before all the positive samples.

请考虑一下SGD迭代求解器,您在训练期间可以批量添加 batch_size:10 。您的训练集在任何阳性样本之前有14,746阴性样本(即1474批次)。因此,对于前1474个迭代,您的求解器仅看到否定的示例,而没有正面的示例。

您希望该求解器学习什么?

Consider your SGD iterative solver, you feed it batches of batch_size:10 during training. Your training set has 14,746 negative samples (that is 1474 batches) before any positive sample. So, for the first 1474 iterations your solver only "sees" negative examples and no positive ones.
What do you expect this solver will learn?

您的求解器仅看到否定示例,因此得知,无论输入什么,都应输出 0。您的测试集也以相同的方式订购,因此在每个test_interval中仅测试50个样本,您仅对测试集中的负样本进行测试,结果的精确度为1。

但正如您所指出的那样,您的网络实际上一无所获。

Your solver only sees negative examples, thus learns that no matter what the input is it should output "0". Your test set is also ordered in the same fashion, so testing only 50 samples at each test_interval, you only test on the negative examples in the test set resulting with a perfect accuracy of 1.
But as you noted, your net actually learned nothing.

我想您已经猜到了现在应该采取的解决方案。您需要改组训练集,并在整个测试集上测试网络。

I suppose you already guess what the solution should be by now. You need to shuffle your training set, and test your net on your entire test set.

这篇关于Caffe:火车网络精度= 1常数!准确性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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