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

Python classifier.py crash when running classification.ipynb #2041

Closed
dgmp88 opened this issue Mar 5, 2015 · 5 comments
Closed

Python classifier.py crash when running classification.ipynb #2041

dgmp88 opened this issue Mar 5, 2015 · 5 comments

Comments

@dgmp88
Copy link

dgmp88 commented Mar 5, 2015

I was getting the following error running the classification.ipynb notebook on a fresh installation on OSX:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-7167c0e21af1> in <module>()
----> 1 prediction = net.predict([input_image])  # predict takes any number of images, and formats them for the Caffe net automatically
      2 print 'prediction shape:', prediction[0].shape
      3 plt.plot(prediction[0])
      4 print 'predicted class:', prediction[0].argmax()

/Users/george/Documents/caffe/python/caffe/classifier.py in predict(self, inputs, oversample)
     84             caffe_in[ix] = self.transformer.preprocess(self.inputs[0], in_)
     85         out = self.forward_all(**{self.inputs[0]: caffe_in})
---> 86         predictions = out[self.outputs[0]].squeeze(axis=(2,3))
     87 
     88         # For oversampling, average predictions across crops.

ValueError: 'axis' entry 2 is out of bounds [-2, 2)

which I was able to fix by deleting the arguments for squeeze so that 86 looks like this:

predictions = out[self.outputs[0]].squeeze()
@dgmp88
Copy link
Author

dgmp88 commented Mar 5, 2015

Hmm, though doing this means that in the next section of classification.ipynb, when oversampling is switched off, the results don't make sense:

print 'prediction shape:', prediction[0].shape
plt.plot(prediction[0])
print 'predicted class:', prediction[0].argmax()

prediction shape: ()
predicted class: 0

unless I remove the indexing:

print 'prediction shape:', prediction.shape
plt.plot(prediction)
print 'predicted class:', prediction.argmax()

prediction shape: (1000,)
predicted class: 281

@seanbell
Copy link

seanbell commented Mar 5, 2015

I think that the problem is that some of the Python code hasn't yet been updated to match #1970 which was recently merged into master.

Perhaps there should be tests for python/caffe/classifier.py and all the steps in examples/classification.ipynb. Ideally, these kinds of bugs would be identified by Travis before major changes are merged.

@shelhamer
Copy link
Member

@seanbell is right about the cause. We haven't come up with a good method for auto-checking the notebooks but these would be valuable integration checks that catch these kinds of issues. I suppose we could at least check they not crash.

There hasn't been a chance to fix these yet but this is on the list. If anyone has fixed these already, PRs are welcome.

@dgmp88
Copy link
Author

dgmp88 commented Mar 5, 2015

Done. I don't know why squeeze was specifying the axis though, so hope I'm not breaking anything.

shelhamer added a commit to shelhamer/caffe that referenced this issue Mar 7, 2015
@latharam
Copy link

I am facing the same problem but with detector.py

Am getting the same error:
predictions = out[self.outputs[0]].squeeze(axis=(2,3))
ValueError: 'axis' entry 2 is out of bounds [-2, 2)

removing the arguments from
predictions = out[self.outputs[0]].squeeze(axis=(2,3))
and making it
predictions = out[self.outputs[0]].squeeze()
fixes this problem but later

when I execute the following piece of code from http://nbviewer.ipython.org/github/bvlc/caffe/blob/master/examples/detection.ipynb

---->predictions_df = pd.DataFrame(np.vstack(df.prediction.values), columns=labels_df['name'])
print(predictions_df.iloc[0])

I got the following error
Traceback (most recent call last):
File "ipynotebuk.py", line 22, in
predictions_df = pd.DataFrame(np.vstack(df.prediction.values), columns=labels_df['name'])
File "/home/lpemula/LPIR_Caffe/env/lib/python2.7/site-packages/pandas/core/frame.py", line 239, in init
copy=copy)
File "/home/lpemula/LPIR_Caffe/env/lib/python2.7/site-packages/pandas/core/frame.py", line 399, in _init_ndarray
return create_block_manager_from_blocks([values.T], [columns, index])
File "/home/lpemula/LPIR_Caffe/env/lib/python2.7/site-packages/pandas/core/internals.py", line 3534, in create_block_manager_from_blocks
construction_error(tot_items, blocks[0].shape[1:], axes, e)
File "/home/lpemula/LPIR_Caffe/env/lib/python2.7/site-packages/pandas/core/internals.py", line 3515, in construction_error
passed,implied))
ValueError: Shape of passed values is (1000, 1570), indices imply (200, 1570)

If I modify it as below,
predictions_df = pd.DataFrame(np.vstack(df.prediction.values))

It runs fine but I am not sure if what I did is right. Please let me know the right fix for this.

cbfinn pushed a commit to cbfinn/caffe that referenced this issue Aug 12, 2015
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

Successfully merging a pull request may close this issue.

4 participants