karpathy / neuraltalk

NeuralTalk is a Python+numpy project for learning Multimodal Recurrent Neural Networks that describe images with sentences.
5.4k stars 1.32k forks source link

CAFFE API error #14

Closed Beanocean closed 9 years ago

Beanocean commented 9 years ago

When I tried to run the python scripts python_features/extract_features.py today, I met with a problem as follow:

Traceback (most recent call last):
  File "./extract_features.py", line 102, in <module>
    net = caffe.Net(args.model_def, args.model)
Boost.Python.ArgumentError: Python argument types in
    Net.__init__(Net, str, str)
did not match C++ signature:
    __init__(boost::python::api::object, std::string, std::string, int)
    __init__(boost::python::api::object, std::string, int)

Then I search this error on the Internet, and I find a same issue in caffe's issue page: Caffe#1905. I think it's an error caused by the update of Caffe's API. So I change the code in extract_features.py#101 as: net = caffe.Net(args.model_def, args.model, caffe.TEST). It worked, but a new problem came out:

Traceback (most recent call last):
  File "./extract_features.py", line 102, in <module>
    caffe.set_phase_test()
AttributeError: 'module' object has no attribute 'set_phase_test'

I think the reason is that some APIs in python_features/extract_features.py are too old.

karpathy commented 9 years ago

Gah, yeah you're right they moved the phase from caffe global into Net class. In your case since you already added the phase as 3rd arg in constructor of Net (the new way), should you just delete that line that's causing trouble? You've already set the test phase with your fix.

Beanocean commented 9 years ago

Thank you very much @karpathy . I have fixed it as you advised.

ghost commented 9 years ago

Hi I'm a total newbie in Caffe in CNNs. I have the same problem when I wanted to run the code for visualization. I didn't get the solution from your response. Could you please explain it a little more? I have n't done what Beanocean did first I mean: "So I change the code in extract_features.py#101 as: net = caffe.Net(args.model_def, args.model, caffe.TEST). It worked, but a new problem came out:"

ShraddhaBhattad commented 9 years ago

Hi , I want to check the trained model on my own set of images, and while running extract_features.m and after downloading caffe , "caffe('set_device', 1); " is not running. I couldn't find caffe.m

Beanocean commented 9 years ago

Hi I'm a total newbie in Caffe in CNNs. I have the same problem when I wanted to run the code for visualization. I didn't get the solution from your response. Could you please explain it a little more? I have n't done what Beanocean did first I mean: "So I change the code in extract_features.py#101 as: net = caffe.Net(args.model_def, args.model, caffe.TEST). It worked, but a new problem came out:"

I think we have different problem though you got the same error. my problem is about feature extraction, but yours is about visualization. Here you can see the different version of python_features/extract_features.py. My problem was caused by the update of CAFFE's API, and it has been fixed up in new version.

Beanocean commented 9 years ago

Hi , I want to check the trained model on my own set of images, and while running extract_features.m and after downloading caffe , "caffe('set_device', 1); " is not running. I couldn't find caffe.m

I think you need to compile matcaffe firstly(execute make matcaffe in your caffe's directory), and add caffe path to the system path of your MATLAB by using addpath("Your caffe path")

HugoNip commented 8 years ago

I also met this problems:

my code follows here:

import numpy as np import matplotlib.pyplot as plt

Make sure that caffe is on the python path:

caffe_root = '/home/guyunee/Desktop/caffe-master/' # this file is expected to be in {caffe_root}/examples,建议使用绝对路径 import sys sys.path.insert(0, caffe_root + 'python')

import caffe

plt.rcParams['figure.figsize'] = (10, 10) plt.rcParams['image.interpolation'] = 'nearest' plt.rcParams['image.cmap'] = 'gray'

caffe.set_phase_test() caffe.set_mode_cpu() net = caffe.Classifier(caffe_root + 'models/bvlc_reference_caffenet/deploy.prototxt', caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel')

input preprocessing: 'data' is the name of the input blob == net.inputs[0]

net.set_mean('data', np.load(caffe_root + 'python/caffe/imagenet/ilsvrc_2012_mean.npy')) # ImageNet mean net.set_raw_scale('data', 255) net.set_channel_swap('data', (2,1,0))

it says:

AttributeError Traceback (most recent call last)

in () ----> 1 caffe.Net.set_phase_test() AttributeError: type object 'Net' has no attribute 'set_phase_test' AttributeError: 'Classifier' object has no attribute 'set_mean' how to solve the problems? because it is too old? @karpathy