Deci-AI / super-gradients

Easily train or fine-tune SOTA computer vision models with one open source training library. The home of Yolo-NAS.
https://www.supergradients.com
Apache License 2.0
4.59k stars 510 forks source link

How to convert yolo_NAS/ckpt_best.pth to tflite model. #993

Closed vijay2712 closed 1 year ago

vijay2712 commented 1 year ago

Please share the documentation to test the model on mobile application

dagshub[bot] commented 1 year ago

Join the discussion on DagsHub!

avideci commented 1 year ago

Hi, I recently opened a PR that supports compilation to CoreML (Apple devices): https://github.com/Deci-AI/super-gradients/pull/1007 It is a simple as drag-and-drop to the XCode worksapce. XCode generates inference classes and you can try your model right away.

As of TensorFlow runtimes, they have great documentation about how to convert to TFLite: https://www.tensorflow.org/lite/models/convert/ We recommend converting to TensorFlow (preferbly Keras is possible, converts better) and then to TFLite. You can convert Tensorflow/Keras to TFLite, or ONNX to TFLite, following these docs.

I would recommend:

  1. Convert pytroch to ONNX using torch.onnx.export
  2. Convert ONNX to TensorFlow/Keras
  3. Convert Keras (h5) / TensorFlow (pb/saved model) to TFLite.
  4. Use the checkpoint from step 3 with a TFLite interpreter (runtime) on your mobile device.

If you seek performance with TFlite, I recommend checking the GPUDelegates together with MediaPipe by Google. Worth saying TFlite runs also on browsers and is universal, unlike CoreML.

vijay2712 commented 1 year ago

Thanks @avideci I will check