Skip to content

Commit

Permalink
Support norm model
Browse files Browse the repository at this point in the history
  • Loading branch information
triple-Mu authored and Chilicyy committed Apr 29, 2023
1 parent d1de948 commit 160822d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
11 changes: 10 additions & 1 deletion deploy/NCNN/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ python ./deploy/NCNN/export_torchscript.py \
## Run inference with NCNN-Python

```shell
python3 deploy/NCNN/infer-lite-model.py \
python3 deploy/NCNN/infer-ncnn-model.py \
data/images/image1.jpg \
work_dir/yolov6lite_s.ncnn.param \
work_dir/yolov6lite_s.ncnn.bin \
--img-size 320 320 \
--max-stride 64 \
--show
```

Expand All @@ -57,6 +58,10 @@ python3 deploy/NCNN/infer-lite-model.py \
- `--img-size` : The image height and width for model input.
- `--max-stride` : The yolov6 lite model max stride.

***Notice!***

If you want to try norm yolov6 model such as `yolov6n/s/m/l`, you should add `--max-stride 32` flags .


## Download

Expand All @@ -65,3 +70,7 @@ python3 deploy/NCNN/infer-lite-model.py \
* [YOLOv6-lite-l]()
* [YOLOv6-lite-l-320x192]()
* [YOLOv6-lite-l-224x128]()
* [YOLOv6-n]()
* [YOLOv6-s]()
* [YOLOv6-m]()
* [YOLOv6-l]()
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def sigmoid(x: ndarray) -> ndarray:
(255, 149, 200), (255, 55, 199)],
dtype=np.uint8)

CONF_THRES = 0.45
IOU_THRES = 0.65


def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
Expand All @@ -92,6 +95,7 @@ def parse_args() -> argparse.Namespace:
default=64,
help='Max stride of yolov6 model')
args = parser.parse_args()
assert args.max_stride in (32, 64)
return args


Expand Down Expand Up @@ -201,8 +205,8 @@ def main(args: argparse.Namespace):
img, ncnn.Mat.PixelType.PIXEL_BGR2RGB, img_w, img_h, w, h
)

wpad = (w + 63) // 64 * 64 - w
hpad = (h + 63) // 64 * 64 - h
wpad = (w + args.max_stride - 1) // args.max_stride * args.max_stride - w
hpad = (h + args.max_stride - 1) // args.max_stride * args.max_stride - h

mat_in_pad = ncnn.copy_make_border(
mat_in,
Expand All @@ -221,10 +225,14 @@ def main(args: argparse.Namespace):
ret1, mat_out1 = ex.extract("out0") # stride 8
ret2, mat_out2 = ex.extract("out1") # stride 16
ret3, mat_out3 = ex.extract("out2") # stride 32
ret4, mat_out4 = ex.extract("out3") # stride 64
if args.max_stride == 64:
ret4, mat_out4 = ex.extract("out3") # stride 64

outputs = [np.array(mat_out1), np.array(mat_out2), np.array(mat_out3)]
if args.max_stride == 64:
outputs.append(np.array(mat_out4))

outputs = [np.array(mat_out1), np.array(mat_out2), np.array(mat_out3), np.array(mat_out4)]
nmsd_boxes, nmsd_scores, nmsd_labels = yolov6_decode(outputs, 0.45, 0.65)
nmsd_boxes, nmsd_scores, nmsd_labels = yolov6_decode(outputs, CONF_THRES, IOU_THRES)

for box, score, label in zip(nmsd_boxes, nmsd_scores, nmsd_labels):
x0, y0, x1, y1 = box
Expand Down

0 comments on commit 160822d

Please sign in to comment.