-
Notifications
You must be signed in to change notification settings - Fork 18.5k
How to pycaffe #1774
Description
There's confusion about the Python interface. In particular users get stuck with
- matching caffe command and the caffe python module
- the
caffe.Netinterface vs. thecaffe.Classifierandcaffe.Detector(caffe.Netis real and the others are meant only as examples). That is, just usecaffe.Net. - python solving: in Bundle CVPR15 tutorial notebooks #2667
- python layers: loss example in Bundle CVPR15 tutorial notebooks #2667 but a data example is still needed
Advice on matching the caffe command and caffe python module:
It can be tricky to get the preprocessing options exactly right. Instead of loading a deploy prototxt in Python, load the exact same model as you do by extract_features.
Instead of making a
caffe.Classifier, make acaffe.Netand callnet.forward()to load inputs from the data layer batch-by-batch:
net = caffe.Net('net_with_data_layer.prototxt', 'weights.caffemodel')
net.forward() # this will load the next mini-batch as defined in the net
fc7 = net.blobs['fc7'].data # or whatever you wantRaw inputs like in deploy model inputs can be processed by the caffe.Net.preprocess() method or caffe.Classifier convenience class since these are bottom blobs. Data layers, like HDF5_DATA or MEMORY_DATA cannot, since these are top blobs in the Net. For models with data layers, call caffe.Net.forward() as shown.
In general I suggest the caffe.Net interface. For input processing #1245 is an important step.
Documentation and examples of all this should follow #1703.