Saltar navegación

Session 3: Model Conversion & Raspberry Pi Setup

Introdución

📌 Objective: Convert the trained model to TensorFlow Lite and prepare it for execution on Raspberry Pi.

  • Converting the model to .tflite for optimized edge device performance.
  • Transferring the model to the Raspberry Pi.
  • Installing necessary dependencies on Raspberry Pi (TensorFlow Lite, OpenCV).
  • Testing the model to ensure it loads correctly on the Raspberry Pi.

💡 By the end of this session, Raspberry Pi will be ready for real-time inference.

Hands-on

📂 Step 3: Convert Model to TensorFlow Lite

Since Raspberry Pi has limited processing power, we need to convert our trained model into TensorFlow Lite format. This lightweight version of the model will allow it to run efficiently on low-power devices. Once converted, we will transfer the model file to the Raspberry Pi for inference.


import tensorflow as tf

# Load the trained model
model = tf.keras.models.load_model("recycling_model.h5")

# Convert the model to TensorFlow Lite
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()

# Save the TensorFlow Lite model
with open("recycling_model.tflite", "wb") as f:
    f.write(tflite_model)

print("Model converted and saved as recycling_model.tflite")

Feito con eXeLearning (Nova xanela)