How to convert object detection model to int8 lite which supported on OpenMV 4 Plus

I trained a object detection model with tfod api, and it worked on my PC, then I want to convert it to int8 model to let it run on my OpenMV 4 Plus, but there are some wrong, I can’t solve, Please help me!

the model link is here

@Johnson_Y Welcome to Tensorflow Forum!

Converting your TensorFlow Object Detection (TFOD) model to an int8 model allows for efficient inference on resource-constrained devices like the OpenMV 4 Plus. Here’s a step-by-step guide on how to convert your TFOD model to int8:


  1. TensorFlow 2.x installed on your PC
  2. TensorFlow Lite Converter installed on your PC
  3. Trained TFOD model in SavedModel format
  4. OpenMV 4 Plus development environment

Step 1: Prepare the TFOD Model

Ensure your TFOD model is saved in SavedModel format. This format encapsulates the model’s architecture, weights, and training configuration. You can check the saved model directory to confirm if it contains the necessary files.

Step 2: Convert the Model to TFLite

  1. Install the TensorFlow Lite Converter using pip:
    pip install tensorflow-lite

  2. Import the TensorFlow and TensorFlow Lite Converter modules:
    import tensorflow as tf
    from tensorflow.lite.converter import lite_model_converter
    model = tf.saved_model.load('path/to/saved_model')

  3. Define the converter configuration:
    converter = lite_model_converter.Converter.from_keras_model(model) converter.optimizations = [tf.lite.Optimize.DEFAULT] converter.inference_input_type = tf.int8 converter.inference_output_type = tf.int8

  4. Convert the model to TFLite format and save it:
    tflite_model = converter.convert() with open('converted_model.tflite', 'wb') as f: f.write(tflite_model)

This will generate a ‘converted_model.tflite’ file containing the quantized int8 model.

Step 3: Deploy the Model to OpenMV 4 Plus

  1. Transfer the ‘converted_model.tflite’ file to your OpenMV 4 Plus device.
  2. Use the OpenMV IDE or appropriate development environment to load and execute the TFLite model on your OpenMV 4 Plus.
  3. Provide input images to the model and process the output predictions.

Remember that the int8 model is optimized for speed and efficiency, but it may come with a slight trade-off in accuracy compared to the original FP32 model. Evaluate the performance of the int8 model on your OpenMV 4 Plus to ensure it meets your accuracy requirements.

Hope this helps!