Skip to content

Commit 79dc74b

Browse files
author
Your Name
committed
add yolox keypoints head!!
1 parent 6514ba7 commit 79dc74b

File tree

8 files changed

+1308
-13
lines changed

8 files changed

+1308
-13
lines changed
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
_BASE_: "../Base-YOLOv7.yaml"
2+
MODEL:
3+
PIXEL_MEAN: [0.485, 0.456, 0.406] # same value as PP-YOLOv2, RGB order
4+
PIXEL_STD: [0.229, 0.224, 0.225]
5+
6+
WEIGHTS: ""
7+
MASK_ON: False
8+
META_ARCHITECTURE: "YOLOX"
9+
BACKBONE:
10+
NAME: "build_cspdarknetx_backbone"
11+
12+
DARKNET:
13+
WEIGHTS: ""
14+
DEPTH_WISE: False
15+
OUT_FEATURES: ["dark3", "dark4", "dark5"]
16+
17+
YOLO:
18+
CLASSES: 80
19+
IN_FEATURES: ["dark3", "dark4", "dark5"]
20+
CONF_THRESHOLD: 0.001
21+
NMS_THRESHOLD: 0.65
22+
IGNORE_THRESHOLD: 0.7
23+
WIDTH_MUL: 0.50
24+
DEPTH_MUL: 0.33
25+
LOSS_TYPE: "v7"
26+
LOSS:
27+
LAMBDA_IOU: 1.5
28+
29+
DATASETS:
30+
TRAIN: ("coco_2017_train",)
31+
# TEST: ("coco_2014_val_mini",)
32+
TEST: ("coco_2017_val",)
33+
34+
INPUT:
35+
# FORMAT: "RGB" # using BGR default
36+
MIN_SIZE_TRAIN: (416, 512, 608, 768)
37+
MAX_SIZE_TRAIN: 800 # force max size train to 800?
38+
MIN_SIZE_TEST: 640
39+
MAX_SIZE_TEST: 800
40+
# open all augmentations
41+
JITTER_CROP:
42+
ENABLED: False
43+
RESIZE:
44+
ENABLED: False
45+
# SHAPE: (540, 960)
46+
DISTORTION:
47+
ENABLED: True
48+
COLOR_JITTER:
49+
BRIGHTNESS: True
50+
SATURATION: True
51+
# MOSAIC:
52+
# ENABLED: True
53+
# NUM_IMAGES: 4
54+
# DEBUG_VIS: True
55+
# # MOSAIC_WIDTH: 960
56+
# # MOSAIC_HEIGHT: 540
57+
MOSAIC_AND_MIXUP:
58+
ENABLED: True
59+
# ENABLED: False
60+
DEBUG_VIS: False
61+
ENABLE_MIXUP: False
62+
DISABLE_AT_ITER: 120000
63+
64+
65+
SOLVER:
66+
# enable fp16 training
67+
AMP:
68+
ENABLED: true
69+
IMS_PER_BATCH: 112
70+
BASE_LR: 0.027
71+
STEPS: (60000, 80000)
72+
WARMUP_FACTOR: 0.00033333
73+
WARMUP_ITERS: 1200
74+
MAX_ITER: 230000
75+
LR_SCHEDULER_NAME: "WarmupCosineLR"
76+
77+
TEST:
78+
EVAL_PERIOD: 10000
79+
# EVAL_PERIOD: 0
80+
OUTPUT_DIR: "output/coco_yolox_s_kpts"
81+
VIS_PERIOD: 5000
82+
83+
DATALOADER:
84+
# proposals are part of the dataset_dicts, and take a lot of RAM
85+
NUM_WORKERS: 3

