AttributeError: 'Classifier' object has no attribute 'set_phase_test'

2,859 views
Skip to first unread message

gamepip...@gmail.com

unread,
Jan 21, 2015, 2:34:52 AM1/21/15
to caffe...@googlegroups.com
import numpy as np
import matplotlib.pyplot as plt
#%matplotlib inline

# Make sure that caffe is on the python path:
# caffe_root = '../'  # this file is expected to be in {caffe_root}/examples
caffe_root = '../../'  # this file is expected to be in {caffe_root}/examples
import sys
sys.path.insert(0, caffe_root + 'python')

import caffe

# Set the right path to your model definition file, pretrained model weights,
# and the image you would like to classify.
MODEL_FILE = caffe_root + 'models/bvlc_reference_caffenet/deploy.prototxt'
PRETRAINED = '/home/levin/project/deepLearning/caffee/caffe-master/models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'
IMAGE_FILE = caffe_root + 'images/cat.jpg'


net = caffe.Classifier(MODEL_FILE, PRETRAINED,
                       mean=np.load(caffe_root + 'python/caffe/imagenet/ilsvrc_2012_mean.npy'),
                       channel_swap=(2,1,0),
                       raw_scale=255,
                       image_dims=(256, 256))

net.set_phase_test()   ### error here
net.set_mode_cpu()


input_image = caffe.io.load_image(IMAGE_FILE)
plt.imshow(input_image)


prediction = net.predict([input_image])  # predict takes any number of images, and formats them for the Caffe net automatically
print 'prediction shape:', prediction[0].shape
plt.plot(prediction[0])
print 'predicted class:', prediction[0].argmax()


I have installed all the python requirements. and make pycaffe.   What's wrong with that?





Evan Shelhamer

unread,
Jan 21, 2015, 11:31:53 PM1/21/15
to gamepip...@gmail.com, caffe...@googlegroups.com
See https://github.com/BVLC/caffe/pull/1728 -- there was an issue with the pycaffe interface for setting phase, mode, and device. master and dev, including the examples, have been updated to the new interface.

--
You received this message because you are subscribed to the Google Groups "Caffe Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caffe-users...@googlegroups.com.
To post to this group, send email to caffe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/caffe-users/fca6f408-a2d6-4f9e-a98a-19fde8f8ec8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Toru Hironaka

unread,
Jan 29, 2015, 4:57:59 PM1/29/15
to caffe...@googlegroups.com
I got a similar problem. Try caffe.set_phase_test() instead of net.set_phase_test(). I may solve the problem. You may want to change the following net.set_mode_cpu() as well. I hope if solve your problem.

Traun Leyden

unread,
Feb 28, 2015, 2:32:50 PM2/28/15
to caffe...@googlegroups.com


On Thursday, January 29, 2015 at 1:57:59 PM UTC-8, Toru Hironaka wrote:
I got a similar problem. Try caffe.set_phase_test() instead of net.set_phase_test(). I may solve the problem. You may want to change the following net.set_mode_cpu() as well. I hope if solve your problem.


Actually it looks like caffe.set_phase_test() has been removed:

>>> import caffe
>>> dir(caffe)
['Classifier', 'Detector', 'Layer', 'Net', 'SGDSolver', 'TEST', 'TRAIN', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '_caffe', 'classifier', 'detector', 'get_solver', 'io', 'proto', 'pycaffe', 'set_device', 'set_mode_cpu', 'set_mode_gpu']

I was able to remove it from my python classify script and everything still seemed to work.

guan...@gmail.com

unread,
Jul 30, 2015, 3:13:00 AM7/30/15
to Caffe Users, gamepip...@gmail.com
There is no need to do that.I ignore this step and it doesn't matter in my caffe's predict job.
Thanks to https://groups.google.com/d/msg/caffe-users/WhWED-unIxc/Hte3QMRYUmsJ !

在 2015年1月21日星期三 UTC+8下午3:34:52,gamepip...@gmail.com写道:
Reply all
Reply to author
Forward
0 new messages