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

How to pycaffe #1774

Closed
3 of 4 tasks
shelhamer opened this issue Jan 22, 2015 · 7 comments
Closed
3 of 4 tasks

How to pycaffe #1774

shelhamer opened this issue Jan 22, 2015 · 7 comments

Comments

@shelhamer
Copy link
Member

shelhamer commented Jan 22, 2015

There's confusion about the Python interface. In particular users get stuck with

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 a caffe.Net and call net.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 want

Raw 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.

@erogol
Copy link
Contributor

erogol commented Jan 22, 2015

Does caffe.Net interface support real-time data passing instead of from definition file. For instance, can I get the layer values of a particular image just read by caffe.io in the code?

Also still I am pretty confident about the issue #1758 that you closed. This is an issue not the users thing.

@kamikawa
Copy link

shelhammer,Thanks for the comment to my request.

I think that one small run through sample code would be greatly helpful.

  1. convert jpg images to database. generate mean data.
  2. train by data generated
  3. test (oversampling for whole testset ) by data generated or jpg images.
    Its language does not matter.

@shelhamer
Copy link
Member Author

@erogol caffe.Net can be passed inputs in realtime for calling forward and backward to compute data / diffs for any layer. Look at the pycaffe.py code and boost::python interface.

Re: #1758 -- the Python preprocessing can work, as it does in our examples, but I agree that it is confusing which is why I advocate for #1245.

@kamikawa and all more pycaffe examples and docs are coming in February after the ICML deadline 02/06.

This was referenced Feb 19, 2015
@mees
Copy link

mees commented Feb 23, 2015

@shelhamer so for replicating the c++ lmdb results we should use your caffe.Net code snippet and for classifying images/that are not stored on lmdbs, caffe.Classifier ? I know that you have tons of stuff to do and that you are already working on it, but I would appreciate a lot if you could update or provide a python classification example, as right now it's very confusing with all the new changes.

@jamesguoxin
Copy link

@shelhamer Hello shelhamer,

Recently I switched from old version to a new version of caffe (downloaded from master branch on 31st March 2015). I've used this new version for some time and everything was fine. Now I would like to organize testing with Python script. I've done all "make all", "make test", "make runtest", "make pycaffe", "make distribute". In my Python script,

import sys
sys.path.insert(0, "/home/nviso/GitHub/caffe/distribute/python")
import caffe

This gives me import error

import caffe
File "/home/nviso/GitHub/caffe/distribute/python/caffe/init.py", line 1, in
from .pycaffe import Net, SGDSolver
File "/home/nviso/GitHub/caffe/distribute/python/caffe/pycaffe.py", line 13, in
from ._caffe import Net, SGDSolver
ImportError: libcaffe.so: cannot open shared object file: No such file or directory

I noticed that libcaffe.so is also in the /distribute/lib folder, so I modified the Python script to

import sys
sys.path.insert(0, "/home/nviso/GitHub/caffe/distribute/python")
sys.path.insert(0, "/home/nviso/GitHub/caffe/distribute/lib")
import caffe

But still I get this import error

import caffe
File "/home/nviso/GitHub/caffe/distribute/python/caffe/init.py", line 1, in
from .pycaffe import Net, SGDSolver
File "/home/nviso/GitHub/caffe/distribute/python/caffe/pycaffe.py", line 13, in
from ._caffe import Net, SGDSolver
ImportError: libcaffe.so: cannot open shared object file: No such file or directory

My code is working fine with previous version of caffe. So I'm not sure if it's caused by the version change. Did you experience similar error? Thanks a lot for your help!

@Jianqiang
Copy link

Hi,

May I ask whether there is a natural way in either command line or python interface to make predictions and collect the results for ALL batches from an input data (e.g. HD5)?

I understand that with the correct number of iterations(=#total/#batch_size), and net.forward(), it will do the work for the test data that is pre-defined in the prototxt files (This is a little bit awkward itself though).

But what if one would like to make predictions for new data and get probabilistic scores out of the predictions, rather than just get a accuracy number on a benchmark dataset? Is there a way to feed customized input (not necessarily 4-dim image input) of data and directly make prediction for them, instead of for data that is defined in the prototxt?

Thanks a lot!

@shelhamer
Copy link
Member Author

Closing since there are now several notebook examples of pycaffe, Python data layers handily cover many use cases, and the Input layer fallback is always there.

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

No branches or pull requests

6 participants