为什么 Caffe refrense 应该在 python 中的 sys 之后?

Why Caffe refrense should go after sys in python?

我使用 Caffe 框架,我使用 python 语言并拥有以下代码:

import numpy as np
import os
import matplotlib
import sys

import matplotlib.pyplot as plt
import matplotlib.image as mpimg

caffe_root = '/home/jackson/caffe/'  # this file should be run from {caffe_root}/examples (otherwise change this line)
sys.path.insert(0, caffe_root + 'python')

import caffe

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)

问题是,当我在 sys.path.insert(0, caffe_root + 'python') 之前移动 import caffe 我收到这个错误:

F0612 09:44:35.476567 5443 upgrade_proto.cpp:928] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: /home/jackson/caffe/models/bvlc_reference_caffenet/deploy.prototxt * Check failure stack trace: * Aborted (core dumped)

Caffe 和 sys 库有冲突吗?为什么会这样?或者是因为我用 sys.path 更改了模块目录? (我应该提一下,没有 sys.path.insert 程序不会 运行)

caffe_root = '/home/jackson/caffe/'  # this file should be run from {caffe_root}/examples (otherwise change this line)
sys.path.insert(0, caffe_root + 'python')

此代码将您的 /home/jackson/caffe/ 文件夹放在您的 python 导入路径的开头,当您将其移动到 import caffe 之后时,python 在中查找 caffe PYTHONPATH 中的其他文件夹以查看是否安装了 caffe,据我所知,您可能在某个地方安装了另一个与您正在使用的 deploy.prototxt 文件不兼容的 caffe