Caffe2 简明教程
Caffe2 - Verifying Access to Pre-Trained Models
在您学习在 Python 应用程序中使用预训练模型之前,让我们首先验证模型是否已安装到您的计算机上,并且可以通过 Python 代码访问。
Before you learn to use a pre-trained model in your Python application, let us first verify that the models are installed on your machine and are accessible through the Python code.
安装 Caffe2 时,预训练的模型将被复制到安装文件夹中。在拥有 Anaconda 安装的计算机上,这些模型位于以下文件夹中。
When you install Caffe2, the pre-trained models are copied in the installation folder. On the machine with Anaconda installation, these models are available in the following folder.
anaconda3/lib/python3.7/site-packages/caffe2/python/models
查看计算机上的安装文件夹中是否存在这些模型。您可以使用以下简短的 Python 脚本尝试从安装文件夹加载这些模型 −
Check out the installation folder on your machine for the presence of these models. You can try loading these models from the installation folder with the following short Python script −
CAFFE_MODELS = os.path.expanduser("/anaconda3/lib/python3.7/site-packages/caffe2/python/models")
INIT_NET = os.path.join(CAFFE_MODELS, 'squeezenet', 'init_net.pb')
PREDICT_NET = os.path.join(CAFFE_MODELS, 'squeezenet', 'predict_net.pb')
print(INIT_NET)
print(PREDICT_NET)
当脚本成功运行时,您将看到以下输出 −
When the script runs successfully, you will see the following output −
/anaconda3/lib/python3.7/site-packages/caffe2/python/models/squeezenet/init_net.pb
/anaconda3/lib/python3.7/site-packages/caffe2/python/models/squeezenet/predict_net.pb
这确认 squeezenet 模块已安装到您的计算机上,并且您的代码可以访问该模块。
This confirms that the squeezenet module is installed on your machine and is accessible to your code.
现在,您可以使用 Caffe2 squeezenet 预训练模块编写用于图像分类的 Python 代码了。
Now, you are ready to write your own Python code for image classification using Caffe2 squeezenet pre-trained module.