一个迷你的pytorch推理框架,它的灵感来自darknet

网友投稿 1427 2022-10-30

一个迷你的pytorch推理框架,它的灵感来自darknet

一个迷你的pytorch推理框架,它的灵感来自darknet

Msnhnet

English | 中文

A mini pytorch inference framework which inspired from darknet.

OS supported (you can check other OS by yourself)

windowslinuxmac
checkedx
gpuxxx

Yolo Test (Win10 MSVC 2017 I7-10700F)

nettime
yolov3465ms
yolov3_tiny75ms
yolov4600ms

Tested networks

lenet5lenet5_bnalexnetvgg16vgg16_bnresnet18resnet34resnet50resnet101resnet152darknet53googLenetyolov3yolov3_sppyolov3_tinyyolov4pretrained models 链接:https://pan.baidu.com/s/1WElMhBhaN5EnPJnD8S1P3w 提取码:1hlm

Requirements

OpenCV4 https://github.com/opencv/opencvyaml-cpp https://github.com/jbeder/yaml-cppQt5 (optional. for Msnhnet viewer) http://download.qt.io/archive/qt/

How to build

Compile opencv4 and yaml-cpp.Config environment. Add "OpenCV_DIR" and "yaml-cpp_DIR"Get qt5 and install. http://download.qt.io/ (optional)Add qt5 bin path to environment.Then use cmake-gui tool and visual studio to make or use vcpkg.

Linux(Ubuntu)

sudo apt-get install qt5-default #optionalsudo apt-get install libqt5svg5-dev #optionalsudo apt-get install libopencv-dev# build yaml-cppgit clone https://github.com/jbeder/yaml-cpp.gitcd yaml-cppmdir build cd build cmake ..make -j4sudo make install #config sudo echo /usr/local/lib > /etc/ld.so.conf/usrlib.confsudo ldconfig# build Msnhnetgit clone https://github.com/msnh2012/Msnhnet.gitcd Msnhnet/buildcmake -DCMAKE_BUILD_TYPE=Release .. make -j4sudo make installvim ~/.bashrc # Last line add: export PATH=/usr/local/bin:$PATH

Test Msnhnet

Download pretrained model and extract. eg.D:/models. Open terminal and cd "Msnhnet install bin". eg. D:/Msnhnet/bin Test yolov3 "yolov3 D:/models". Test yolov3tiny_video "yolov3tiny_video D:/models". Test classify "classify D:/models".

View Msnhnet

Open terminal and cd "Msnhnet install bin" eg. D:/Msnhnet/bin run "MsnhnetViewer"

How to convert your own pytorch network

Use pytorch to load network

import torchvision.models as modelsimport torchfrom torchsummary import summary md = models.resnet18(pretrained = True)md.to("cpu")md.eval()print(md, file = open("net.txt", "a"))summary(md, (3, 224, 224),device='cpu')

Write msnhnet file according to net.txt and summary result.(Manually :o. Like darnet cfg)Export msnhbin

val = []dd = 0for name in md.state_dict(): if "num_batches_tracked" not in name: c = md.state_dict()[name].data.flatten().numpy().tolist() dd = dd + len(c) print(name, ":", len(c)) val.extend(c)with open("alexnet.msnhbin","wb") as f: for i in val : f.write(pack('f',i))

Ps. More detail in file "pytorch2msnhbin/pytorch2msnhbin.py"

Enjoy it! :D

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:关于springboot加载yml配置文件的no字段自动转义问题
下一篇:Spring Cloud Feign实现动态URL
相关文章

 发表评论

暂时没有评论,来抢沙发吧~