1 平台:
jetson Nano + 128gtf卡+ jetpack:jetson-nano-sd-r32.1-2019-03-18 .zip
sampleSSD目录:/usr/src/tensorrt/sample/sampleSSD/
使用的data文件在“:/usr/src/tensorrt/data/ssd/
编译之后的可执行文件在:/usr/src/tensorrt/bin/
2 环境准备:
2.1 主要为了装上pillow
sudo apt-get -y install cmake
sudo apt-get install python3
sudo apt-get install python3-pip
sudo apt-get install python3-dev
sudo apt install libopenblas-dev libatlas-dev liblapack-dev
sudo apt install liblapacke-dev checkinstall
sudo pip3 install numpy scipy
sudo pip3 install pyyaml
sudo pip3 install scikit-build
sudo apt install libffi-dev
sudo pip3 install cffi
sudo apt-get install -qq protobuf-compiler python-pil python-lxml python-tk
sudo pip3 install -q Cython contextlib2 lxml matplotlib
sudo pip3 install -q pycocotools
sudo pip3 install -q pillow
2.3 8gb交换空间设置
sudo fallocate -l 8G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo "/swapfile swap swap defaults 0 0" | sudo tee --append /etc/fstab > /dev/null
3 文件准备
(这一步可以把PrepareINT8CalibrationBatches.sh和batchPrepare.py文件拷贝到其他主机上进行):
3.1a 下载VOC数据集并且转行成batches文件
sampleSSD目录:/usr/src/tensorrt/sample/sampleSSD/ 下的 PrepareINT8CalibrationBatches.sh
sudo /usr/src/tensorrt/sample/sampleSSD/ PrepareINT8CalibrationBatches.sh
等待下载voc数据集 并且转换batches(/usr/src/tensorrt/data/ssd/batches/)
3.1b如果你已经有了voc数据集(2007或者2012)
可以直接运行batchPrepare.py 直接进行batches转换:
python batchPrepare.py --inDir ./VOC2007/JPEGImages/ --outDir /usr/src/tensorrt/data/ssd/
转换完确认.batch 文件在/usr/src/tensorrt/data/ssd/batches/中
4.caffe模型下载并准备
4.1 model
models_VGGNet_VOC0712_SSD_300x300.tar.gz 链接
https://drive.google.com/file/d/0BzKzrI_SkD1_WVVTSmQxU0dVRzA/view
解压:
把其中的VGG_VOC0712_SSD_300x300_iter_120000.caffemodel 移动到/usr/src/tensorrt/data/ssd/
4.2 ssd.prototxt
修改上面解压的里面的deploy.prototxt 文件名为ssd.prototxt 并且按照官方文档修改内容:
Edit the deploy.prototxt file and change all the Flatten layers to Reshape operations with the following parameters:
把所有的Flatten层 都改成以下内容,type名记得更改为Reshape
reshape_param {
shape {
dim: 0
dim: -1
dim: 1
dim: 1
}
}
Update the detection_out layer by adding the keep_count output, for example, add:
把以下内容加在top: "detection_out"下面
top: "keep_count"
Rename the deploy.prototxt file to ssd.prototxt and run the sample.
本文末尾处附上我修改好的ssd.prototxt!
5 编译运行
5.1 编译
cd /usr/src/tensorrt/sample/sampleSSD/
sudo make
5.2 运行
直接运行会卡死,必须关闭图形界面
ctrl+alt+ f3
登陆
sudo su
init 3#关闭图形 init 5 重启图形
cd /usr/src/tensorrt/bin/
./sample_ssd --mode INT8
加载网络很慢很慢,大概等待10分钟出结果
会输出检测bus图的里面的一年巴士汽车的结果,输出分数和边框坐标
在/usr/src/tensorrt/bin/中会有检测的结果图
附上我自己的测速结果:
jetson Nano + ssd+ int8 tensorrt+300*300*3 = 单张图像检测延时:300ms
本位末尾会附上我自己修改的sampleSSD.cpp
重新make 然后运行 repeat 是重复次数,重复多次以计算代码运算速度
还加上了对流程中各个部分的时间花费计算
./sample_ssd --mode INT8 --repeat 2000
6.附件
6.1修改好的ssd.prototxt:
name: "VGG_VOC0712_SSD_300x300_deploy"
input: "data"
input_shape {
dim: 1
dim: 3
dim: 300
dim: 300
}
layer {
name: "conv1_1"
type: "Convolution"
bottom: "data"
top: "conv1_1"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 64
pad: 1
kernel_size: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu1_1"
type: "ReLU"
bottom: "conv1_1"
top: "conv1_1"
}
layer {
name: "conv1_2"
type: "Convolution"
bottom: "conv1_1"
top: "conv1_2"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 64
pad: 1
kernel_size: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu1_2"
type: "ReLU"
bottom: "conv1_2"
top: "conv1_2"
}
layer {
name: "pool1"
type: "Pooling"
bottom: "conv1_2"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layer {
name: "conv2_1"
type: "Convolution"
bottom: "pool1"
top: "conv2_1"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 128
pad: 1
kernel_size: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu2_1"
type: "ReLU"
bottom: "conv2_1"
top: "conv2_1"
}
layer {
name: "conv2_2"
type: "Convolution"
bottom: "conv2_1"
top: "conv2_2"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 128
pad: 1
kernel_size: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu2_2"
type: "ReLU"
bottom: "conv2_2"
top: "conv2_2"
}
layer {
name: "pool2"
type: "Pooling"
bottom: "conv2_2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layer {
name: "conv3_1"
type: "Convolution"
bottom: "pool2"
top: "conv3_1"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 256
pad: 1
kernel_size: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu3_1"
type: "ReLU"
bottom: "conv3_1"
top: "conv3_1"
}
layer {
name: "conv3_2"
type: "Convolution"
bottom: "conv3_1"
top: "conv3_2"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 256
pad: 1
kernel_size: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu3_2"
type: "ReLU"
bottom: "conv3_2"
top: "conv3_2"
}
layer {
name: "conv3_3"
type: "Convolution"
bottom: "conv3_2"
top: "conv3_3"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 256
pad: 1
kernel_size: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu3_3"
type: "ReLU"
bottom: "conv3_3"
top: "conv3_3"
}
layer {
name: "pool3"
type: "Pooling"
bottom: "conv3_3"
top: "pool3"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layer {
name: "conv4_1"
type: "Convolution"
bottom: "pool3"
top: "conv4_1"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 512
pad: 1
kernel_size: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu4_1"
type: "ReLU"
bottom: "conv4_1"
top: "conv4_1"
}
layer {
name: "conv4_2"
type: "Convolution"
bottom: "conv4_1"
top: "conv4_2"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 512
pad: 1
kernel_size: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu4_2"
type: "ReLU"
bottom: "conv4_2"
top: "conv4_2"
}
layer {
name: "conv4_3"
type: "Convolution"
bottom: "conv4_2"
top: "conv4_3"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 512
pad: 1
kernel_size: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu4_3"
type: "ReLU"
bottom: "conv4_3"
top: "conv4_3"
}
layer {
name: "pool4"
type: "Pooling"
bottom: "conv4_3"
top: "pool4"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layer {
name: "conv5_1"
type: "Convolution"
bottom: "pool4"
top: "conv5_1"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 512
pad: 1
kernel_size: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
dilation: 1
}
}
layer {
name: "relu5_1"
type: "ReLU"
bottom: "conv5_1"
top: "conv5_1"
}
layer {
name: "conv5_2"
type: "Convolution"
bottom: "conv5_1"
top: "conv5_2"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 512
pad: 1
kernel_size: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
dilation: 1
}
}
layer {
name: "relu5_2"
type: "ReLU"
bottom: "conv5_2"
top: "conv5_2"
}
layer {
name: "conv5_3"
type: "Convolution"
bottom: "conv5_2"
top: "conv5_3"
param {
lr_mult: 1
decay_mult: 1