打开时出现运行时错误 deploy.prototxt

RuntimeError while opening deploy.prototxt

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

我发现我忘记为 caffe_root 添加 / "very silly mistake!"

在你的caffe_root赞

末尾添加反斜杠
caffe_root = '/home/ebadawy/git/caffe/'

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

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