[Rising Sun x3] Hands-on yolov5-7.0 example segmentation
1. Preface
In fact, yolov5 released the version of instance segmentation a long time ago, and it was updated to YOLOV5-7.0 a few days ago. The speed and accuracy of instance segmentation are really amazing. The idea of instance segmentation is consistent with yolact, so I wanted to test it with python code on x3 first.
yolov5seg.png
Code: https://github.com/Rex-LK/ai_arm_learning
2. Test steps
2.1 Convert onnx to bin
The configuration file is as follows:
model_parameters:
onnx_model: 'yolov5n-seg.onnx'
output_model_file_prefix: 'yolov5n-seg'
march: 'bernoulli2'
input_parameters:
input_type_train: 'rgb'
input_layout_train: 'NCHW'
input_type_rt: 'nv12'
norm_type: 'data_scale'
scale_value: 0.003921568627451
input_layout_rt: 'NHWC'
calibration_parameters:
cal_data_dir: './calibration_data_rgb_f32'
calibration_type: 'max'
max_percentile: 0.9999
compiler_parameters:
compile_mode: 'latency'
optimize_level: 'O3'
debug: False
core_num: 2
2.2 run_x3.py
The following will give a brief overview of the code, the detailed content can refer to the yolov5 source code, onnxruntime inference code, and this article test code.
class Yolov5_7_Seg:
...
def letterbox(self):
...
def process_mask(self):
...
if __name__ == "__main__":
v5_7_seg_detector = Yolov5_7_Seg(args.modelpath,
conf_thres=args.confThreshold,
iou_thres=args.nmsThreshold)
prediction_out = v5_7_seg_detector.detect(image0)
final_mask, final_det = v5_7_seg_detector.postprocess(prediction_out)
d_r = DRAW_RESULT(args.modelpath,
conf_thres=args.confThreshold,
iou_thres=args.nmsThreshold)
colors_obj = Colors(
) # create instance for 'from utils.plots import colors'
d_r.draw_mask(final_mask,
colors_=[colors_obj(x, True) for x in final_det[:, 5]],
im_src=image0)
d_r.draw_detections(image0, final_det[:, :4], final_det[:, 4],
final_det[:, 5])
2.3 Results
masks_det.jpg
It can be seen that the effect is still very good. This result is tested by yolov5n model, and the accuracy will be higher if yolo5s, m, l and other large models are used.
3. Summary
Through the study of YOLOV5-SEG source code, I have further understood the idea of yolov5 instance segmentation and the implementation steps. In the future, I may test x3 cpp deployment code and tensort code. Due to the large number of matrix multiplications in cpp deployments, there is an opportunity to review the cpp implementation matrix implementation learned earlier and apply it to the actual code.