2023/10/30

build caffe for snpe

snpe 1.X 版 的 setup 好像比較簡單(?)

以 1.68 版來看。
snpe-caffe-to-dlc 是用 python3,加上其他onnx, pytorch 也都是用 python3。
所以 build caffe 得時候,要設定能 python3

可以參考這一個人 寫的 Makefile.config:
USE_CUDNN := 0
CPU_ONLY := 1
USE_OPENCV := 0
USE_LEVELDB := 0
USE_LMDB := 0
BLAS := open
ANACONDA_HOME := /opt/conda/envs/snpe
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
                $(ANACONDA_HOME)/include/python3.6m \
                $(ANACONDA_HOME)/lib/python3.6/site-packages/numpy/core/include
PYTHON_LIB := $(ANACONDA_HOME)/lib
PYTHON_LIBRARIES := boost_python36 python3.6m
WITH_PYTHON_LAYER := 1
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
USE_NCCL := 0
USE_PKG_CONFIG := 0
BUILD_DIR := build
DISTRIBUTE_DIR := distribute
DEBUG := 0
TEST_GPUID := 0
Q ?= @
依照這個修改 Makefile.config 需要自己 build libboost_python.
參考另一個 caffe for python3 的說明。
library 改 boost_python3 就可以 make pycaffe OK



參考這一篇,用 conda install 的方式。
用 conda install caffe (python2.7.17) run snpe-caffe-to-dlc 是 failed:
$ snpe-caffe-to-dlc --input_network deploy.prototxt --caffe_bin mobilenet_iter_73000.caffemodel --output_path mobile_net.dlc
Encountered Error: ERROR_CAFFE_NOT_FOUND: Error loading caffe, Message: No module named 'caffe'. PYTHONPATH: 
['/home/charles-chang/snpe-1.68.0.3932/bin/x86_64-linux-clang', '/home/charles-chang/snpe-1.68.0.3932/models/alexnet/scripts', 
 '/home/charles-chang/snpe-1.68.0.3932/models/lenet/scripts', '/home/charles-chang/snpe-1.68.0.3932/lib/python', 
 '/home/charles-chang/qidk/Solutions/VisionSolution1-ObjectDetection/model', 
 '/usr/lib/python36.zip', '/usr/lib/python3.6', 
 '/usr/lib/python3.6/lib-dynload', 
 '/home/charles-chang/.local/lib/python3.6/site-packages', 
 '/usr/local/lib/python3.6/dist-packages', 
 '/usr/lib/python3/dist-packages']

Stack Trace:
Traceback (most recent call last):
  File "/home/charles-chang/snpe-1.68.0.3932/lib/python/qti/aisw/converters/caffe/caffe_to_ir.py", line 92, in convert
    import caffe
ModuleNotFoundError: No module named 'caffe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/charles-chang/snpe-1.68.0.3932/bin/x86_64-linux-clang/snpe-caffe-to-dlc", line 46, in <module>
    graph = converter.convert()
  File "/home/charles-chang/snpe-1.68.0.3932/lib/python/qti/aisw/converters/caffe/caffe_to_ir.py", line 95, in convert
    raise Exception(code_to_message.get_error_message("ERROR_CAFFE_NOT_FOUND")(e.msg, str(sys.path)))
Exception: ERROR_CAFFE_NOT_FOUND: Error loading caffe, Message: No module named 'caffe'. PYTHONPATH: 
['/home/charles-chang/snpe-1.68.0.3932/bin/x86_64-linux-clang', 
 '/home/charles-chang/snpe-1.68.0.3932/models/alexnet/scripts',
 '/home/charles-chang/snpe-1.68.0.3932/models/lenet/scripts',
 '/home/charles-chang/snpe-1.68.0.3932/lib/python',
 '/home/charles-chang/qidk/Solutions/VisionSolution1-ObjectDetection/model',
 '/usr/lib/python36.zip', '/usr/lib/python3.6',
 '/usr/lib/python3.6/lib-dynload',
 '/home/charles-chang/.local/lib/python3.6/site-packages',
 '/usr/local/lib/python3.6/dist-packages',
 '/usr/lib/python3/dist-packages']
看起來也是因為python3 的關係。

沒有留言:

張貼留言