How to generate concate layer prototxt using pytho

2019-09-18 20:45发布

I have a prototxt as follows:

layer {
  name: "data"
  type: "HDF5Data"
  top: "data1"
  top: "data2"
  top: "label"
  include {
    phase: TRAIN 
  }
  hdf5_data_param {
    source: "./source_list.txt"
    batch_size: 2
    shuffle: true 
  }
}
layer {
  name: "concat"
  type: "Concat" 
  bottom: "data1"
  bottom: "data2"
  top: "data"
  concat_param {
    concat_dim:1
  }
}

I want to generate above prototxt using caffe NetSpec in python. However, It was wrong. This is my code. Please help me to fix it. Thanks

from caffe import layers as L
...
n = caffe.NetSpec()
n.data, n.label = L.HDF5Data(top=["data1", "data2"], batch_size=2,
                             source="./source_list.txt", ntop=2,shuffle= True,
                             include={'phase': caffe.TRAIN})
n.concat = L.Concat(n.data["data1"], n.data["data2"])

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-18 21:26

You need to have two data outputs

n.data1, n.data2, n.label = L.HDF5Data(ntop=3, name="data",
                                       hdf5_data_param={'source': "./source_list.txt", 
                                                         'shuffle': True,
                                                         'batch_size': 2}
                                       include={'phase': caffe.TRAIN})
n.data = L.Concat(n.data1, n.data2, name="concat", concat_param={'concat_dim':1})
查看更多
登录 后发表回答