hailo-ai / hailo_model_zoo

The Hailo Model Zoo includes pre-trained models and a full building and evaluation environment
MIT License
319 stars 44 forks source link

Error occurred during the conversion process of the YOLOv8n model #94

Closed pcycccccc closed 6 months ago

pcycccccc commented 6 months ago

I have converted my trained model from the official YOLOv8 project into an ONNX model, using the command: yolo export model=G:\People\person_weights\best.pt imgsz=640 format=onnx opset=11. Then, I attempted to convert this ONNX model into a HEF file using hailo_mz with the command:hailomz compile --ckpt /root/autodl-tmp/my_data/person_v8n.onnx --calib-path /root/autodl-tmp/my_data/person_image/ --yaml /root/autodl-tmp/hailo_mz/hailo_model_zoo/hailo_model_zoo/cfg/networks/yolov8n.yaml --classes 1, but it resulted in the following error. Can someone help me identify the problem? image image To troubleshoot the issue, I tested the conversion using the official yolov8n.onnx model provided with the command: hailomz compile --ckpt /root/autodl-tmp/my_data/yolov8n.onnx --calib-path /root/autodl-tmp/my_data/coco_val2017/ --yaml /root/autodl-tmp/hailo_mz/hailo_model_zoo/hailo_model_zoo/cfg/networks/yolov8n.yaml --classes 80. In the file, I only modified the path of the ONNX model and the number of classes in yolov8n_nms_config.json, without altering anything else. The yolov8n.onnx model successfully converted, but my own model, person.onnx, did not convert successfully

Versions: HailoDF 3.27.0;HailoMZ 2.11.0

ShathirHussain commented 5 months ago

HI @pcycccccc , Can you help us providing the steps you followed to solve the issue ?

pcycccccc commented 5 months ago

@ShathirHussain

我用三通道的彩色图像验证过了,模型这么转换是可行的,并且可以在推理部署代码里表现出较好的检测效果。灰度图的转换我测试的时候,这种转换方式是行不通的(具体原因不知),需要改变一下alls内容,并且推理部署的代码也需要根据模型进行优化。

ShathirHussain commented 4 months ago

Thanks @pcycccccc When I am running the command the calibration is done on only 64 images...no matter how many more I give and it is giving me following error. hailo_model_optimization.acceleras.utils.acceleras_exceptions.NegativeSlopeExponentNonFixable: Quantization failed in layer yolov8n_lp_yuy2/conv63 due to unsupported required slope. Desired shift is 19.0, but op has only 8 data bits. This error raises when the data or weight range are not balanced. Mostly happens when using random calibration-set/weights, the calibration-set is not normalized properly or batch-normalization was not used during training.

Can you help us identifying the issue?

pcycccccc commented 4 months ago

@ShathirHussain Yes, I also encountered this problem at that time. Even after consulting with technical personnel, the issue could not be resolved. 4993c025d5ff0a3c9ac033327e3a3e9 The only solution was to generate a HEF file by converting YOLOv8 (without NMS). Correspondingly, you need to add the relevant NMS code during the CPP inference process.

ShathirHussain commented 4 months ago

Thanks @pcycccccc , Is it because of single class used while training? When I tried converting yolov8n models trained on multiple classes, the models converted succefully. I am facing this problem when I am trying to convert a model trained on a single class.

pcycccccc commented 4 months ago

@ShathirHussain I have tested the following situations:

I haven't tested other situations, but I feel it might be more related to the dataset itself. What type of dataset are you using?

ShathirHussain commented 4 months ago

@pcycccccc

How can I prepare the dataset, my model is trained on 3-channel color images, 1 class. No matter the number of Images I provide as dataset, the hailomz is taking only 64 entries for calibration.

pcycccccc commented 4 months ago

@ShathirHussain

When converting the model, I used 1024 images as the calibration dataset, preferably images from the train dataset. I am using Hailo_Dataflow version 3.27.0 and Model Zoo version 2.11.0

If you need further assistance, do not hesitate to contact me via email or WeChat. My WeChat ID is pcycccccc.

ShathirHussain commented 4 months ago

@pcycccccc

Can you share the alls file that you have used to convert yolov8n 3-channel images for 1 class from onnx to hef?

That would be helpful. Thanks.

pcycccccc commented 4 months ago

@ShathirHussain 1、准备校准数据集 2、修改yolov8n.yaml指向你的onnx路径,onnx的命名可以修改为yolov8n.onnx 3、nms.json文件内容如下: f0c258d5d3f7e0222a41c8c1becc7ce 4、alls文件按照官方提供的内容修改json文件的路径,其他不改动。 5、执行指令就是:hailomz compile --ckpt yolov8n.onnx --calib-path image_dataset --model-script yolov8n.alls --classes 1 yolov8n