nano上 1M lightweight face detection model 的配置 (pytorch1.4.0 gpu)

目录

本文的目的是在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已经在上一步进行编译

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章