Search code examples
pythongoogle-colaboratorytensorflow-litetraining-datayolov5

How to convert yolov5 trained model into tflite in google colab to install on mobile app?


I have used Yolov5 to train the model in google colab and how can I export the .tflite file of the trained model so that it can be used for mobile applications. Thanks for help me


Solution

  • Assuming that you have the latest TensorFlow version 2.7.0 use the general method for that purpose that it is shown here:

    import tensorflow as tf
    
    # Convert the model
    converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir) # path to the SavedModel directory
    tflite_model = converter.convert()
    
    # Save the model.
    with open('model.tflite', 'wb') as f:
      f.write(tflite_model)
    

    Get back with your results and tag me if you have problems