如何在相同的原型文本中生成用于训练和测试的数据层(HDF5)?

时间:2017-02-17 05:11:17

标签: python neural-network deep-learning caffe pycaffe

我有一个HDF5类型的数据层。它包含预期的训练和测试阶段

name: "LogisticRegressionNet"
layer {
  name: "data"
  type: "HDF5Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  hdf5_data_param {
    source: "examples/hdf5_classification/data/train.txt"
    batch_size: 10
  }
}
layer {
  name: "data"
  type: "HDF5Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  hdf5_data_param {
    source: "examples/hdf5_classification/data/test.txt"
    batch_size: 10
  }
}

我想用python来生成它。这是我的代码

import caffe
from caffe import layers as L  # pseudo module using __getattr__ magic to generate protobuf messages
from caffe import params as P  # pseudo module using __getattr__ magic to generate protobuf messages
n = caffe.NetSpec()
n.data, n.label = L.HDF5Data(batch_size=batch_size, source='examples/hdf5_classification/data/train.txt', ntop=2, include={'phase': caffe.TRAIN})
n.data, n.label = L.HDF5Data(batch_size=batch_size, source='examples/hdf5_classification/data/test.txt',ntop=2, include={'phase': caffe.TEST})

但是,我的输出只是测试阶段。我该如何解决?感谢

layer {
  name: "data"
  type: "HDF5Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  hdf5_data_param {
    source: "examples/hdf5_classification/data/test.txt"
    batch_size: 2
  }
}

1 个答案:

答案 0 :(得分:1)

这是一个未解决的问题in caffe(你可以找到其他相关SO线程的链接)。

你可以做的是为火车写一个prototxt,为测试写一个。 solver.prototxt支持定义列车网络文件名和测试网络文件名。