[TOC]

概述

文章参考:https://developer.qualcomm.com/sites/default/files/docs/snpe/setup.html

环境搭建

推荐的Ubuntu18.04

由于我的电脑不支持18.04,所以暂时使用20.04.验证是否可用。

Python环境

1
2
3
4
5
6
7
8
9
conda  create -n python36  python=3.6

# To activate this environment, use
#
# $ conda activate python36
#
# To deactivate an active environment, use
#
# $ conda deactivate

caffe环境的搭建

1
2
3
4
5
(base) frewen@freweniubuntu:~/03.ProgramSpace/20.AILearning/03.Source/caffe$ cp Makefile.config.example Makefile.config
(base) frewen@freweniubuntu:~/03.ProgramSpace/20.AILearning/03.Source/caffe$ make all
PROTOC src/caffe/proto/caffe.proto
make:protoc:命令未找到
make: *** [Makefile:639:.build_release/src/caffe/proto/caffe.pb.cc] 错误 127

提示:make:protoc:命令未找到

解决办法:

1
sudo apt-get install protobuf-c-compiler protobuf-compiler

出现错误:

1
2
3
4
5
6
7
8
9
10
11
12
PROTOC src/caffe/proto/caffe.proto
CXX .build_release/src/caffe/proto/caffe.pb.cc
CXX src/caffe/layer.cpp
In file included from ./include/caffe/blob.hpp:8,
from ./include/caffe/layer.hpp:8,
from src/caffe/layer.cpp:1:
./include/caffe/common.hpp:4:10: fatal error: boost/shared_ptr.hpp: 没有那个文件或目录
4 | #include <boost/shared_ptr.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:582:.build_release/src/caffe/layer.o] 错误 1

解决方案:https://blog.csdn.net/zhang_yang_43/article/details/78357446?locationNum=8&fps=1

解决方案:出现该错误的原因是少了依赖。

1
$ sudo apt-get install --no-install-recommends libboost-all-dev  

出现错误

1
2
3
4
5
6
7
8
9
10
11
(base) frewen@freweniubuntu:~/03.ProgramSpace/20.AILearning/03.Source/caffe$ make all
CXX src/caffe/layer.cpp
In file included from ./include/caffe/blob.hpp:8,
from ./include/caffe/layer.hpp:8,
from src/caffe/layer.cpp:1:
./include/caffe/common.hpp:5:10: fatal error: gflags/gflags.h: 没有那个文件或目录
5 | #include <gflags/gflags.h>
| ^~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:582:.build_release/src/caffe/layer.o] 错误 1

解决方法:https://blog.csdn.net/sdlypyzq/article/details/85237020

1
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

出现错误:

1
2
3
4
5
6
7
8
9
10
11
(base) frewen@freweniubuntu:~/03.ProgramSpace/20.AILearning/03.Source/caffe$ make all
CXX src/caffe/layer.cpp
In file included from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/layer.hpp:8,
from src/caffe/layer.cpp:1:
./include/caffe/util/device_alternate.hpp:34:10: fatal error: cublas_v2.h: 没有那个文件或目录
34 | #include <cublas_v2.h>
| ^~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:582:.build_release/src/caffe/layer.o] 错误 1

解决方案:https://blog.csdn.net/Dorothy_Xue/article/details/88023019

去掉Makefile.config中,CPU_ONLY := 1的注释

出现错误:

1
2
3
4
5
6
7
8
9
10
(base) frewen@freweniubuntu:~/03.ProgramSpace/20.AILearning/03.Source/caffe$ make all
CXX src/caffe/layer.cpp
In file included from ./include/caffe/util/math_functions.hpp:11,
from ./include/caffe/layer.hpp:12,
from src/caffe/layer.cpp:1:
./include/caffe/util/mkl_alternate.hpp:14:10: fatal error: cblas.h: 没有那个文件或目录
14 | #include <cblas.h>
| ^~~~~~~~~
compilation terminated.
make: *** [Makefile:582:.build_release/src/caffe/layer.o] 错误 1

解决方案:https://www.cnblogs.com/xiaochouk/p/12090862.html

1
sudo apt-get install libblas-dev

出现错误:

1
2
3
4
5
6
7
8
9
(base) frewen@freweniubuntu:~/03.ProgramSpace/20.AILearning/03.Source/caffe$ make all
CXX src/caffe/layer.cpp
CXX src/caffe/net.cpp
src/caffe/net.cpp:8:10: fatal error: hdf5.h: 没有那个文件或目录
8 | #include "hdf5.h"
| ^~~~~~~~
compilation terminated.
make: *** [Makefile:582:.build_release/src/caffe/net.o] 错误 1

解决方案:

1
2
3
# Whatever else you find you need goes here.
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/hdf5/serial
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# handle IO dependencies
USE_LEVELDB ?= 1
USE_LMDB ?= 1
# This code is taken from https://github.com/sh1r0/caffe-android-lib
USE_HDF5 ?= 1
USE_OPENCV ?= 1

ifeq ($(USE_LEVELDB), 1)
LIBRARIES += leveldb snappy
endif
ifeq ($(USE_LMDB), 1)
LIBRARIES += lmdb
endif
# This code is taken from https://github.com/sh1r0/caffe-android-lib
ifeq ($(USE_HDF5), 1)
# LIBRARIES += hdf5_hl hdf5
LIBRARIES += hdf5_serial_hl hdf5_serial
endif
ifeq ($(USE_OPENCV), 1)
LIBRARIES += opencv_core opencv_highgui opencv_imgproc

ifeq ($(OPENCV_VERSION), 3)
LIBRARIES += opencv_imgcodecs
endif

endif

Tensorflow环境的搭建

ONNX环境搭建

SNPE环境搭建

1
unzip -X snpe-1.60.0.3313.zip
1
source snpe-1.60.0.3313/bin/dependencies.sh
1
source snpe-1.60.0.3313/bin/check_python_depends.sh

设置SNPE环境变量,在~/.bashrc文件里面添加

1
export SNPE_ROOT=/home/frewen/03.ProgramSpace/20.AILearning/04.Resource/snpe-1.60.0.3313

依赖的python环境