Giter VIP home page Giter VIP logo

ppogg / yolov5-lite Goto Github PK

View Code? Open in Web Editor NEW
2.1K 28.0 387.0 69.39 MB

🍅🍅🍅YOLOv5-Lite: Evolved from yolov5 and the size of model is only 900+kb (int8) and 1.7M (fp16). Reach 15 FPS on the Raspberry Pi 4B~

License: GNU General Public License v3.0

Dockerfile 0.05% Python 23.46% Shell 0.61% C++ 67.15% Java 0.39% CMake 2.01% C 2.61% Makefile 3.70% TypeScript 0.01%
ncnn yolov5 android-app mnn shufflenetv2 repvgg transformer tensorrt pplcnet openvivo

yolov5-lite's Introduction

Hi there! I'm pogg.

Hi, I’m pogg, a student who likes to record life, and here is my Garden of Eden~

  • 🔭 When I was in undergraduate, I teamed up with my classmates to attend competition. At that time I was exposed to machine learning and was fascinated by it.🤖
  • 🌱 During graduate school, I chose deep learning as my research direction. I believe that there will be many interesting people and things on this way.🤣
  • 👯 During the second year of graduate school, I have practiced in Guangzhou and recorded my own interesting experiments during the period.
  • 💡 I like to program by python and C++
  • 🤣 Hope to meet more friends. Nice to meet you~ 😁

Things I code with

Docker github actions Google git baidu arvix centos Raspberry%20Pi vim python pytorch tensorflow mxnet

Open source projects

🎁 Projects ⭐ Stars 📚 Forks 🛎 Issues 📬 Pull requests
YOLOv5-Lite Stars Forks Issues Pull Requests
YOLO-Streaming Stars Forks Issues Pull Requests
Retinaface_Ghost Stars Forks Issues Pull Requests
ncnn-yolov4-int8 Stars Forks Issues Pull Requests

I like listening to music, playing ball, and like to adventurous more. 🎼🎸🎶 → Spotify Playing 🎧👀


GIF

At the same time, I also have other blogs, welcome to pay attention!💻📌

Connect with me and Grab a Coffee! 🙋‍♀️🥤

This README file is generated every 3 hours!
Last refresh: Monday, 14:07 CEST
Create your own here!

Stars License

yolov5-lite's People

Contributors

ppogg 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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

yolov5-lite's Issues

Here is a performance table that evaluate by coco api

Update on 2021-08-26 --------------------------------------------------------------------------------------

image

# evaluate in 640×640:
Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.268
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.451
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.273

# evaluate in 416×416:
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.240
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.412
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.239

# evaluate in 320×320:
Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.205
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.362
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.202

Tensorflow Converter

Hello,

Is there any function in order to convert the Yolov5-lite models to TensorFlow?

关于使用c++部署的问题?

你好,大佬,就是我想问一下如果使用trt或tensorrt加速能够用c++的api吗,因为目前我的项目其他部分是用的c++,然后用tensorrt加速yolov5用的是c++,主要是我看您这个把pplcnet和yolov5s结合的工作在速度上有很大提升,我就是想用openvino的c++的api来推理可以吗?

ncnn raspberry pi example

Hi again! I would like to thank you for this amazing work.

I am trying to deploy this yolo into my raspberry pi. However, I am new to ncnn framework.

Could you provide me an example or further steps in order to follow?

Until now, I have deployed this repo in the Raspberry Pi and I have run detect.py, obtaining 3 second inference per image.

How do I accomplish this 100ms inference time that you report?

使用openvino推理xml文件报错

我在项目根目录下python openvino/openvino.py -m v5lite-c.xml -i openvino/bike.jpg, 我事先运行了/opt/intel/openvino_2021/bin/setupvars.sh
报错:

Traceback (most recent call last):
  File "openvino/openvino.py", line 23, in <module>
    import ngraph
  File "/opt/intel/openvino_2021/python/python3.8/ngraph/__init__.py", line 16, in <module>
    from ngraph.helpers import function_from_cnn
  File "/opt/intel/openvino_2021/python/python3.8/ngraph/helpers.py", line 7, in <module>
    from openvino.inference_engine import IENetwork
  File "/home/fraunhofer/Software/YOLOv5-Lite/openvino/openvino.py", line 25, in <module>
    from openvino.inference_engine import IENetwork, IECore
ModuleNotFoundError: No module named 'openvino.inference_engine'; 'openvino' is not a package

关于openvino量化的问题

如题,大佬提示了ncnn in8量化可以保持精度,
想问一下在openvino下使用int8量化(应该是均匀量化)是否也可以保持精度

Problem converting yolov5-lite to tflite

When launching according to ultralytics this line:

