caffe icon indicating copy to clipboard operation
caffe copied to clipboard

Training From Extracted Feature Vector

Open seewalker opened this issue 12 years ago • 6 comments

I have a feature vector produced by running extract_features on a pretrained model and my data. I want to train a neural network using that feature vector as the input blob. What layer type would that data be considered? Or, if I'm on the wrong train, how can I train a network with the result of extract_features as my starting point?

I've tried making the first layer of my network a DATA layer like so:

layers {
    name: "data"
    type: DATA 
    top: "data"
    top: "label"
    data_param {
        source: "/home/a/learning/train_feature_vector"
        batch_size: 50
        mirror: false
    }
}

and having the next layer consider this layer, "data", its bottom. I've also tried making this layer have a image_data_param instead of a data_param, but with no success. Is there something deeply wrong with my approach, or am I missing some detail?

In case it matters, the layer being extracted is an inner product layer (with in-place relu and dropout layers) and the first layer after this "data" layer is also such an inner product layer.

seewalker avatar Jul 14 '14 16:07 seewalker

I have the same problem and am rather lost on how to initiate a net with mid-level features as input rather than images. Does anybody have advice or a simple working example where they use features as input to another neural net?

dennis-chen avatar Jul 14 '14 19:07 dennis-chen

I am trying to run the given extract_features file and get a feature vector. I have ran the extract features file and the features are saved to leveldb. How do i extract the feature vector from this type of file?

meera1hahn avatar Jul 14 '14 21:07 meera1hahn

@meera1hahn, The leveldb you're talking about IS the feature vector. Extracting the weights and biases from it is easy with the python wrappers, as show in this tutorial. The main question of this thread is how to train from the feature vector as a starting point.

seewalker avatar Jul 15 '14 04:07 seewalker

@seewalker, I have looked at that tutorial, however that python wrapper processes the images individually not in batch mode so it takes a while. My goal is the take the feature from the fc7 layer and then pass those into an svm classifer. So I need to convert the leveldb into vector that i can save as a .mat file. Do you know how to do this?

meera1hahn avatar Jul 15 '14 15:07 meera1hahn

You should be able to use the matcaffe wrapper to do that. Stay tunned at the new Matcaffe2 for easy feature extraction directly from matlab.

Sergio

2014-07-15 8:39 GMT-07:00 meera1hahn [email protected]:

@seewalker https://github.com/seewalker, I have looked at that tutorial, however that python wrapper processes the images individually not in batch mode so it takes a while. My goal is the take the feature from the fc7 layer and then pass those into an svm classifer. So I need to convert the leveldb into vector that i can save as a .mat file. Do you know how to do this?

— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/690#issuecomment-49050571.

sguada avatar Jul 15 '14 23:07 sguada

You can solve with custom data through the Python interface or the in-progress update to the MATLAB interface. The HDF5DataLayer works with custom data of any shape too. You should be able to use the standard DataLayer provided you follow the same format of the Datum that is used in the convert_imageset utility.

Please continue the discussion on the caffe-users mailing list. As of the latest release we prefer to keep issues reserved for Caffe development. Thanks!

shelhamer avatar Aug 12 '14 00:08 shelhamer