deploy/demo_quantized_int8.py

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
from torch import Tensor
2+
from wanwu.core.backends.trt import TensorRTInferencer
3+
import os
4+
import cv2
5+
import argparse
6+
import numpy as np
7+
import onnxruntime
8+
from alfred.vis.image.det import visualize_det_cv2_part
9+
from alfred.vis.image.mask import vis_bitmasks_with_classes
10+
from alfred.utils.file_io import ImageSourceIter
11+
12+
13+
def vis_res_fast(img, boxes, masks, scores, labels):
14+
if masks is not None:
15+
# masks shape, might not same as img, resize contours if so
16+
img = vis_bitmasks_with_classes(
17+
img,
18+
labels,
19+
masks,
20+
force_colors=None,
21+
draw_contours=True,
22+
mask_border_color=[255, 255, 255],
23+
)
24+
thickness = 1 if masks is None else 2
25+
font_scale = 0.3 if masks is None else 0.4
26+
if boxes:
27+
img = visualize_det_cv2_part(
28+
img,
29+
scores,
30+
labels,
31+
boxes,
32+
line_thickness=thickness,
33+
font_scale=font_scale,
34+
)
35+
return img
36+
37+
38+
def load_test_image(f, h, w):
39+
a = cv2.imread(f)
40+
a = cv2.resize(a, (w, h))
41+
a_t = np.expand_dims(np.array(a).astype(np.float32), axis=0)
42+
return a_t, a
43+
44+
45+
def preprocess_image(img, h, w):
46+
a = cv2.resize(img, (w, h))
47+
a_t = np.expand_dims(np.array(a).astype(np.float32), axis=0)
48+
return a_t, img
49+
50+
51+
def make_parser():
52+
parser = argparse.ArgumentParser("onnxruntime inference sample")
53+
parser.add_argument(
54+
"-m",
55+
"--model",
56+
type=str,
57+
default="yolox.onnx",
58+
help="Input your onnx model.",
59+
)
60+
parser.add_argument(
61+
"-i",
62+
"--image_path",
63+
type=str,
64+
default="test_image.png",
65+
help="Path to your input image.",
66+
)
67+
parser.add_argument(
68+
"-o",
69+
"--output_dir",
70+
type=str,
71+
default="demo_output",
72+
help="Path to your output directory.",
73+
)
74+
parser.add_argument(
75+
"-s",
76+
"--score_thr",
77+
type=float,
78+
default=0.3,
79+
help="Score threshould to filter the result.",
80+
)
81+
parser.add_argument(
82+
"-t",
83+
"--type",
84+
default='sparseinst',
85+
help="model type.",
86+
)
87+
return parser
88+
89+
90+
if __name__ == "__main__":
91+
args = make_parser().parse_args()
92+
93+
engine_f = args.model
94+
trt_model = TensorRTInferencer(engine_f)
95+
input_shape = trt_model.ori_input_shape
96+
print('input shape: ', input_shape)
97+
98+
iter = ImageSourceIter(args.image_path)
99+
while True:
100+
im = next(iter)
101+
if isinstance(im, str):
102+
im = cv2.imread(im)
103+
104+
inp, ori_img = preprocess_image(im, h=input_shape[0], w=input_shape[1])
105+
output = trt_model.infer(inp)
106+
107+
print(output)
108+
109+
if "sparse" in args.type:
110+
masks, scores, labels = None, None, None
111+
for o in output:
112+
if o.dtype == np.float32:
113+
scores = o
114+
if o.dtype == np.int32 or o.dtype == np.int64:
115+
labels = o
116+
if o.dtype == bool:
117+
masks = o
118+
masks = masks[0]
119+
print(masks.shape)
120+
if len(masks.shape) > 3:
121+
masks = np.squeeze(masks, axis=1)
122+
scores = scores[0]
123+
labels = labels[0]
124+
# keep = scores > 0.15
125+
keep = scores > 0.06
126+
scores = scores[keep]
127+
labels = labels[keep]
128+
masks = masks[keep]
129+
print(scores)
130+
print(labels)
131+
print(masks.shape)
132+
img = vis_res_fast(im, None, masks, scores, labels)
133+
else:
134+
predictions = demo_postprocess(output[0], input_shape, p6=args.with_p6)[0]
135+
boxes = predictions[:, :4]
136+
scores = predictions[:, 4:5] * predictions[:, 5:]
137+
138+
boxes_xyxy = np.ones_like(boxes)
139+
boxes_xyxy[:, 0] = boxes[:, 0] - boxes[:, 2] / 2.0
140+
boxes_xyxy[:, 1] = boxes[:, 1] - boxes[:, 3] / 2.0
141+
boxes_xyxy[:, 2] = boxes[:, 0] + boxes[:, 2] / 2.0
142+
boxes_xyxy[:, 3] = boxes[:, 1] + boxes[:, 3] / 2.0
143+
# boxes_xyxy /= ratio
144+
dets = multiclass_nms(boxes_xyxy, scores, nms_thr=0.65, score_thr=0.1)
145+
final_boxes, final_scores, final_cls_inds = (
146+
dets[:, :4],
147+
dets[:, 4],
148+
dets[:, 5],
149+
)
150+
img = visualize_det_cv2_part(
151+
ori_img, final_scores, final_cls_inds, final_boxes
152+
)
153+
cv2.imshow("aa", img)
154+
cv2.waitKey(0)
155+
156+
cv2.imshow("YOLOv7 SparseInst CPU int8", img)
157+
if iter.video_mode:
158+
if cv2.waitKey(1) & 0xFF == ord("q"):
159+
break
160+
else:
161+
cv2.waitKey(0)

