Giter Site home page Giter Site logo

yolov5_caffe's Introduction

环境配置

ubuntu:18.04

cuda:10.0

cudnn:7.6.5

caffe: 1.0

OpenCV:3.4.2

Anaconda3:5.2.0

相关的安装包我已经放到百度云盘,可以从如下链接下载: https://pan.baidu.com/s/17bjiU4H5O36psGrHlFdM7A 密码: br7h

cuda和cudnn的安装

可以参考我的另一篇部署文章(TensorRT int8 量化部署 yolov5s 4.0 模型)

Anaconda安装

chmod +x Anaconda3-5.2.0-Linux-x86_64.sh(从上面百度云盘链接下载)

./Anaconda3-5.2.0-Linux-x86_64.sh

按ENTER,然后按q调至结尾

接受协议 yes

安装路径 使用默认路径

执行安装

在使用的用户.bashrc上添加anaconda路径,比如

export PATH=/home/willer/anaconda3/bin:$PATH

caffe安装

git clone https://github.com/Wulingtian/yolov5_caffe.git

cd yolov5_caffe

命令行输入如下内容:

export CPLUS_INCLUDE_PATH=/home/你的用户名/anaconda3/include/python3.6m

make all -j8

make pycaffe -j8

vim ~/.bashrc

export PYTHONPATH=/home/你的用户名/yolov5_caffe/python:$PYTHONPATH

source ~/.bashrc

编译过程踩过的坑

libstdc++.so.6: version `GLIBCXX_3.4.21' not found

解决方案:搞定 libstdc++.so.6: version `GLIBCXX_3.4.21' not found

ImportError: No module named google.protobuf.internal

解决方案:ImportError: No module named google.protobuf.internal

wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or dir

解决方案:caffe : /wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or dir

yolov5s模型转换onnx模型

pip安装onnx和onnx-simplifier

pip install onnx

pip install onnx-simplifier

拉取yolov5官方代码

git clone https://github.com/ultralytics/yolov5.git

训练自己的模型步骤参考yolov5官方介绍,训练完成后我们得到了一个模型文件

cd yolov5

vim models/export.py 修改opset_version为10

python models/export.py --weights 训练得到的模型权重路径 --img-size 训练图片输入尺寸

python -m onnxsim onnx模型名称 yolov5s-simple.onnx 得到最终简化后的onnx模型

onnx模型转换caffe模型

git clone https://github.com/Wulingtian/yolov5_onnx2caffe.git

cd yolov5_onnx2caffe

vim convertCaffe.py

设置onnx_path(上面转换得到的onnx模型),prototxt_path(caffe的prototxt保存路径),caffemodel_path(caffe的caffemodel保存路径)

python convertCaffe.py 得到转换好的caffe模型

caffe模型推理

定位到yolov5_caffe目录下

cd tools

vim caffe_yolov5s.cpp

设置如下参数:

INPUT_W(模型输入宽度)

INPUT_H(模型输入高度)

NUM_CLASS(模型有多少个类别,例如我训练的模型是安全帽检测,只有1类,所以设置为1,不需要加背景类)

NMS_THRESH(做非极大值抑制的阈值)

CONF_THRESH(类别置信度)

prototxt_path(caffe模型的prototxt路径)

caffemodel_path(caffe模型的caffemodel路径)

pic_path(预测图片的路径)

定位到yolov5_caffe目录下

make -j8

cd build

./tools/caffe_yolov5s 输出平均推理时间,以及保存预测图片到当前目录下,至此,部署完成!

yolov5_caffe's People

Contributors

wulingtian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

yolov5_caffe's Issues

It is can not convert onnx to caffe model

hello;
i have build the environment successfully fellow the illustration. when i run python convertCaffe.py; it return as bellow :
Traceback (most recent call last):
File "convertCaffe.py", line 6, in
import caffe
File "/home/bkuser/work2/data/liudongbo/yolov5_caffe/python/caffe/init.py", line 1, in
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File "/home/bkuser/work2/data/liudongbo/yolov5_caffe/python/caffe/pycaffe.py", line 13, in
from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver,
ImportError: dynamic module does not define module export function (PyInit__caffe)

