Implementing a Multi Target Regression Net with Caffe with Non-image data input

302 Views Asked by At

I was trying to implement a simple net in Caffe for coping with multi-target regression.

The dimension of my input is 5. The dimension of my output is 3.

I have this data on a mat file.

I have used h5create and h5write to create both train.h5 and test.h5 files.

load('train_data.mat')
h5create('train_data.h5','/data',[5 10000]);
h5write('train_data.h5', '/data', x');
load('train_label.mat')
h5create('train_label.h5','/label',[3 10000]);
h5write('train_label.h5', '/label', Y');

load('test_data.mat')
h5create('test_data.h5','/data',[5 2500]);
h5write('test_data.h5', '/data', x');
load('test_label.mat')
h5create('test_label.h5','/label',[3 2500]);
h5write('test_label.h5', '/label', Y');

I designed a network in Caffe as follows:

name: "RegressionNet"    
  layer {        
    name: "data"        
    type: "HDF5Data"        
    top: "data"        
    top: "data"        
    include {        
      phase: TRAIN        
    }        
    hdf5_data_param {        
      source: "examples/my_second_cnn_example/data/train_data.txt"        
      batch_size: 10        
    }        
  }                
  layer {        
    name: "data"        
    type: "HDF5Data"        
    top: "label"        
    top: "label"        
    include {        
      phase: TRAIN        
    }        
    hdf5_data_param {        
      source: "examples/my_second_cnn_example/data/train_label.txt"        
      batch_size: 10        
    }       
  }        
  layer {        
    name: "data"        
    type: "HDF5Data"        
    top: "data"        
    top: "data"        
    include {        
      phase: TEST        
    }        
    hdf5_data_param {        
      source: "examples/my_second_cnn_example/data/test_data.txt"        
      batch_size: 10        
    }        
  }        
  layer {        
    name: "data"        
    type: "HDF5Data"        
    top: "label"        
    top: "label"        
    include {        
      phase: TEST        
    }        
    hdf5_data_param {        
      source: "examples/my_first_cnn_example/data/test_label.txt"        
      batch_size: 10        
    }       
  }        
  layer {        
    name: "fc1"        
    type: "InnerProduct"        
    bottom: "data"        
    top: "fc1"       
    param {        
      lr_mult: 1        
      decay_mult: 1        
    }        
    param {        
      lr_mult: 2        
      decay_mult: 0        
    }        
    inner_product_param {        
      num_output: 3        
      weight_filler {        
        type: "xavier"        
      }        
      bias_filler {        
        type: "constant"        
        value: 0        
      }        
    }        
  }        
  layer {        
    name: "loss"        
    type: "EuclideanLoss"        
    bottom: "fc1"        
    bottom: "label"        
    top: "loss"        
  }       
  layer {        
    name: "accuracy"        
    type: "Accuracy"        
    bottom: "fc1"        
    bottom: "label"        
    top: "accuracy"        
    include {        
      phase: TEST        
    }        
  }

Unfortunately It does not work! I got the following error

Check failed: outer_num_ * inner_num_ == bottom[1]->count() (10 vs. 30) Number of labels must match number of predictions; e.g., if label axis == 1 and prediction shape is (N, C, H, W), label count (number of labels) must be N*H*W, with integer values in {0, 1, ..., C-1}.

I think that the problem is in the way I'm organizing the data. And also in the use of the Accuracy layer.

However, any idea about how to solve it?

0

There are 0 best solutions below