How can I generate data layer (HDF5) for training and testing in same prototxt?

人走茶凉 提交于 2019-12-11 06:03:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!