I will add a few words to Mailerdaimon's answer.
I followed the installation guide ( https://github.com/BVLC/caffe/wiki/Ubuntu-14.04-VirtualBox-VM ) to configure Caffe in my vagrant virtual machine. FYI, virtual machines DO NOT support GPU acceleration. Let's get back to business after I fix the "CPU / GPU switch in sample scripts" ( https://github.com/BVLC/caffe/pull/2058 ) and add the options --print_results --labels_file ( https: / /github.com/jetpacapp/caffe/blob/master/python/classify.py ) to 'python / classify.py', this command is' ./python/classify.py./examples/images/cat.jpg foo -print_results 'still produces the following error:
Traceback (most recent call last): File "./python/classify.py", line 175, in <module> main(sys.argv) File "./python/classify.py", line 129, in main channel_swap=channel_swap) File "/home/vagrant/caffe/python/caffe/classifier.py", line 38, in __init__ self.transformer.set_mean(in_, mean) File "/home/vagrant/caffe/python/caffe/io.py", line 267, in set_mean raise ValueError('Mean shape incompatible with input shape.') ValueError: Mean shape incompatible with input shape.
Then I give the form "average" (3 * 256 * 256) and "enter" (3 * 227 * 227). Obviously, these two forms are incompatible. But older versions of 'set_mean ()' DO NOT throw an error, so I dig up the python code and find out that the old set_mean () function looks like this (python / caffe / pycaffe.py, line 195-202, https://github.com/ jetpacapp / caffe / ):
if mode == 'elementwise': if mean.shape != in_shape[1:]: # Resize mean (which requires H x W x K input in range [0,1]). m_min, m_max = mean.min(), mean.max() normal_mean = (mean - m_min) / (m_max - m_min) mean = caffe.io.resize_image(normal_mean.transpose((1,2,0)), in_shape[2:]).transpose((2,0,1)) * (m_max - m_min) + m_min
But in the latest Caffe, contributors encapsulate 'set_mean ()' and other conversion functions into the Transformer class. The new function 'set_mean ()' looks like this: (python / caffe / io.py, line 253-254, https://github.com/BVLC/caffe/ ):
if ms != self.inputs[in_][1:]: raise ValueError('Mean shape incompatible with input shape.')
Jesus said how these two functions can be the same? Therefore, I change the new "set_mean ()", comment on the proposal to increase the error and add the procedure for reinstalling the form, as in the old "set_mean ()".
if ms != ins: print(self.inputs[in_]) in_shape = self.inputs[in_][1:] m_min, m_max = mean.min(), mean.max() normal_mean = (mean - m_min) / (m_max - m_min) mean = resize_image(normal_mean.transpose((1,2,0)), in_shape[1:]).transpose((2,0,1)) * \ (m_max - m_min) + m_min ''' raise ValueError('Mean shape incompatible with input shape.') '''
Voila, the problem is resolved.
Classifying 1 inputs. Done in 1.17 s. [('tabby', '0.27933'), ('tiger cat', '0.21915'), ('Egyptian cat', '0.16064'), ('lynx', '0.12844'), ('kit fox', '0.05155')]