nano上 Ultra-Light-Fast-Generic-Face-Detector-1MB 的配置
目錄
本文的目的是在nano上配置 1M lightweight face detection model (1MB輕量級人臉檢測模型) ,nano本身環境 ubuntu18.04,python3.6.8。
檢查cuda環境是否配置
nano默認安裝的cuda10.0,但是沒有自動配置cuda環境,所以要先進行環境檢查。
- 檢查cuda環境
$ nvcc -V
如果沒有正常顯示cuda版本的話就進行如下配置:
$ sudo gedit ~/.bashrc
然後將以下內容拷貝至文檔最後
export PATH=/usr/local/cuda-10.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-10.0
然後刷新環境重新打開控制檯輸入nvcc -V命令查看是否成功
$ source ~/.bashrc
增加swap空間
由於nano內存有限,直接編譯pytorch會導致死機,所以強烈建議給散熱片上增加一個風扇,其次是需要增加swap空間,如果是使用我提供的whl直接安裝,還是需要執行本步驟,實測如果不增加swap,運行人臉檢測時會非常卡進而死機。
- 下載源碼
$ mkdir -p ~/nano
$ cd ~/nano
$ git clone https://github.com/ncnynl/installSwapfile
$ cd installSwapfile
- 安裝後,默認增加6G空間在/mnt/swapfile
$ sh installSwapfile.sh
pytorch-gpu 1.4.0編譯
其實 lightweight face detection model (1MB輕量級人臉檢測模型) 官方要求是pytorch1.2.0,但是我下載錯誤導致編譯了1.4.0,但是實測可以正常使用,所以無論是1.2.0還是1.4.0都無所謂。
可以自己按照以下教程編譯(大概需要24小時左右),或者直接下載我編譯好的文件,歡迎支持CSDN積分 😃
CSDN: pytorch1.4.0 for nano
某度: pytorch1.4.0 for nano.
- requirements.txt
future
numpy
pyyaml
requests
setuptools
six
typing
- 下載源碼 (v1.4.0是pytorch版本,可以根據自己需求修改- )
$ git clone -b v1.4.0 --recursive http://github.com/pytorch/pytorch
$ cd pytorch
$ git submodule sync
$ git submodule update --init --recursive
- 配置環境變量
$ export USE_NCCL=0
$ export USE_DISTRIBUTED=0
$ export TORCH_CUDA_ARCH_LIST="5.3;6.2"
- 構建wheel 針對python3
$ sudo apt-get install python3-pip cmake
$ sudo pip3 install -U setuptools
$ sudo pip3 install -r requirements.txt
$ pip3 install scikit-build --user
$ python3 setup.py bdist_wheel
- 編譯完成後的whl文件位置
$ cd dist
$ ls
torch-1.4.0a0+36d17f4-cp36-cp36m-linux_aarch64.whl
- 安裝
# Python 3.6 (download pip wheel from above)
$ pip3 install torch-1.4.0a0+36d17f4-cp36-cp36m-linux_aarch64.whl --user
- pip安裝torchvision
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple torchvision --user
- 如果網速不好可以考慮源碼編譯
$ git clone https://github.com/pytorch/vision
$ cd vision
$ git checkout -b v0.4.0
$ sudo python3 setup.py install
OpenCV編譯
本文提供的方式需要消耗大量的存儲空間,儘量保證有11G的空間,編譯完成後刪除源碼包即可釋放空間。如果沒有足夠的空間可以自己按照一般得方式編譯即可。
- nano一鍵配置opencv代碼,複製存儲爲.sh運行即可
#!/bin/bash
#
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA Corporation and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA Corporation is strictly prohibited.
#
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <Install Folder>"
exit
fi
folder="$1"
user="nvidia"
passwd="nvidia"
echo "** Install requirement"
sudo apt-get update
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install -y python2.7-dev python3.6-dev python-dev python-numpy python3-numpy
sudo apt-get install -y libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install -y libv4l-dev v4l-utils qv4l2 v4l2ucp
sudo apt-get install -y curl
sudo apt-get update
echo "** Download opencv-4.0.0"
cd $folder
curl -L https://github.com/opencv/opencv/archive/4.0.0.zip -o opencv-4.0.0.zip
curl -L https://github.com/opencv/opencv_contrib/archive/4.0.0.zip -o opencv_contrib-4.0.0.zip
unzip opencv-4.0.0.zip
unzip opencv_contrib-4.0.0.zip
cd opencv-4.0.0/
echo "** Building..."
mkdir release
cd release/
cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="5.3" -D CUDA_ARCH_PTX="" -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.0.0/modules -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python2=ON -D BUILD_opencv_python3=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j3
sudo make install
sudo apt-get install -y python-opencv python3-opencv
echo "** Install opencv-4.0.0 successfully"
echo "** Bye :)"
Ultra-Light-Fast-Generic-Face-Detector-1MB 環境配置
1MB lightweight face detection model (1MB輕量級人臉檢測模型)
$ git clone https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB
$ cd Ultra-Light-Fast-Generic-Face-Detector-1MB
需要安裝的環境在requirements.txt,其中的opencv已經在上一步進行編譯