从 .caffemodel 执行验证损失?

Perform the validation loss from .caffemodel?

AFAIK,我们有两种方法来获得验证损失。
(1) 在训练过程中在线通过设置求解器如下: train_net: 'train.prototxt'

test_net: "test.prototxt"
test_iter: 200
test_interval: 100

(2) 根据.caffemodel 文件中的权重离线。在这个问题中,由于GPU有限,我考虑了第二种方式。首先,我在 snapshot: 100 每 100 次迭代后将网络的权重保存到 .caffemodel。基于这些.caffemodel,我想计算validation loss

../build/tools/caffe test -model ./test.prototxt -weights $snapshot -iterations 10 -gpu 0 

其中 snapshot 是 .caffemodel 的文件名。例如snap_network_100.caffemodel

而我的测试prototxt的数据层是

layer {
  name: "data"
  type: "HDF5Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  hdf5_data_param {
    source: "./list.txt"
    batch_size: 8
    shuffle: true
  }
}

第一种和第二种方式给出了不同的验证损失。我发现第一种方法的验证损失与批量大小无关。这意味着不同批量大小的验证损失相同。而第二种方式,验证损失随批次大小的不同而变化,但损失与不同的迭代非常接近。

我的问题是哪种方法计算验证损失是正确的?

您计算不同次迭代的验证损失:

test_iter: 200

在您的 'solver.prototxt' 中,对比 -iterations 10 当 运行 来自命令行时。这意味着您正在平均不同数量的验证样本的损失。
由于从命令行验证时使用的样本少得多,因此您对 batch_size.
更加敏感 确保您使用完全相同的设置并验证验证损失确实相同。