Caffe - Doing forward pass with multiple input blo

2019-09-09 23:35发布

问题:

Following are the input layers of my fine-tuned model:

layer {
  type: "HDF5Data"
  name: "data"
  top: "Meta" 
  hdf5_data_param {
    source: "/path/to/train.txt"
    batch_size: 50
  }
  include { phase: TRAIN }
}
layer {
  name: "data"
  type: "ImageData"
  top: "X"
  top: "Labels"
  include {
    phase: TRAIN
  }
  transform_param {
    mirror: true
    crop_size: 227
    mean_file: "data/ilsvrc12/imagenet_mean.binaryproto"
  }
  image_data_param {
    source: "/path/to/train.txt"
    batch_size: 50
    new_height: 256
    new_width: 256
  }
}
layer {
  type: "HDF5Data"
  name: "data"
  top: "Meta" 
  hdf5_data_param {
    source: "/path/to/val.txt"
    batch_size: 50
  }
  include { phase: TEST }
}
layer {
  name: "data"
  type: "ImageData"
  top: "X"
  top: "Labels"
  include {
    phase: TEST
  }
  transform_param {
    mirror: false
    crop_size: 227
    mean_file: "data/ilsvrc12/imagenet_mean.binaryproto"
  }
  image_data_param {
    source: "/path/to/val.txt"
    batch_size: 50
    new_height: 256
    new_width: 256
  }
}

As you can see it has one imagedata input layer and 1 hdf5 input layer, if there was only 1 type of layer say imagedata, I could have done:

input_data = {prepare_images(im)}; # dimension 227*227*3*10

and then scores = caffe('forward',input_data); But here I have to give two types of input data, how can I do this? Please help!

回答1:

I had to check matcaffe.cpp (and recompile with make matcaffe) and print the check variables for the 'Invalid Input Size' condition I was failing, to get the idea of transposing input_data which works.

input_data = {prepare_images(im),prepare_other_data()};
scores = caffe('forward', input_data');

Thus taking the transpose worked for me.