python models/tf.py --weights weights/yolov5-lite.pt --cfg models/yolov5-lite.yaml --tfl-int8 --source data/images/ --ncalib 100

I get the following error:

2021-09-22 07:53:50.613057: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2021-09-22 07:53:50.613133: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Namespace(agnostic_nms=False, batch_size=1, cfg='models/yolov5-lite.yaml', dynamic_batch_size=False, img_size=[320, 320], iou_thres=0.5, ncalib=100, score_thres=0.4, source='data/images/', tf_nms=False, tf_raw_resize=False, tfl_int8=True, topk_all=100, topk_per_class=100, weights='weights/yolov5-lite.pt')
Traceback (most recent call last):
  File "models/tf.py", line 458, in <module>
    model = attempt_load(opt.weights, map_location=torch.device('cpu'), inplace=True, fuse=False)
  File "./models/experimental.py", line 94, in attempt_load
    ckpt = torch.load(attempt_download(w), map_location=map_location)  # load
  File "/usr/local/lib/python3.7/site-packages/torch/serialization.py", line 607, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "/usr/local/lib/python3.7/site-packages/torch/serialization.py", line 882, in _load
    result = unpickler.load()
  File "/usr/local/lib/python3.7/site-packages/torch/serialization.py", line 875, in find_class
    return super().find_class(mod_name, name)
AttributeError: Can't get attribute 'conv_bn_relu_maxpool' on <module 'models.common' from './models/common.py'>

Any idea in how to solve this?

shufflenetv2预训练的模型的问题