then i run python2 convertCaffe.py; it return as bellow :
Traceback (most recent call last):
File "convertCaffe.py", line 6, in
import caffe
File "/home/bkuser/work2/data/liudongbo/yolov5_caffe/python/caffe/init.py", line 1, in
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File "/home/bkuser/work2/data/liudongbo/yolov5_caffe/python/caffe/pycaffe.py", line 13, in
from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver,
ImportError: dynamic module does not define module export function (PyInit__caffe)
bkuser@bk-ai3:~/work2/data/liudongbo/yolov5_onnx2caffe$ python2 convertCaffe.py
Traceback (most recent call last):
File "convertCaffe.py", line 8, in
import onnx
ImportError: No module named onnx

then , i run pip2 install onnx ,but it failed.

could you give me an advice please ?
Yours

the performace

hello,thx for your code,i have test the yolov5s,but the res is not well,could you help me confirm if there is any loss between onnx-caffe?thx again!

The problem about C++11 when make all -j8

when I make all -j8,the problem as:
tools/caffe_yolov5s.cpp:246:5: warning: identifier 'nullptr' is a keyword in C++11 [-Wc++0x-compat]
Net caffe_net(prototxt_path, caffe::TEST, 0, nullptr);
^
tools/caffe_yolov5s.cpp: In function 'std::vector initAnchors()':
tools/caffe_yolov5s.cpp:62:13: error: 'class std::vector' has no member named 'emplace_back'
anchors.emplace_back(anchor);

ubuntu:18.04
cuda:10.0
cudnn:7.6.5
caffe: 1.0
OpenCV:3.4.2
Anaconda3:5.2.0

boost::detail::set_tss_data 碰到找不到这个,请问作者你boost的版本是多少

.build_release/lib/libcaffe.so: undefined reference to boost::detail::set_tss_data(void const*, void (*)(void (*)(void*), void*), void (*)(void*), void*, bool)' collect2: error: ld returned 1 exit status Makefile:636: recipe for target '.build_release/tools/caffe.bin' failed make: *** [.build_release/tools/caffe.bin] Error 1 make: *** Waiting for unfinished jobs.... .build_release/lib/libcaffe.so: undefined reference to boost::detail::set_tss_data(void const*, void ()(void ()(void*), void*), void ()(void), void*, bool)'
collect2: error: ld returned 1 exit status
Makefile:636: recipe for target '.build_release/tools/upgrade_net_proto_binary.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1
.build_release/lib/libcaffe.so: undefined reference to boost::detail::set_tss_data(void const*, void (*)(void (*)(void*), void*), void (*)(void*), void*, bool)' collect2: error: ld returned 1 exit status Makefile:636: recipe for target '.build_release/tools/upgrade_solver_proto_text.bin' failed make: *** [.build_release/tools/upgrade_solver_proto_text.bin] Error 1 .build_release/lib/libcaffe.so: undefined reference to boost::detail::set_tss_data(void const*, void ()(void ()(void*), void*), void ()(void), void*, bool)'
collect2: error: ld returned 1 exit status
Makefile:636: recipe for target '.build_release/tools/caffemodel2txt.bin' failed
make: *** [.build_release/tools/caffemodel2txt.bin] Error 1
.build_release/lib/libcaffe.so: undefined reference to boost::detail::set_tss_data(void const*, void (*)(void (*)(void*), void*), void (*)(void*), void*, bool)' collect2: error: ld returned 1 exit status Makefile:636: recipe for target '.build_release/tools/caffe_yolov5s.bin' failed make: *** [.build_release/tools/caffe_yolov5s.bin] Error 1 .build_release/lib/libcaffe.so: undefined reference to boost::detail::set_tss_data(void const*, void ()(void ()(void*), void*), void ()(void), void*, bool)'
collect2: error: ld returned 1 exit status
Makefile:636: recipe for target '.build_release/tools/extract_features.bin' failed
make: *** [.build_release/tools/extract_features.bin] Error 1
.build_release/lib/libcaffe.so: undefined reference to boost::detail::set_tss_data(void const*, void (*)(void (*)(void*), void*), void (*)(void*), void*, bool)' collect2: error: ld returned 1 exit status Makefile:636: recipe for target '.build_release/tools/compute_image_mean.bin' failed make: *** [.build_release/tools/compute_image_mean.bin] Error 1 .build_release/lib/libcaffe.so: undefined reference to boost::detail::set_tss_data(void const*, void ()(void ()(void*), void*), void ()(void), void*, bool)'
collect2: error: ld returned 1 exit status
Makefile:636: recipe for target '.build_release/tools/upgrade_net_proto_text.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_text.bin] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.