USB神經網路計算卡實作目標檢測

本文介紹以Gyrfalcon Technology公司Lightspeeur 2801S晶片為核心的USB神經網路計算卡上進行目標檢測(Object Detection)推論(Inference)。其中模型的建立、訓練與轉換部份需要在有Nvidia的GPU的電腦上進行,所使用框架為Caffe,算法為SSD(Single Shot MultiBox Detector)。本文是參照廠商的SSD模型工具包(MDK)文件實作後所做的整理,電腦使用的作業系統為Ubuntu 16.04.5 LTS (Xenial Xerus) 64-bit PC (AMD64) desktop,相關檔案的取得請聯絡” 汯采有限公司”購買”AI 64G資料U盤”。首先將SSD算法的相關檔案拷貝到家目錄:

接著進行模型開發工具解壓縮:

tar zxvf GTI_SSD_model_development_kit_v1-0.tar.gz 

安裝OpenCV 3:

cd ~/GTI_SSD_conversion_tool_v1-0/lightsprModelConvert/
sh install_opencv.sh
cd ~

參照廠商文件,進行 1.環境安裝

# 1)基礎依賴安裝:

sudo apt-get update && sudo apt-get upgrade && \
sudo apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
wget \
libatlas-base-dev \
libboost-all-dev \
libgflags-dev \
libgoogle-glog-dev \
libhdf5-serial-dev \
libleveldb-dev \
liblmdb-dev \
libprotobuf-dev \
libsnappy-dev \
protobuf-compiler \
python-pip \
python-setuptools \
python-scipy \
libopenblas-dev

# 2) python2依賴安裝

cd GTI_SSD_model_development_kit_v1-0/FilesAndInstructions/caffe-ssd/

cd python

sudo pip install --upgrade pip && \
for req in $(cat requirements.txt) pydot; do sudo pip install $req; done

# 3) CUDA(英偉達顯卡)

cd /tmp

sudo apt-get update && sudo apt-get install wget -y --no-install-recommends && \
wget "https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb" && \
sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb && \
sudo apt-get update && \
sudo apt-get install -y cuda-8-0

wget https://developer.download.nvidia.com/compute/redist/cudnn/v5.1/cudnn-8.0-linux-x64-v5.1.tgz && \
sudo tar -xzf cudnn-8.0-linux-x64-v5.1.tgz -C /usr/local && \
rm cudnn-8.0-linux-x64-v5.1.tgz && sudo ldconfig && \
cd -

# 回到Caffe原始碼目錄:

cd ~/GTI_SSD_model_development_kit_v1-0/FilesAndInstructions/caffe-ssd/

編譯Caffe前請修改Makefile.config如下所示:

PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include

再進行Caffe編譯:

# 4)編譯caffe-ssd

make clean

make all

make pycaffe

接著進行 2.模型訓練

# 1)數據準備

cd ~

tar zxvf GTI_SSD_DataSets_v1-0.tar.gz

# 進入"多目標檢測"專案目錄:

cd ~/GTI_SSD_model_development_kit_v1-0/FilesAndInstructions/ssd_typ_mdk/

訓練前請修改run_ssd_training.sh如下所示:

$TOOLS/caffe train \
--solver=$slovertxttyp \
--weights=$ssd \
--gpu 0 2>&1 | tee $LOG $@

完成後執行run_ssd_training.sh進行訓練(執行時間很久):

source run_ssd_training.sh

訓練完成後,進行 3.模型轉換 :

cd ~/GTI_SSD_conversion_tool_v1-0/lightsprModelConvert/

source setting_caffe.sh

將生成的模型放入inputs/SSD_typ並命名為SSD_typ_quant.caffemodel後進行轉換:

make SSD_typ_vgg

make SSD_typ_ssd

轉換完成後,進行 4.模型使用

cd ~

tar zxvf Gti2801_SSD_sample_v1-0.tar.gz

cp ~/GTI_SSD_conversion_tool_v1-0/lightsprModelConvert/cnn_weights_SSD_typ/vgg.dat ~/Gti2801_SSD_sample_v1-0/Data/Models/gti2801/multi-object

cp ~/GTI_SSD_conversion_tool_v1-0/lightsprModelConvert/cnn_weights_SSD_typ/ssd.bin ~/Gti2801_SSD_sample_v1-0/Data/Models/gti2801/multi-object

修改Gti2801_SSD_sample_v1-0/Data/Models/gti2801/userinput.txt,如下所示:

{
"Gti device type": 0, # 0: GTI 2801, 1: GTI 2803
"model": [
{
"Network name": "Gnet1",
"Image output format": 0, # 0: Conv out pooling, 1: Sub layers, 2: Conv out, 3: Major layers
"Dump input image": 0,
"USB write block numbers": 2048, # eMMC USB dongle block numbers for one write or read command, 2048 for best performance, 128 for USB 2.0 compatibility
"USB read delay": 15000, # Delay time (us) between eMMC USB dongle write and read commands, 4000 for gNet3, 12000 for gNet1
"USB device node": "/dev/sg1", # The first available eMMC device node, find the node name from folder /dev/ after dongle is plugged in
}
]
}

完成後編譯與執行展示程式:

cd ~/Gti2801_SSD_sample_v1-0/Sample/Linux/

cp Makefile_x86 Makefile

make

sudo chmod 777 /dev/sg1

./ssdSample -dev_id /dev/sg1

執行結果如下所示:

至此,就完成在USB神經網路計算卡上進行目標檢測SSD算法推論之驗證。

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *