打开deploy.prototxt时出现RuntimeError

3

我正在尝试使用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)

我正在使用Arch Linux和Python 3.5。

3个回答

0

我发现我忘记为caffe_root附加/,这是一个非常愚蠢的错误!


0
在你的caffe_root后面添加反斜杠,例如:
caffe_root = '/home/ebadawy/git/caffe/'

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


0

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接