machine-learning - Caffe : train network accuracy = 1 constant ! 准确性问题

标签 machine-learning neural-network deep-learning caffe training-data

现在,我正在使用 2 类数据训练网络...但第一次迭代后精度为常数 1!

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

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

网络.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 个样本。
- 你的训练集和测试集似乎非常精确:所有负样本(标签=0)都在所有正样本之前分组在一起。

<小时/>

考虑您的 SGD 迭代求解器,您在训练期间向其提供批处理 batch_size:10。您的训练集在任何正样本之前有 14,746 个负样本(即 1474 个批处理)。因此,对于前 1474 次迭代,您的求解器仅“看到”负面示例,而看不到正面示例。
您预计该求解器会学到什么?

问题

你的求解器只看到反例,因此知道无论输入是什么,它都应该输出“0”。您的测试集也以相同的方式排序,因此在每个 test_interval 只测试 50 个样本,您只测试测试集中的负面示例,从而获得完美的准确度 1。
但正如您所指出的,您的网络实际上什么也没学到。

解决方案

我想您现在已经猜到解决方案应该是什么了。您需要打乱训练集,并在整个测试集上测试您的网络。

关于machine-learning - Caffe : train network accuracy = 1 constant ! 准确性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35456689/

相关文章:

machine-learning - 向后传播 : are analytical second derivatives worth calculating?

python - C-contiguous fashion在caffe blob存储中意味着什么?

machine-learning - 在caffe中定义新层时如何获取学习率或迭代次数

python - 无法使用 detectorron2 恢复训练

machine-learning - 易于安装的生产就绪型实时推荐引擎

machine-learning - 如何区分结构化数据和非结构化数据?

python - Keras 只训练特定的输出

python - python中的神经网络感受野可视化

python - 在 Keras 中将多个输入样本映射到单个输出样本

python - 学习曲线 - 为什么训练准确率开始时如此之高,然后突然下降?