问题
I have a data layer with HDF5 type. It contains both Train and Test phase as expected
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
}
}
I want to use python to generate it. This is my code
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})
However, my output is only Test phase. How can I fix it? Thanks
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:
This is an open issue in caffe (you can find links to other relevant SO threads there).
What you can do is write two prototxt one for train and one for test. solver.prototxt support definition of train net file name and test net file name.
来源:https://stackoverflow.com/questions/42289880/how-can-i-generate-data-layer-hdf5-for-training-and-testing-in-same-prototxt