https://blog.csdn.net/jesse_mx/article/details/53404563
安装caffe-ssd前,要先安装CUDA和CUDNN
安装CUDA包,下载的版本要与TK1的CUDA Driver版本一致,否则后面的samples无法执行.
TX1,2.4 cuda-repo-l4t-8-0-local_8.0.34-1_arm64.deb
https://blog.csdn.net/zyazky/article/details/52388605
1.安装CUDA包
sudo dpkg -i cuda-repo-l4t-8-0-local_8.0.34-1_arm64.deb
2.更新apt-get
sudo apt-get update
3.安装samples和toolkit
sudo apt-get install cuda-samples-8-0
sudo apt-get install cuda-toolkit-8-0
4.设置当前用户下可以访问GPU
sudo usermod -a -G video $USER
5.修改环境变量
cd ~
vim .bashrc
在最后一行加上:
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib:$LD_LIBRARY_PATH
source .bashrc
6.查看编译环境是否安装成功
cd /usr/local/cuda
nvcc -V
7.编译与运行例程
查看当前目录中是否有samples:ll
复制samples:cuda-install-samples-6.0.sh /home/ubuntu/
cd NVIDIA_CUDA-8.0_Samples/
ls
make
https://blog.csdn.net/lengconglin/article/details/77506386
https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#axzz4qYJp45J2
unzip cuDNN-v5.1.zip
cd cuDNN
2.3.2. Installing from a Debian File
Navigate to your <cudnnpath> directory containing cuDNN Debian file.
Install the runtime library, for example:
sudo dpkg -i libcudnn5_5.1.5-1+cuda8.0_arm64.deb
Install the developer library, for example:
sudo dpkg -i libcudnn5-dev_5.1.5-1+cuda8.0_arm64.deb
Install the code samples and the cuDNN Library User Guide, for example:
sudo dpkg -i libcudnn5-doc_5.1.5-1+cuda8.0_arm64.deb
2.4. Verifying
Copy the cuDNN sample to a writable path.
$cp -r /usr/src/cudnn_samples_v5/ $HOME
Go to the writable path.
$ cd $HOME/cudnn_samples_v5/mnistCUDNN
Compile the mnistCUDNN sample.
$make clean && make
Run the mnistCUDNN sample.
$ ./mnistCUDNN
If cuDNN is properly installed and running on your Linux system, you will see a message similar to the following:
Test passed!
安装依赖包
依次安装以下依赖项,如果不想每一次install都出现yes or no的提示项,可以在命令末尾加上“-y”。
$ sudo apt-get install build-essential -y #必要的编译工具依赖
- 1
$ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
- 1
$ sudo apt-get install --no-install-recommends libboost-all-dev
- 1
$ sudo apt-get install libatlas-base-dev
- 1
$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
- 1
PS.毕竟不是笔记本电脑,下载安装过程可能极为缓慢,需要有充足的时间和耐心。
安装easy_install和pip
pip和easy_install的作用是方便以后安装python软件包。
下载安装easy_install
$ wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
- 1
也可以使用博主上传的py文件:ez_setup.py
$ sudo python ez_setup.py --insecure
- 1
下载安装pip
$ wget https://bootstrap.pypa.io/get-pip.py
- 1
也给出下载地址:get-pip.py
$ sudo python get-pip.py
- 1
PS.如果以上都两个包都很难安装上,也没关系。不过,至少要安装python-pip,使用如下命令:sudo apt-get install python-pip
安装python常用库
$ sudo apt-get install libblas-dev liblapack-dev libatlas-base-dev gfortran python-numpy
- 1
克隆ssd源码
$ git clone https://github.com/weiliu89/caffe.git
$ cd caffe/
$ git checkout ssd # 切换至分支ssd
- 1
- 2
- 3
安装pycaffe所需依赖包
$ cd ~/caffe/python
$ sudo su # 使用超级权限
$ for req in $(cat "requirements.txt"); do pip install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
- 1
- 2
- 3
PS.终端输入Ctrl+Shift+d退出sudo su模式
编译caffe-ssd
这里建议先把能改的都改了,最后进行编译,一次就可以成功,可以节省不少时间。
修改Makefile.config
$ cd ~/caffe
$ cp Makefile.config.example Makefile.config
$ gedit Makefile.config
- 1
- 2
- 3
- 将
USE_CUDNN := 1
取消注释 INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
后面打上一个空格 然后添加/usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
后面打上一个空格,然后添加/usr/lib/aarch64-linux-gnu/hdf5/serial/
- 在
CUDA_ARCH :=
后面加一句-gencode arch=compute_53,code=sm_53
,最好同时删除sm_35以下以及sm_53以上的条目
说明:第1步的作用是使用cudnn编译,第2、3步是添加hdf5的路径,这个路径和x86的PC是不一样的,没有的话会出现找不到hdf5.h的错误,第4步是为了匹配TX1的GPU计算能力,因为查到其计算能力为5.3,加上之后使得GPU加速发挥得更好。
如有需要,可参考博主的配置文件:Makefile.config for SSD
修改Makefile
$ cd ~/caffe
$ gedit Makefile
- 1
- 2
进入文件,修改NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
为 NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
说明:修改这一步是为了避免出现string.h ‘memcy’ was not declared in this scope
这样的错误,这种错误通常是由于gcc版本太新而导致的。
建立hdf5软连接
$ cd /usr/lib/aarch64-linux-gnu
$ sudo ln libhdf5_serial.so.10.1.0 libhdf5.so
$ sudo ln libhdf5_serial_hl.so.10.0.2 libhdf5_hl.so
$ sudo ldconfig # 使连接生效
- 1
- 2
- 3
- 4
说明:这一步是为了建立软连接,避免出现找不到lhdf5_hl和lhdf5的错误。
make caffe-ssd
$ cd ~/caffe
$ make all -j4
$ make test -j4
$ make runtest -j4 # 如果能运行demo,make test & runtest非必须
$ make pycaffe -j4
$ make matcaffe -j4 # 可选,但要修改其他选项,参看底部文献
- 1
- 2
- 3
- 4
- 5
- 6
PS.编译过程中可能会出现nvcc warning: The 'compute_20'and 'sm_21' architectures are ......
这种警告,原因是TX1的计算能力是5.3,管不到2.0的情况,可以在Makefile.config中删除“compute_20”所在条目;也可能会提示找不到openblas库,那就继续安装openblas:sudo apt-get install libopenblas-dev
,然后重新编译。
$ cd ~/caffe/python
$ python
$ import caffe
- 1
- 2
- 3
上面是在测试Python环境,只要没报错,就可以说明编译成功了。也有可能会出警告:UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment
这种情况也不要紧,可用下面命令消除之(终端Python环境下):
$ import matplotlib
$ matplotlib.use('TkAgg')
- 1
- 2
PS.make runtest -j4
居然运行了一个多小时,已经无力吐槽。。。
测试AlexNet
$ cd ~/caffe
$ ./build/tools/caffe time --gpu 0 --model
$ ./models/bvlc_alexnet/deploy.prototxt
- 1
- 2
- 3
测试结果为total time:10687.4ms
运行caffe-ssd
在Jetson TX1上运行ssd的过程和电脑上基本一样,详细的步骤可以参考博主的文章:
SSD:Single Shot MultiBox Detector的安装配置和运行
这里,仍然简要说下步骤:
下载使用已有模型
想直接看看ssd效果的话,可以下载作者训练好的模型:下载地址
得到了一个压缩包:models_VGGNet_VOC0712_SSD_300x300.tar.gz ,将其解压,把其中的VGGNet文件夹放到/home/ubuntu/caffe/models/目录之下。
增加pycaffe环境变量
$ cd
$ echo "export PYTHONPATH=/home/ubuntu/caffe/python:$PYTHONPATH" >> ~/.profile
$ source ~/.profile
$ echo $PYTHONPATH #检查环境变量的值
- 1
- 2
- 3
- 4
说明:如果没有这一步的话,可能会出现no module named caffe
或者no module named caffe-proto
这种错误。
进行webcam检测
$ cd ~/caffe
$ python examples/ssd/ssd_pascal_webcam.py
- 1
- 2
按理说过一会应该会出现检测窗口,但非常不幸的是,窗口全黑,只看到帧率,看不见画面。原因推测是Jetson TX1的CSI摄像头接口不支持这种程序调用,没办法,只得外接USB摄像头来看演示效果。首先在.profile文件中添加环境变量export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libv4l/v4l1compat.so
,然后在py文件中修改”webcam_id”为1即可。
进行video检测
$ cd ~/caffe
$ python examples/ssd/ssd_pascal_video.py
- 1
- 2
这里会对内置的演示视频进行检测,这次没有出问题,可以运行成功,我就不放图了,效果和电脑比较有一定差距,帧率比较低,看以后能不能想办法加速一下。
PS.esc键可以退出窗口,在终端键入Ctrl+Shift+c可强制退出。
进行image检测
参看博主之前的博文:SSD: Single Shot MultiBox Detector检测单张图片
TX1开发板也研究一周了,ssd也还算能跑的通,看来下一步就得训练自己的数据模型了。