训练bvlc_reference_caffenet,输入数据缩放为[0,1]

时间:2017-12-05 05:42:06

标签: caffe

我跟随Caffe ImageNet Tutorial并且可以成功训练bvlc_reference_caffenet。现在我想将输入数据从[0,255]缩放到[0,1](因为我后来必须在具有有限固定/浮点精度的硬件上运行此CNN),就像在Caffe LeNet MNIST Tutorial中完成它一样通过向scale图层添加data参数:

layer {
  name: "mnist"
  type: "Data"
  transform_param {
    scale: 0.00390625
  }
  data_param {
    source: "mnist_train_lmdb"
    backend: LMDB
    batch_size: 64
  }
  top: "data"
  top: "label"
}

由于这个原因,我还将此scale参数添加到bvlc_reference_caffenet,并将平均参数除以每个通道减去255:

layer {
  name: "data"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  transform_param {
     crop_size: 227
     scale: 0.00390625
     mean_value: 0.40784313
     mean_value: 0.45882352
     mean_value: 0.48235294
     mirror: true
  }
  data_param {
    source: "examples/imagenet/ilsvrc12_train_lmdb"
    batch_size: 32
    backend: LMDB
  }
}
layer {
  name: "data"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  transform_param {
    crop_size: 227
    scale: 0.00390625
    mean_value: 0.40784313
    mean_value: 0.45882352
    mean_value: 0.48235294
    mirror: false
  }
  data_param {
    source: "examples/imagenet/ilsvrc12_val_lmdb"
    batch_size: 32
    backend: LMDB
  }
}

当我训练网时,准确率总是低于偶然。我需要采用哪些其他参数来训练网络[0,1]图像而不是[0,255]图像?

1 个答案:

答案 0 :(得分:2)

Caffe首先减去均值然后缩放结果。您应保留原始的0...255平均值 参考:

if (has_mean_file) {
          transformed_data[top_index] =
            (datum_element - mean[data_index]) * scale;
}

data_transformer.cpp