Open t109598032 opened 1 year ago
you can try this i wrote it same as YOLOv5, and the tflite model after exported can use same as YOLOv5
hi, thanks for your reply, i have tried it, the YOLOv7 tflite int8 works fine on PC, but on i.MX8, with cpu it works fine, while with vx delegate(gpu acceleration) the output turn out to be wrong. It is the same result when i tried YOLOv5 model previously. That is wierd. Same code and same model file, just different inference hardware, maybe it could be the problem of the machine itself i think. same problme here
hi, all, I provide a way to conver yolov7-tiny to tflite int8 (full integer quantization)model, and run successfully with correct bbox, but may still need improvement.
Using
python export.py --simplify --grid --end2end
will generate.onnx
including backbone+yolo layer+post-process. Then convert it to tflite fp32, int8 model by onnx2tf , the fp32 model works fine with correct bbox, but int8 model fails even the output value are all almost equals to 0. Watching the operator framework through Netron website, we can find that tflite fp32 and int8 model has one thing different. I dont know why int8 model is addedQuantize
op.(even using officialonnx_tf
tool will get same problem), maybe it is the reason causing value=0.So, convert the
yolov7-tiny.pt
to.onnx
file with only--simplify
(without--grid
、--end2end
), as i know that will output only backbone+yolo layer part only, without postprocess. Then convert to tflite int8, with just the python code implemented post-process like following:so far you can see the object bbox correctly on your image. to me, use the method above i successfully run my own trained model on PC and i.MX with vx_delegate acceleration, with speed 15s/image and 0.021s/image respectively by 224x224 model.(tflite model is good at arm64, but bad for x86 right?)
tensor_01.npy
~tensor_03.npy
can get from 3 add op node of post-process part through .onnx with full post-process (using Netron website, just mind the tensor shape order).This looks a way to solve tflite int8 value=0 problem, but obviously not robust, especially when you change the model input shape, using own trained model, the tensor_01~03.npy has to change(what are these value mean?), and the [[[[[144,300]]],[[[304,220]]],[[[288,584]]]]] etc. also need to change(are these number called anchor?). Anyone has a better solution?