This session, delivered at DevFest Nairobi 2022, focused on deploying ML models on edge devices. I used a Raspberry Pi as an example of the needs and demonstrated how TFLite could be utilized to deploy a model from TFHub onto a Raspberry Pi. I also showed how such a model could be fine-tuned on a new dataset, and how the code could be implemented to run continuously while reading a media stream from a sensor such as a camera or a microphone.
12. # Imports
from tflite_support.task import vision
from tflite_support.task import core
# Create ImageClassifier from options.
classifier =
vision.ImageClassifier.create_from_file('model.tflite')
# Run inference on Coral Edge TPU.
image = vision.TensorImage.create_from_file('image.jpg')
classification_result = classifier.classify(image)
13. Results:
Rank #0:
index : 671
score : 0.91406
class name : /m/01bwb9
display name: Passer domesticus
Rank #1:
index : 670
score : 0.00391
class name : /m/01bwbt
display name: Passer montanus
Rank #2:
index : 495
score : 0.00391
class name : /m/0bwm6m
display name: Passer italiae
17. import os
import numpy as np
import tensorflow as tf
assert tf.__version__.startswith('2')
from tflite_model_maker import model_spec
from tflite_model_maker import image_classifier
from tflite_model_maker.config import ExportFormat
from tflite_model_maker.config import QuantizationConfig
from tflite_model_maker.image_classifier import DataLoader
import matplotlib.pyplot as plt
24. # Imports
from tflite_support.task import audio
from tflite_support.task import core
from tflite_support.task import processor
#stream from mic
audio.AudioClassifier.create_from_file('yamnet.tflite')
recorder = classifier.create_audio_record()
tensor =classifier.create_tensor_audio()
recorder.start_recording()