打开deploy.prototxt时出现RuntimeError

时间:2016-04-24 20:11:40

标签: python caffe

我正在尝试运行一个带有caffe的简单代码,该代码应该打开deploy.prototxt但是它无法打开文件并抛出此错误

RuntimeError: Could not open file /home/ebadawy/git/caffemodels/bvlc_reference_caffenet/deploy.prototxt

这是我的代码

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['figure.figsize'] = (10, 10)        # large images
plt.rcParams['image.interpolation'] = 'nearest'  # don't interpolate:     show square pixels
plt.rcParams['image.cmap'] = 'gray'  # use grayscale output rather than a (potentially misleading)
                                     # color heatmap
caffe_root = '/home/ebadawy/git/caffe'

import os
if os.path.isfile(caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'):
    print('CaffeNet found.')
else:
    print('Downloading pre-trained CaffeNet model...')
    os.system('../scripts/download_model_binary.py ../models/bvlc_reference_caffenet')

import caffe

caffe.set_mode_cpu()
model_def = caffe_root + 'models/bvlc_reference_caffenet/deploy.prototxt'
model_weights = caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'

net = caffe.Net(model_def,      # defines the structure of the model
            model_weights,  # contains the trained weights
            caffe.TEST)     # use test mode (e.g., don't perform dropout)

我正在使用archlinux + python3.5

3 个答案:

答案 0 :(得分:0)

我发现我忘了追加/ caffe_root“非常愚蠢的错误!”

答案 1 :(得分:0)

在你的caffe_root末尾添加反斜杠,如

caffe_root = '/home/ebadawy/git/caffe/'

我猜你的路径应该是指caffe / models,而不是caffemodels。 祝你好运

答案 2 :(得分:0)

我使用包含deploy.prototxt文件的目录的绝对路径解决了这个问题。