Skip to content

Commit d522e78

Browse files
support yolov5 6.2 (Tencent#4328)
1 parent a12c24d commit d522e78

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

examples/yolov5.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
#include <stdio.h>
2727
#include <vector>
2828

29-
#define YOLOV5_V60 1 //YOLOv5 v6.0
29+
//#define YOLOV5_V60 1 //YOLOv5 v6.0
30+
#define YOLOV5_V62 1 //YOLOv5 v6.2 export onnx model method https://github.com/shaoshengsong/yolov5_62_export_ncnn
3031

31-
#if YOLOV5_V60
32+
#if YOLOV5_V60 || YOLOV5_V62
3233
#define MAX_STRIDE 64
3334
#else
3435
#define MAX_STRIDE 32
@@ -79,7 +80,7 @@ class YoloV5Focus : public ncnn::Layer
7980
};
8081

8182
DEFINE_LAYER_CREATOR(YoloV5Focus)
82-
#endif //YOLOV5_V60
83+
#endif //YOLOV5_V60 YOLOV5_V62
8384

8485
struct Object
8586
{
@@ -278,7 +279,12 @@ static int detect_yolov5(const cv::Mat& bgr, std::vector<Object>& objects)
278279

279280
// original pretrained model from https://github.com/ultralytics/yolov5
280281
// the ncnn model https://github.com/nihui/ncnn-assets/tree/master/models
281-
#if YOLOV5_V60
282+
#if YOLOV5_V62
283+
if (yolov5.load_param("yolov5s_6.2.param"))
284+
exit(-1);
285+
if (yolov5.load_model("yolov5s_6.2.bin"))
286+
exit(-1);
287+
#elif YOLOV5_V60
282288
if (yolov5.load_param("yolov5s_6.0.param"))
283289
exit(-1);
284290
if (yolov5.load_model("yolov5s_6.0.bin"))
@@ -358,7 +364,10 @@ static int detect_yolov5(const cv::Mat& bgr, std::vector<Object>& objects)
358364
// stride 16
359365
{
360366
ncnn::Mat out;
361-
#if YOLOV5_V60
367+
368+
#if YOLOV5_V62
369+
ex.extract("353", out);
370+
#elif YOLOV5_V60
362371
ex.extract("376", out);
363372
#else
364373
ex.extract("781", out);
@@ -381,7 +390,9 @@ static int detect_yolov5(const cv::Mat& bgr, std::vector<Object>& objects)
381390
// stride 32
382391
{
383392
ncnn::Mat out;
384-
#if YOLOV5_V60
393+
#if YOLOV5_V62
394+
ex.extract("367", out);
395+
#elif YOLOV5_V60
385396
ex.extract("401", out);
386397
#else
387398
ex.extract("801", out);

0 commit comments

Comments
 (0)