PINTO0309 / PINTO_model_zoo

A repository for storing models that have been inter-converted between various frameworks. Supported frameworks are TensorFlow, PyTorch, ONNX, OpenVINO, TFJS, TFTRT, TensorFlowLite (Float32/16/INT8), EdgeTPU, CoreML.
https://qiita.com/PINTO
MIT License
3.62k stars 576 forks source link

Provide YOLOX s/m/l/x in TFLite format #189

Closed leeflix closed 2 years ago

leeflix commented 2 years ago

Issue Type

Feature Request

OS

Windows

OS architecture

x86_64

Programming Language

Python

Framework

TensorFlowLite

Model name and Weights/Checkpoints URL

-

Description

There are only the nano and tiny version available for YOLOX. Could you provide the other versions (s, m, l, x) in TFLite format aswell?

Thanks for this repository! It is a great help for me.

Relevant Log Output

No response

URL or source code for simple inference testing code

No response

PINTO0309 commented 2 years ago

S, M, L, X https://github.com/PINTO0309/PINTO_model_zoo/tree/main/132_YOLOX commit: c4ec188ff52031ae5f5257a8e0b42545275f3dcb

k4is0r commented 2 years ago

Hi PINTO,

sorry to bother you about that, but it seems that the newly created models (s,m,l,x) don`t work. Not even with the demo code. Just the old models you created a few months ago (nano,tiny) seem to work.

As example:

python yolox_tflite_demo.py --model /saved_model_yolox_nano_320x320/model_float32.tflite --label ./data/coco_labels.txt --videopath ./testvideo.mp4

coco_yolox_nano_320x320

python yolox_tflite_demo.py --model /yolox_s_320x320/model_float32.tflite --label ./data/coco_labels.txt --videopath ./testvideo.mp4

coco_yolox_s_320x320

I think there has been a change within your openvino2tensorflow conversion tool that is causing this. For example my newly trained yolox nano 320x320 model with customized images is working with pytorch, with onnx and with openvino, but when I want to convert it to tensorflow lite with...

openvino2tensorflow --model_path YOLOX_outputs/yolox_nano_custom_options/FP16/best_ckpt.xml --model_output_path YOLOX_outputs/yolox_nano_custom_options/saved_model --output_saved_model --output_pb --output_no_quant_float32_tflite --string_formulas_for_normalization 'data / 255' --weight_replacement_config replace.json

I get the same problems as I have with your newly created s,m,l and x models...

I don`t know exactly whats the difference between your old models and the new ones. The only difference I found with Netron was the Maxpool change: The old nano model with MaxPool2D and Padding as SAME: nano_maxpool The new s model with MirrorPad (which is not usable with edgetpu btw :/), MaxPool2D and Padding as VALID: s_maxpool

But I don`t think that is the root for this because even when I change the padding with replacement_config to ZERO padding or manually edit the XML File from VALID to SAME, the issue that the accuracy drops to zero is still persistent...

PINTO0309 commented 2 years ago

YOLOX-S - 480x640 image image

iwatake2222 commented 2 years ago

YOLOX-L works well in my environment, too. It seems we don't need normalization for new s/m/l models. So, I suggest just input values in the range of [0, 255] without normalization. (I'm not sure it a proper input format, though...) Also, your input image looks portrait. Why don't you try with a basic image?

image

k4is0r commented 2 years ago

YOLOX-L works well in my environment, too. It seems we don't need normalization for new s/m/l models. So, I suggest just input values in the range of [0, 255] without normalization. (I'm not sure it a proper input format, though...) Also, your input image looks portrait. Why don't you try with a basic image?

Thank you very much! That was the problem! After you pointed it out I searched for the change: The yolox team changed their data_augmentation.py in August and deleted the / 255 normalization:

image

They still use float32 input but without the 255 normalization (dunno why...) Maybe the preprocess routine should get updated in "https://github.com/PINTO0309/PINTO_model_zoo/blob/main/132_YOLOX/demo/tflite/yolox_tflite_demo.py" too to address the /= 255 normalization deletion for newer yolox models?

Thanks for the pointing that out. I already searched hours over hours because of this ^^

PINTO0309 commented 2 years ago

I keep converting and committing a large number of models by myself, so I intentionally do not keep track of past models or the latest pre-processing and post-processing.

Therefore, I think the latest preprocessing that iwatake2222 pointed out makes sense.

The demo code is not always maintained up to date, so we are still waiting for a kind collaborator. If you can help me fix the demo code, it would be greatly appreciated. 😸