deploy/quant_atom/qt_ppq_sinst.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
Examples on how to quantize with PPQ
44
5+
I dont suggest you using PPQ, it has a lot of bugs.
6+
57
"""
68
from typing import Iterable
79

@@ -80,14 +82,16 @@ def collate_fn(batch):
8082
INPUT_SHAPE = [640, 640, 3]
8183
DEVICE = "cuda"
8284
PLATFORM = (
83-
TargetPlatform.ORT_OOS_INT8
85+
# TargetPlatform.ORT_OOS_INT8
86+
TargetPlatform.TRT_INT8
8487
)
8588
EXECUTING_DEVICE = "cpu" # 'cuda' or 'cpu'.
8689

8790
# create a setting for quantizing your network with PPL CUDA.
8891
# quant_setting = QuantizationSettingFactory.pplcuda_setting()
8992
quant_setting = QuantizationSettingFactory.default_setting()
90-
quant_setting.equalization = True # use layerwise equalization algorithm.
93+
# quant_setting.equalization = True # use layerwise equalization algorithm.
94+
quant_setting.equalization = False # tensorrt false
9195
quant_setting.dispatcher = (
9296
"conservative" # dispatch this network in conservertive way.
9397
)

images/dog.jpg

160 KB
Loading

readme.md

+13-11
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ Here are some tasks need to be claimed:
9494
- [ ] MobileVIT: https://github.com/apple/ml-cvnets/blob/main/cvnets/models/classification/mobilevit.py
9595

9696

97+
## 🆕 News!
98+
99+
- ***2022.05.09***: Big new function added! **We adopt YOLOX with Keypoints Head!**, model still under train, but you can check at code already;
100+
- ***2022.04.23***: We finished the int8 quantization on SparseInst! It works perfect! Download the onnx try it our by your self.
101+
- ***2022.04.15***: Now, we support the `SparseInst` onnx expport!
102+
- ***2022.03.25***: New instance seg supported! 40 FPS @ 37 mAP!! Which is fast;
103+
- ***2021.09.16***: First transformer based DETR model added, will explore more DETR series models;
104+
- ***2021.08.02***: **YOLOX** arch added, you can train YOLOX as well in this repo;
105+
- ***2021.07.25***: We found **YOLOv7-Res2net50** beat res50 and darknet53 at same speed level! 5% AP boost on custom dataset;
106+
- ***2021.07.04***: Added YOLOF and we can have a anchor free support as well, YOLOF achieves a better trade off on speed and accuracy;
107+
- ***2021.06.25***: this project first started.
108+
- more
109+
97110

98111
## 💁‍♂️ Results
99112

@@ -104,17 +117,6 @@ Here are some tasks need to be claimed:
104117
![](https://s1.ax1x.com/2022/03/25/qN5zp6.png) | ![](https://s2.loli.net/2022/03/25/MBwq9YT7zC5Sd1A.png)
105118

106119

107-
## 🆕 News!
108-
109-
- **2022.04.23**: We finished the int8 quantization on SparseInst! It works perfect! Download the onnx try it our by your self.
110-
- **2022.04.15**: Now, we support the `SparseInst` onnx expport!
111-
- **2022.03.25**: New instance seg supported! 40 FPS @ 37 mAP!! Which is fast;
112-
- **2021.09.16**: First transformer based DETR model added, will explore more DETR series models;
113-
- **2021.08.02**: **YOLOX** arch added, you can train YOLOX as well in this repo;
114-
- **2021.07.25**: We found **YOLOv7-Res2net50** beat res50 and darknet53 at same speed level! 5% AP boost on custom dataset;
115-
- **2021.07.04**: Added YOLOF and we can have a anchor free support as well, YOLOF achieves a better trade off on speed and accuracy;
116-
- **2021.06.25**: this project first started.
117-
- more
118120

119121

120122
## 🧑‍🦯 Installation && Quick Start

0 commit comments

Comments
 (0)