首页 > 解决方案 > caffe 到 onnx 的 libcaffeconverter 导入错误

问题描述

问题描述


我正在关注https://github.com/onnx/onnx-docker/blob/master/onnx-ecosystem/converter_scripts/caffe_coreml_onnx.ipynb上的 caffe to onnx 教程,我遇到了这个错误: ImportError: cannot import name 'libcaffeconverter '来自'coremltools'

经过进一步调查,我意识到 coremltools 目录中没有 libcaffeconverter。

系统信息


操作系统平台和分发:Windows 10 x64 ONNX 版本:1.7.0 Python 版本:3.7.7 Protobuf 版本:3.13.0 Visual Studio 版本(如果适用):2017 版本 15.9.28307.1234

复制说明


创建一个新环境并运行“pip install coremltools==4.0b3”

在https://github.com/onnx/onnx-docker/blob/master/onnx-ecosystem/converter_scripts/caffe_coreml_onnx.ipynb运行代码

或者

跑:

导入 coremltools coremltools.converters.caffe.convert(None)

预期行为


我希望代码根据代码中指定的 caffe 文件创建并保存一个 onnx 文件

标签: pythonneural-networkcaffeonnxcoremltools

解决方案


TL;DR:切换到 python 3.6

像问题所在的 OP 一样import coremltools coremltools.converters.caffe.convert(None),产生 `ImportError: cannot import name 'libcaffeconverter' 这可以通过在 python 3.6 中使用虚拟环境来避免

解决方法:

  1. 在终端中使用您选择的包管理器创建一个 python 3.6 环境: conda create -n <your env name here> python=3.6 anacondavirtualenv --python=/usr/bin/python3.6

  2. 激活虚拟环境 conda activate <your env name here>(或 pip 等价物)

  3. 导航到您的项目目录并运行您的文件 python <your script here>.py

现在它应该按计划工作


推荐阅读