Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature extraction #13

Closed
FreakTheMighty opened this issue Jun 24, 2015 · 8 comments
Closed

Feature extraction #13

FreakTheMighty opened this issue Jun 24, 2015 · 8 comments

Comments

@FreakTheMighty
Copy link

Thanks for the library. Is it possible extract features from different layers in the network?

@mtngld
Copy link

mtngld commented Jun 30, 2015

Hi,

Try something like that:

  //Feature extraction
    const shared_ptr<Blob<float> >& features = caffe_net->blob_by_name("fc7");
    LOG(INFO) << "Features size " << features->count();
    vector myfeatures  = vector<float>(features->cpu_data(),features->cpu_data()+features->count());

Change "fc7" to whatever layer you want

@isikdogan
Copy link

I'm also trying to extract features. I need the features before they are passed through the softmax layer, just like in the code snippet above. Where should I add this code? Is it caffe_mobile.cpp?
Thanks

@mtngld
Copy link

mtngld commented Aug 11, 2015

Yes, you can simply add it to predict_top_k function or create a dedicated feature extraction function

@vimalthilak
Copy link

You can always modify the prototxt to extract features that are of interest to you. I have been able to extract features from the output of average pooling layer of a GoogLeNet model by simply removing the last three layers from the deploy prototxt file of the same model. You just re-run Forward() as before.

@isikdogan
Copy link

Thanks for your responses. I wasn't familiar with the Java Native Interface. I was able to run it by modifying caffe_jni.cpp and caffe_mobile.cpp files.

@Keyurpatel93
Copy link

isikdogan, can you please share how you modified the caffe_jni.cpp and caffe_mobile.cpp files to be able to extract features from a layer in the network?

@isikdogan
Copy link

Keyurpatel93, I just noticed your message. I no longer work on that project. The development version of OpenCV seems to have caffe-compatible functions. I don't know if those functions are available in the Android version yet, but if so then it could be more convenient to use them:
http://docs.opencv.org/master/d6/d0f/group__dnn.html

@sh1r0
Copy link
Owner

sh1r0 commented Dec 29, 2015

Thanks to the discussions above. Feature extraction is integrated in the latest master branch, so I'm gonna close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants