|
18、darknet2ncnn将darknet 模型转换为ncnn模型,实现darknet网络模型在移动端的快速部署
yolov3-tiny:Android端
转换模型(darknet ---> ncnn):
Use darknet2ncnn to convert darknet model to ncnn model
https://github.com/xiangweizeng/darknet2ncnn 这个不行了
这个才行: 重点看这个
https://blog.csdn.net/tugouxp/article/details/121143770
git clone https://gitee.com/damone/darknet2ncnn.git
cd darknet2ncnn
git submodule init
git submodule update
cd darknet
开启opencv 和 改架构CUDA的
ARCH= -gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=[sm_50,compute_50] \
-gencode arch=compute_52,code=[sm_52,compute_52] \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=[sm_61,compute_61] \
-gencode arch=compute_75,code=sm_75
make -j8
rm libdarknet.so
下面为我总结的:
data/yolov3-tiny.cfg data/yolov3-tiny.weights 这两个文件没有变化 应该是输入的
example/zoo/yolov3-tiny.param example/zoo/yolov3-tiny.bin 这两个文件已经变了 应该是输出的
example/data/dog.jpg 这个没变
命令的用法:./darknet2ncnn darknet.cfg darknet.weights ncnn.param ncnn.bin
命令的用法:./convert_verify [darknet.cfg] [darknet.weights] [ncnn.param] [ncnn.bin] [test.image]
ncnn模型需要的网络配置和权重文件的格式:[ncnn.param] [ncnn.bin]
make yolov3-tiny.net 执行之后:
./darknet2ncnn data/yolov3-tiny.cfg data/yolov3-tiny.weights example/zoo/yolov3-tiny.param example/zoo/yolov3-tiny.bin
Loading weights from data/yolov3-tiny.weights...Done!
./convert_verify data/yolov3-tiny.cfg data/yolov3-tiny.weights example/zoo/yolov3-tiny.param example/zoo/yolov3-tiny.bin example/data/dog.jpg
Loading weights from data/yolov3-tiny.weights...Done!
Start run all operation:
conv_0 : weights diff : 0.000000
conv_0_batch_norm : slope diff : 0.000000
conv_0_batch_norm : mean diff : 0.000000
conv_0_batch_norm : variance diff : 0.000000
conv_0_batch_norm : biases diff : 0.000000
Layer: 0, Blob : conv_0_activation, Total Diff 259359.718750 Avg Diff: 0.093669
Layer: 1, Blob : maxpool_1, Total Diff 85732.632812 Avg Diff: 0.123851
conv_2 : weights diff : 0.000000
conv_2_batch_norm : slope diff : 0.000000
conv_2_batch_norm : mean diff : 0.000000
conv_2_batch_norm : variance diff : 0.000000
conv_2_batch_norm : biases diff : 0.000000
Layer: 2, Blob : conv_2_activation, Total Diff 95723.023438 Avg Diff: 0.069142
Layer: 3, Blob : maxpool_3, Total Diff 33560.359375 Avg Diff: 0.096964
conv_4 : weights diff : 0.000000
conv_4_batch_norm : slope diff : 0.000000
conv_4_batch_norm : mean diff : 0.000000
conv_4_batch_norm : variance diff : 0.000000
conv_4_batch_norm : biases diff : 0.000000
Layer: 4, Blob : conv_4_activation, Total Diff 47419.449219 Avg Diff: 0.068503
Layer: 5, Blob : maxpool_5, Total Diff 17139.689453 Avg Diff: 0.099041
conv_6 : weights diff : 0.000000
conv_6_batch_norm : slope diff : 0.000000
conv_6_batch_norm : mean diff : 0.000000
conv_6_batch_norm : variance diff : 0.000000
conv_6_batch_norm : biases diff : 0.000000
Layer: 6, Blob : conv_6_activation, Total Diff 17113.324219 Avg Diff: 0.049444
Layer: 7, Blob : maxpool_7, Total Diff 6735.393066 Avg Diff: 0.077841
conv_8 : weights diff : 0.000000
conv_8_batch_norm : slope diff : 0.000000
conv_8_batch_norm : mean diff : 0.000000
conv_8_batch_norm : variance diff : 0.000000
conv_8_batch_norm : biases diff : 0.000000
Layer: 8, Blob : conv_8_activation, Total Diff 6129.817383 Avg Diff: 0.035421
Layer: 9, Blob : maxpool_9, Total Diff 2565.875244 Avg Diff: 0.059307
conv_10 : weights diff : 0.000000
conv_10_batch_norm : slope diff : 0.000000
conv_10_batch_norm : mean diff : 0.000000
conv_10_batch_norm : variance diff : 0.000000
conv_10_batch_norm : biases diff : 0.000000
Layer: 10, Blob : conv_10_activation, Total Diff 1663.026123 Avg Diff: 0.019220
Layer: 11, Blob : maxpool_11, Total Diff 2608.484619 Avg Diff: 0.030146
conv_12 : weights diff : 0.000000
conv_12_batch_norm : slope diff : 0.000000
conv_12_batch_norm : mean diff : 0.000000
conv_12_batch_norm : variance diff : 0.000000
conv_12_batch_norm : biases diff : 0.000000
Layer: 12, Blob : conv_12_activation, Total Diff 13798.509766 Avg Diff: 0.079734
conv_13 : weights diff : 0.000000
conv_13_batch_norm : slope diff : 0.000000
conv_13_batch_norm : mean diff : 0.000000
conv_13_batch_norm : variance diff : 0.000000
conv_13_batch_norm : biases diff : 0.000000
Layer: 13, Blob : conv_13_activation, Total Diff 1050.790405 Avg Diff: 0.024288
conv_14 : weights diff : 0.000000
conv_14_batch_norm : slope diff : 0.000000
conv_14_batch_norm : mean diff : 0.000000
conv_14_batch_norm : variance diff : 0.000000
conv_14_batch_norm : biases diff : 0.000000
Layer: 14, Blob : conv_14_activation, Total Diff 3824.680176 Avg Diff: 0.044202
conv_15 : weights diff : 0.000000
conv_15 : biases diff : 0.000000
Layer: 15, Blob : conv_15_activation, Total Diff 6452.077148 Avg Diff: 0.149718
Layer: 17, Blob : route_17, Total Diff 1050.790405 Avg Diff: 0.024288
conv_18 : weights diff : 0.000000
conv_18_batch_norm : slope diff : 0.000000
conv_18_batch_norm : mean diff : 0.000000
conv_18_batch_norm : variance diff : 0.000000
conv_18_batch_norm : biases diff : 0.000000
Layer: 18, Blob : conv_18_activation, Total Diff 1104.450073 Avg Diff: 0.051056
Layer: 19, Blob : upsample_19, Total Diff 4417.800293 Avg Diff: 0.051056
Layer: 20, Blob : route_20, Total Diff 10547.617188 Avg Diff: 0.040633
conv_21 : weights diff : 0.000000
conv_21_batch_norm : slope diff : 0.000000
conv_21_batch_norm : mean diff : 0.000000
conv_21_batch_norm : variance diff : 0.000000
conv_21_batch_norm : biases diff : 0.000000
Layer: 21, Blob : conv_21_activation, Total Diff 9796.311523 Avg Diff: 0.056608
conv_22 : weights diff : 0.000000
conv_22 : biases diff : 0.000000
Layer: 22, Blob : conv_22_activation, Total Diff 28997.115234 Avg Diff: 0.168216
make yolov3-tiny.coco
./yolo zoo/yolov3-tiny.param zoo/yolov3-tiny.bin data/dog.jpg data/coco.names
命令的用法:./yolo [ncnn.param] [ncnn.bin] [imagepath] [lable.txt]
./yolo-param-bin [ncnn.param.bin] [ncnn.bin] [imagepath] [lable.txt]
./classifier [ncnn.param] [ncnn.bin] [imagepath] [lable.txt]
./classifier zoo/yolov3-tiny.param zoo/yolov3-tiny.bin data/dog.jpg data/coco.names
mkdir -p build-android-armv7
cd build-android-armv7
cmake -DCMAKE_TOOLCHAIN_FILE=/home/dfy888/Android_Sdk/ndk/android-ndk-r19c/build/cmake/android.toolchain.cmake -DANDROID_ABI="armeabi-v7a" -DANDROID_ARM_NEON=ON -DANDROID_PLATFORM=android-20 ..
cmake -DCMAKE_TOOLCHAIN_FILE= -DANDROID_ABI= -DANDROID_ARM_NEON=ON -DANDROID_PLATFORM=android-14 ..
ANDROID_ABI 是移动端硬件架构名字,"armeabi-v7a" 支持绝大部分手机硬件,项目中运用RK3399是v8硬件架构,这边用手机测试所以用v7a
ANDROID_ARM_NEON 是否使用 NEON 指令集,设为 ON 支持绝大部分手机硬件
ANDROID_PLATFORM 指定最低系统版本,"android-14" 就是 android-4.0
我们推荐大部分的开发者删简 x86,x86_64,和arm32 的ABIs。您可以通过如下的Gradle配置实现,
这个配置只包括了 armeabi-v7a和arm64-v8a,该配置能涵盖住大部分的现代Android设备
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
lib/libncnn.a文件 以我理解这个文件就是相当于把ncnn打包成android可导入的形式
include文件夹 里面包含各种常用的.h文件
app闪退 报错:java.lang.UnsatisfiedLinkError: dlopen failed: library "libomp.so" not found
还是小屁孩回复 hzmsfdl1年前
闪退根据我们实验室的使用,应该是你的ndk版本问题 的确我降级后可以了 19都可以
参考:
https://gitee.com/damone/darknet2ncnn
https://github.com/Tencent/ncnn
http://github-mirror.bugkiller.org/chehongshu/ncnnforandroid_objectiondetection_Mobilenetssd
目前ncnn对Caffe的支持是最好的 模型还可以加密等
对yolov4-tiny模型转换 日志:
- jiang@jiang-Ubuntu:~/jjj_darknet_works/darknet2ncnn$ ./darknet2ncnn data/yolov4-tiny.cfg data/yolov4-tiny.weights example/zoo/yolov4-tiny-radar.param example/zoo/yolov4-tiny-radar.bin
- layer filters size input output
- 0 conv 32 3 x 3 / 2 608 x 608 x 3 -> 304 x 304 x 32 0.160 BFLOPs
- 1 conv 64 3 x 3 / 2 304 x 304 x 32 -> 152 x 152 x 64 0.852 BFLOPs
- 2 conv 64 3 x 3 / 1 152 x 152 x 64 -> 152 x 152 x 64 1.703 BFLOPs
- 3 route 2
- Unused field: 'groups = 2'
- Unused field: 'group_id = 1'
- 4 conv 32 3 x 3 / 1 152 x 152 x 64 -> 152 x 152 x 32 0.852 BFLOPs
- 5 conv 32 3 x 3 / 1 152 x 152 x 32 -> 152 x 152 x 32 0.426 BFLOPs
- 6 route 5 4
- 7 conv 64 1 x 1 / 1 152 x 152 x 64 -> 152 x 152 x 64 0.189 BFLOPs
- 8 route 2 7
- 9 max 2 x 2 / 2 152 x 152 x 128 -> 76 x 76 x 128
- 10 conv 128 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BFLOPs
- 11 route 10
- Unused field: 'groups = 2'
- Unused field: 'group_id = 1'
- 12 conv 64 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 64 0.852 BFLOPs
- 13 conv 64 3 x 3 / 1 76 x 76 x 64 -> 76 x 76 x 64 0.426 BFLOPs
- 14 route 13 12
- 15 conv 128 1 x 1 / 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BFLOPs
- 16 route 10 15
- 17 max 2 x 2 / 2 76 x 76 x 256 -> 38 x 38 x 256
- 18 conv 256 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BFLOPs
- 19 route 18
- Unused field: 'groups = 2'
- Unused field: 'group_id = 1'
- 20 conv 128 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 128 0.852 BFLOPs
- 21 conv 128 3 x 3 / 1 38 x 38 x 128 -> 38 x 38 x 128 0.426 BFLOPs
- 22 route 21 20
- 23 conv 256 1 x 1 / 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BFLOPs
- 24 route 18 23
- 25 max 2 x 2 / 2 38 x 38 x 512 -> 19 x 19 x 512
- 26 conv 512 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x 512 1.703 BFLOPs
- 27 conv 256 1 x 1 / 1 19 x 19 x 512 -> 19 x 19 x 256 0.095 BFLOPs
- 28 conv 512 3 x 3 / 1 19 x 19 x 256 -> 19 x 19 x 512 0.852 BFLOPs
- 29 conv 18 1 x 1 / 1 19 x 19 x 512 -> 19 x 19 x 18 0.007 BFLOPs
- 30 yolo
- Unused field: 'scale_x_y = 1.05'
- Unused field: 'cls_normalizer = 1.0'
- Unused field: 'iou_normalizer = 0.07'
- Unused field: 'iou_loss = ciou'
- Unused field: 'resize = 1.5'
- Unused field: 'nms_kind = greedynms'
- Unused field: 'beta_nms = 0.6'
- 31 route 27
- 32 conv 128 1 x 1 / 1 19 x 19 x 256 -> 19 x 19 x 128 0.024 BFLOPs
- 33 upsample 2x 19 x 19 x 128 -> 38 x 38 x 128
- 34 route 33 23
- 35 conv 256 3 x 3 / 1 38 x 38 x 384 -> 38 x 38 x 256 2.555 BFLOPs
- 36 conv 18 1 x 1 / 1 38 x 38 x 256 -> 38 x 38 x 18 0.013 BFLOPs
- 37 yolo
- Unused field: 'scale_x_y = 1.05'
- Unused field: 'cls_normalizer = 1.0'
- Unused field: 'iou_normalizer = 0.07'
- Unused field: 'iou_loss = ciou'
- Unused field: 'resize = 1.5'
- Unused field: 'nms_kind = greedynms'
- Unused field: 'beta_nms = 0.6'
- Loading weights from data/yolov4-tiny.weights...Done!
复制代码
|
-
01.png
(95.58 KB, 下载次数: 256)
-
02.png
(82.22 KB, 下载次数: 256)
-
03.png
(59.14 KB, 下载次数: 258)
-
04.png
(85.81 KB, 下载次数: 255)
-
05.png
(141.73 KB, 下载次数: 257)
-
06.png
(160.01 KB, 下载次数: 256)
-
07.png
(49.5 KB, 下载次数: 255)
-
08.png
(143.42 KB, 下载次数: 255)
-
09.png
(106.58 KB, 下载次数: 258)
-
10.png
(84.79 KB, 下载次数: 255)
-
11.png
(73.45 KB, 下载次数: 256)
-
12_ka.png
(61.39 KB, 下载次数: 258)
-
13.png
(76.6 KB, 下载次数: 257)
-
14.png
(131.04 KB, 下载次数: 252)
|