请问您有用shufflenetv2的预训练模型训练吗?
我要用pytorch官网的'shufflenetv2_x1.0' 模型的时候出现层的shape对应不上的问题:左边是官方的,右边是你的
10 : stage2.0.branch1.2.weight torch.Size([58, 24, 1, 1]) __ model.1.branch1.1.running_var torch.Size([24])
11 : stage2.0.branch1.3.weight torch.Size([58]) __ model.1.branch1.1.num_batches_tracked torch.Size([])
12 : stage2.0.branch1.3.bias torch.Size([58]) __ model.1.branch1.2.weight torch.Size([60, 24, 1, 1]

你的模型会出现多出一层‘model.1.branch1.1.num_batches_tracked’ 而且shape是[ ]空的,网上说这是新版pytorch的问题
但是主要问题是左边stage2.0.branch1.2 ([58, 24, 1, 1]) 和右边你的branch1.2.weight torch.Size([60, 24, 1, 1] 开始出现shape不匹配,接下去陆陆续续都开始shape不一样了

是您搭建网络出错了吗?

关于c++部署的问题?

大佬你好就是我想问一下你的pplcnet+yolov5s能否使用openvino的c++ api推理,主要是我现在使用tensorrt就用的c++ api来推理yolov5s,然后我看到您测试的速度十分可观,所以我也想尝试一下,用c++会有哪些不同吗?

没有找到weights文件夹

没有找到可运行的pt文件,drive.google上不去下载不了模型,大神是不是漏了上传weights文件夹

关于ONNX调用的问题

我在链接看到了你这个项目。有些地方不太明白,想请教一下:
文章的五、What can be used for?中有两个地方:

(G2)导出onnx后无需其他修改(针对部署而言)
(G3)DNN或ort调用不再需要额外对Focus层进行拼接(之前玩yolov5在这里卡了很久,虽然能调用但精度也下降挺多)
这个是指yolov5原代码的模型导出onnx即可使用DNN和ort直接调用吗,还是经过你的修改之后才可以

weights folder no long supplied

when running on v1.3:
python detect.py --source sample/horse.jpg
returns the error FileNotFoundError: [Errno 2] No such file or directory: 'weights/yolov5ss.pt' since the weights folder has been removed from the github repository

多卡分布式训练缓慢

您好,我用您的模型训练自己的数据集,大概一万左右,batch size是64,用了两张1080ti,但是训练过程极其缓慢,比单卡快了不到20%,请问这种情况是正常的吗?gpu占用率也极其低。

在COCO上直接训练v5lite-s 416x416,未修改任何参数,map仅35.2

直接用原始参数在COCO上训练v5lite-s,输入416x416,测试的结果如下:
模型测试命令:python test.py --device 0 --conf-thres 0.1 --iou-thres 0.5

Class Images Labels P R [email protected] [email protected]:.95: 100%|█| 79/79 [00:45<00:00
all 5000 36335 0.537 0.363 0.352 0.203

使用博主提供的模型v5lite-s,输入416x416,测试的结果如下:
模型测试命令:python test.py --device 0 --conf-thres 0.1 --iou-thres 0.5

Class Images Labels P R [email protected] [email protected]:.95: 100%|█| 79/79 [00:48<00:00
all 5000 36335 0.542 0.388 0.373 0.225

mAP相差2个点,请问这是什么原因导致的呢?期待大佬的回复!谢谢。

mnn demo error

使用mnn_demo里面的测试代码以及模型,得到的结果不对,测试环境:MNN-1.1.0 Linux,想问一下checkpoint目录下提供的模型时可用的吗?

output

测试帧率问题

您好,复现shufflev2-yolov5代码与官方yolov5s代码对比,在同一实验环境下测试同一段视频为何测试速度反而是yolov5s更快一些(测试了两次)。

shufflev2-yolov5 yolov5s
96.353s 92.874s
95.978s 90.501s

复现不出RepVGG(Silu)的精度

您好,我依据您在博客说的将RepVGG替换原先的3×3卷积,但是我复现不出您提到的精度呢?您方便将您训练的这个模型的权重文件发给我一份吗?

万分感谢!

导出onnx并用opencv dnn调用满屏都是框

在Ubuntu18.04下用c++ opencv4.5
代码如下
vector classes_yolo5;
yolov5

float Sigmoid(float x) {
return static_cast(1.f / (1.f + exp(-x)));
}

void draw(int classId, float conf, int left, int top, int right, int bottom, Mat& frame) // Draw the predicted bounding box
{
//Draw a rectangle displaying the bounding box
rectangle(frame, Point(left, top), Point(right, bottom), Scalar(0, 0, 255), 3);
string label = format("%.2f", conf);
label = classes_yolo5[classId] + ":" + label;

int baseLine;
Size labelSize = getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
top = max(top, labelSize.height);
putText(frame, label, Point(left, top), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(0, 255, 0), 1);

}

void postprocess_yolo5(Mat& frame, vector& outs,int inpWidth, int inpHeight){
float anchors[3][6] = {{10.0, 13.0, 16.0, 30.0, 33.0, 23.0}, {30.0, 61.0, 62.0, 45.0, 59.0, 119.0},{116.0, 90.0, 156.0, 198.0, 373.0, 326.0}};
float stride[3] = { 8.0, 16.0, 32.0 };
float confThreshold = 0.9;
float nmsThreshold = 0.05;
float objThreshold = 0.9;

vector<int> classIds;
vector<float> confidences;
vector<Rect> boxes;
float ratioh = (float)frame.rows / inpHeight;
float ratiow = (float)frame.cols / inpWidth;
int n = 0, q = 0, i = 0, j = 0, nout = classes_yolo5.size() + 5, c = 0;
float* pdata = (float*)outs[0].data;
for (n = 0; n < 3; n++) 
{
	int num_grid_x = (int)(inpWidth / stride[n]);
	int num_grid_y = (int)(inpHeight / stride[n]);
	for (q = 0; q < 3; q++)    
	{
		const float anchor_w = anchors[n][q * 2];
		const float anchor_h = anchors[n][q * 2 + 1];
		for (i = 0; i < num_grid_x; i++){
			for (j = 0; j < num_grid_y; j++){
				float box_score = Sigmoid(pdata[4]);
				if (box_score > objThreshold){
					cv::Mat scores(1, classes_yolo5.size(), CV_32FC1, pdata + 5);
					Point classIdPoint;
					double max_class_socre;
					minMaxLoc(scores, 0, &max_class_socre, 0, &classIdPoint);
					max_class_socre = Sigmoid((float)max_class_socre);
					if (max_class_socre > objThreshold) {
						//rect [x,y,w,h]
						float x = (Sigmoid(pdata[0]) * 2.f - 0.5f + j) * stride[n];  //x
						float y = (Sigmoid(pdata[1]) * 2.f - 0.5f + i) * stride[n];   //y
						float w = powf(Sigmoid(pdata[2]) * 2.f, 2.f) * anchor_w;   //w
						float h = powf(Sigmoid(pdata[3]) * 2.f, 2.f) * anchor_h;  //h
						int left = (x - 0.5*w)*ratiow;
						int top = (y - 0.5*h)*ratioh;
						classIds.push_back(classIdPoint.x);
						confidences.push_back(max_class_socre);
						boxes.push_back(Rect(left, top, int(w*ratiow), int(h*ratioh)));
					}	
				}
                pdata += nout;	
			}
		}
	}
}

vector<int> indices;
NMSBoxes(boxes, confidences, confThreshold, nmsThreshold, indices);
for (size_t i = 0; i < indices.size(); ++i)
{
	int idx = indices[i];
	Rect box = boxes[idx];
	draw(classIds[idx], confidences[idx], box.x, box.y,
		box.x + box.width, box.y + box.height, frame);
}

}

void Quickdemo::yolov5()
{
int inpWidth = 640;//448
int inpHeight =640;
string classesFile = "/home/jzf/Documents/darknet/data/mydata.names";
string yolo5path = "/home/jzf/opencv_test/yolov5/v5lite-sim.onnx";

ifstream ifs(classesFile.c_str());
string line;
while(getline(ifs,line)) classes_yolo5.push_back(line);

Net net = readNetFromONNX(yolo5path);
    Mat srcimg;
    srcimg = imread("/home/jzf/Documents/darknet/07.jpg");//VOCdevkit/VOC2007/JPEGImages/
    //capture.read(srcimg);	
    Mat blob; 
    blobFromImage(srcimg, blob, 1 / 255.0, Size(inpWidth, inpHeight), Scalar(0, 0, 0), true, false);
    net.setInput(blob);
    vector<Mat> outs;
    net.forward(outs, net.getUnconnectedOutLayersNames());
    postprocess_yolo5(srcimg,outs,inpWidth,inpHeight);
    
    vector<double> layersTimes;
    double freq = getTickFrequency() / 1000;
    double t = net.getPerfProfile(layersTimes) / freq;
    string lable = format("Inference time for a frame : %.2f ms", t);
    putText(srcimg,lable,Point(0,15),FONT_HERSHEY_SIMPLEX,0.5,Scalar(0,0,255));

    namedWindow("yolo5", 0);
    imshow("yolo5", srcimg);
    imwrite("/home/jzf/opencv_test/yolov5.png",srcimg);

}

Got Segmentation Fault when running ncnn on Raspberry Pi

First thanks for the good job you have done. The model works great when running in pytorch.
But after I followed #53 tutorial and run on Raspberry Pi, the terminal shows Segmentation fault.
image

Do you have any idea to fix it?
Thank you so much.

训不到大佬的结果

python -m torch.distributed.launch --nproc_per_node 4 train.py --batch-size 512 --data data/coco.yaml --cfg models/yolov5ss-1.0.yaml --img-size 320 --weights '' --cache-images

Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.184
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.321
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.186
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.056
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.169
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.303
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.192
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.325
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.379
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.143
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.406
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.578

报错dataset not found

...按步骤 数据格式 类别改了之后 运行报错dataset not found 是还需要改哪里的配置嘛

Which model is the fastest?

I wonder which architecture inside the model folder corresponds to the fastest (yolo-fastest) indicated in the README repo.

I mean, what command should I run in order to train that network?

Thanks in advance!

批量预测保存

预测脚本中能批量保存预测结果和生成对应的json文件吗

What happen with my yolov5.param file ?

I try to convert your yolov5-lite.pt in folder weights to get 2 file .bin and .param
image
When i open file my yolov5.pram after using ncnn, I have seen the difference from your yolov5-lite.param file on assets folder (ncnn_Android). This is my yolov5.param:
image
What step did i go wrong ?

转tensorrt 报错

大佬 用你的生成权重文件生成了模型权重v5Lite-s-best.wts 然后放到tensorrtx /yolov5 里 去生成engine 文件。结果报错

sudo ./yolov5 -s v5Lite-s-best.wts v5Lite-s-best.engine s
Loading weights: v5Lite-s-best.wts
[10/25/2021-10:12:43] [E] [TRT] Parameter check failed at: ../builder/Network.cpp::addScale::482, condition: shift.count > 0 ? (shift.values != nullptr) : (shift.values == nullptr)
yolov5: /home/nxin/download/tensorrtx-jetson/yolov5/common.hpp:155: nvinfer1::IScaleLayer* addBatchNorm2d(nvinfer1::INetworkDefinition*, std::map<std::__cxx11::basic_string, nvinfer1::Weights>&, nvinfer1::ITensor&, std::__cxx11::string, float): Assertion `scale_1' failed.
Aborted

ncnn测试很慢的问题

大佬请问一下,我下载了最新版的ncnn,在服务器电脑Linux 18.04系统上安装和编译也都过了没啥问题,都按照教程编译也没什么特别操作。
服务器电脑配置:CPU: Intel(R) Xeon(R) Gold 6230 CPU @ 2.10GHz GPU:TITAN RTX
就在那个编译的ncnn工程下跑了你的yolov5ss.cpp1 和你提供的ncnn模型2
为什么测试的速度很慢,大概一两秒才能出一张结果,而且那张person的图片竟然有一个误检(一个人框里面多了一个小框我没这里办法上传图片)。
我跑pytorch模型速度(cpu)就相对正常。
请问您ncnn部署测试是怎么做的呢?是因为ncnn在电脑上跑本来就很慢吗也不太可能一两秒吧?我对ncnn部署一窍不通,请指教,谢谢

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.