2
votes

Suppose I have a trained caffe model (.caffemodel weights file and .prototxt file with the description of the net) and an image that I want to classify using this net (a simple feed-forward, then get the output values of the last layer), assume the image has the correct dimensions for the first layer of the net.

I've seen tutorials doing this with Matlab or Python.

Is there a way of doing it with Caffe itself from shell? (without using bindings in another language)

Thanks

2
Have you tried using the caffe.bin executable in build/tools/ folder running in test mode. What more option do you expect than the result of running this executable? - Anoop K. Prabhu

2 Answers

1
votes

You can do this the following way:

./build/tools/extract_features.bin
models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
examples/_temp/imagenet_val.prototxt fc7 examples/_temp/features 10 leveldb

Instead of "fc7" you can specify the name or even multiple names of the layers you want the output from. Also checkout these links for more details: https://github.com/BVLC/caffe/blob/master/tools/extract_features.cpp#L36-L45, http://caffe.berkeleyvision.org/gathered/examples/feature_extraction.html

0
votes

You can call $CAFFE_ROOT/python/classify.py from shell to classify an image:

~$ python $CAFFE_ROOT/python/classify.py \
      --model_def /path/to/deploy.prototxt \
      --pretrained_model /path/to/weights.caffemodel \
      --gpu \
      /path/to/image.jpg /path/to/output

There are some more optional parameters for this python script, you might need to set some of them.