【问题标题】:low accuracy in neural network with caffe带有caffe的神经网络精度低
【发布时间】:2018-07-06 11:37:55
【问题描述】:

在 caffe 中,我创建了一个简单的网络来对人脸图像进行分类,如下所示:

myExampleNet.prototxt

name: "myExample"
layer {
  name: "example"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  transform_param {
    scale: 0.00390625
  }
  data_param {
    source: "examples/myExample/myExample_train_lmdb"
    batch_size: 64
    backend: LMDB
  }
}
layer {
  name: "mnist"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  transform_param {
    scale: 0.00390625
  }
  data_param {
    source: "examples/myExample/myExample_test_lmdb"
    batch_size: 100
    backend: LMDB
  }
}
layer {
  name: "ip1"
  type: "InnerProduct"
  bottom: "data"
  top: "ip1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 50
    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: 155
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {
  name: "accuracy"
  type: "Accuracy"
  bottom: "ip2"
  bottom: "label"
  top: "accuracy"
  include {
    phase: TEST
  }
}
layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "ip2"
  bottom: "label"
  top: "loss"
}

myExampleSolver.prototxt

net: "examples/myExample/myExampleNet.prototxt"
test_iter: 15
test_interval: 500
base_lr: 0.01
momentum: 0.9
weight_decay: 0.0005
lr_policy: "inv"
gamma: 0.0001
power: 0.75
display: 100
max_iter: 30000
snapshot: 5000
snapshot_prefix: "examples/myExample/myExample"
solver_mode: CPU

我使用 caffe 的convert_imageset 创建 LMDB 数据库,我的数据有大约 40000 个训练数据和 16000 个测试数据。 155 个案例,每个案例分别有大约 260 和 100 张训练图像和测试图像。

我使用这个命令来训练数据:

build/tools/convert_imageset -resize_height=100 -resize_width=100 -shuffle examples/myExample/myData/data/ examples/myExample/myData/data/labels_train.txt examples/myExample/myExample_train_lmdb 

这个命令用于测试数据:

build/tools/convert_imageset -resize_height=100 -resize_width=100 -shuffle examples/myExample/myData/data/ examples/myExample/myData/data/labels_test.txt examples/myExample/myExample_test_lmdb

但是经过 30000 次迭代后,我的损失很高,准确率很低:

...
I0127 09:25:55.602881 27305 solver.cpp:310] Iteration 30000, loss = 4.98317
I0127 09:25:55.602917 27305 solver.cpp:330] Iteration 30000, Testing net (#0)
I0127 09:25:55.602926 27305 net.cpp:676] Ignoring source layer example
I0127 09:25:55.827739 27305 solver.cpp:397]     Test net output #0: accuracy = 0.0126667
I0127 09:25:55.827764 27305 solver.cpp:397]     Test net output #1: loss = 5.02207 (* 1 = 5.02207 loss)

当我将我的数据集更改为 mnist 并将 ip2num_output 从 155 更改为 10 时,损失显着减少并且准确性提高了!

哪一部分错了?

【问题讨论】:

    标签: machine-learning deep-learning neural-network caffe


    【解决方案1】:

    您的代码不一定有问题。

    您为 MNIST 获得了这些良好结果的事实确实表明您拥有一个“正确”的模型,即它不会产生编码错误等,但绝不保证它会表现良好在另一个不同的问题中。

    请记住,原则上,预测 10 类问题(如 MNIST)比预测 155 类问题要容易得多;第一种情况下的基线(即简单随机猜测)准确率约为 10%,而第二种情况下仅为 0.65%。添加您的数据大小(与 MNIST 相比)也不大(它们也是 color 图片,即与单通道 MNIST 相比的 3 通道吗?),您的结果可能开始看起来不是令人费解和惊讶。

    此外,事实证明 MNIST 是出了名的容易拟合(我一直在尝试自己构建模型,但无法很好地拟合 MNIST,到目前为止没有太大的成功),并且您很容易达到一个现在已成为社区共识的结论,即 MNIST 的良好性能对于模型架构来说并没有什么意义。

    【讨论】:

    • 谢谢,我的图像是 3 通道 (RGB) 与 mnist 单通道。 0.65% 的基线准确率 强迫我拥有糊状数据?那么模型不应该过度拟合我的数据(火车损失低)吗?但是我在火车上的损失也很高(接近测试损失)。不过我该如何解决呢?
    • @mortezaaliahmadi 我没有说过拟合;在我看来,您的模型不够复杂,无法很好地概括最复杂的 155 类问题。
    • @mortezaaliahmadi 你需要一个更复杂的网络(即更多层),因为这是一个计算机视觉环境,最好是卷积神经网络
    • 谢谢,在这个网络之前,我有一个convolutionpoolinginner-productreluinner-productsoftmaxwithloss。准确率非常低,所以我决定将网络小型化......
    • @mortezaaliahmadi 保留它们,并可能添加更多(转换和密集);正如我所说,您向 MNIST 扔的几乎任何东西都会起作用!但对于更复杂的问题,您将需要更复杂的模型。
    猜你喜欢
    • 2016-10-22
    • 1970-01-01
    • 2016-10-19
    • 2018-07-07
    • 2020-04-04
    • 2018-07-14
    • 1970-01-01
    • 2017-07-23
    • 2023-03-29
    相关资源
    最近更新 更多