Using the GPU, despite setting CPU_Only, leads to an unexpected keyword argument

I install Caffe on a Ubuntu 14.04 virtual server with CUDA installed (without driver) using https://github.com/BVLC/caffe/wiki/Ubuntu-14.04-VirtualBox-VM as inspiration. During the installation process, I edited the MakeFile to include "CPU_ONLY := 1" before creating it. However, it seems that Caffe is still trying to use the GPU. When I try to run a test case, I get the following error:

 python python/classify.py examples/images/cat.jpg foo Traceback (most recent call last): File "python/classify.py", line 130, in <module> main(sys.argv) File "python/classify.py", line 103, in main channel_swap=channel_swap) TypeError: __init__() got an unexpected keyword argument 'gpu' 

How can I fix this and start the CPU completely?

+8
python caffe
source share
4 answers

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')] 
+13
source share

Currently, there are some problems due to the large number of interface changes made by caffe developers. Python Wrapper has not yet been updated with these changes.

See this PR which fixes the problem: https://github.com/BVLC/caffe/pull/1964

+2
source share

The same error was resolved in another google group: -

Where all you have to do is change this:

  mean=np.load(mean_file) 

:

 mean=np.load(mean_file).mean(1).mean(1) 

Google Group: middle form is not compatible with input form

+2
source share

only one typo from user 2696499

 if ms != inputs[in_][1:] 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.') ''' 
0
source share

All Articles