[Mobilar] How To Deploy Models In Mini Way

若干阅读材料


  •  YOLO网络 + DarkNet 测试

Object detection with darknet (YOLOv3)

1
2
3
4
5
6
git clone https://github.com/pjreddie/darknet.git
cd darknet/
make
 
wget https://pjreddie.com/media/files/yolov3.weights
./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg

加载时间有点长,原因位置,至少模型比较大,200+M

Most of the time is spent loading the weights for the model. The actual detection took 200 ms.

But that still seems too long! If we are to do real time detection at 24 images / s, we should do much better than this. I'm trying to find out if that's normal, and will update the post when done. Maybe my two GeForceGTX 1080 Ti are not enough, or maybe only one of them is used...

I have tried the same exercise on the CPU, and it takes 37 s, so for sure, at least a GPU is used.

 

  • Mini-Caffe

Ref: https://github.com/luoyetx/mini-caffe

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ make
[  1%] Building CXX object CMakeFiles/caffe.dir/src/blob.cpp.o
In file included from /home/gg/TEST/mini-caffe/src/./util/io.hpp:11:0,
                 from /home/gg/TEST/mini-caffe/src/blob.cpp:7:
/home/gg/TEST/mini-caffe/src/./util/../proto/caffe.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
 #error This file was generated by a newer version of protoc which is
  ^~~~~
/home/gg/TEST/mini-caffe/src/./util/../proto/caffe.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
 #error incompatible with your Protocol Buffer headers.  Please update
  ^~~~~
/home/gg/TEST/mini-caffe/src/./util/../proto/caffe.pb.h:14:2: error: #error your headers.
 #error your headers.
  ^~~~~
In file included from /home/gg/TEST/mini-caffe/src/./util/io.hpp:11:0,
                 from /home/gg/TEST/mini-caffe/src/blob.cpp:7:
/home/gg/TEST/mini-caffe/src/./util/../proto/caffe.pb.h:25:10: fatal error: google/protobuf/generated_message_table_driven.h: No such file or directory
 #include <google/protobuf/generated_message_table_driven.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/caffe.dir/build.make:62: recipe for target 'CMakeFiles/caffe.dir/src/blob.cpp.o' failed
make[2]: *** [CMakeFiles/caffe.dir/src/blob.cpp.o] Error 1
CMakeFiles/Makefile2:135: recipe for target 'CMakeFiles/caffe.dir/all' failed
make[1]: *** [CMakeFiles/caffe.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

  

(1) 修改 protoc的版本,解决方法:https://github.com/BVLC/caffe/issues/5078

或者,只用Ubuntu18.04 的 docker image。

build$ protoc --version
libprotoc 3.5.1

 

更新版本:https://gist.github.com/samklr/0b8a0620f82005e7f556

(2) fix一些问题:

添加这一条:CMakefile.txt

1
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

添加:

1
#include <math.h>

 

执行编译。

复制代码
#! /bin/bash
wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
tar xzf protobuf-2.6.1.tar.gz
cd protobuf-2.6.1
sudo apt-get update
sudo apt-get install build-essential
sudo ./configure
sudo make
sudo make check
sudo make install 
sudo ldconfig
protoc --version
复制代码

部署的话,只需要几个M的样子。

1
2
3
4
5
6
7
8
9
10
11
12
root@58749cb10254:~/mini-caffe/build# ll
total 2824
drwxr-xr-x  3 root root    4096 May 30 09:44 ./
drwxr-xr-x 15 root root    4096 May 30 09:28 ../
-rw-r--r--  1 root root   12809 May 30 09:42 CMakeCache.txt
drwxr-xr-x  8 root root    4096 May 30 09:44 CMakeFiles/
-rw-r--r--  1 root root   67536 May 30 09:42 Makefile
-rwxr-xr-x  1 root root   42392 May 30 09:44 benchmark*
-rw-r--r--  1 root root    1491 May 30 09:42 cmake_install.cmake
-rwxr-xr-x  1 root root 2601672 May 30 09:44 libcaffe.so*
-rwxr-xr-x  1 root root  115464 May 30 09:44 run_net*
-rwxr-xr-x  1 root root   13536 May 30 09:44 run_net_c*

  

  • PyTorch 部署

Ref: [PyTorch]PyTorch的C++前端和模型部署,一些参考资料。

 

 continue...

posted @   郝壹贰叁  阅读(400)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示