Run an inference with tflite-runtime inside a Raspberry Pi 4B.

python3 -m pip install tflite-runtime
Manage packages inside Thonny.
# Load the TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path="/content/food_model_250.tflite")
interpreter.allocate_tensors()

# Get input and output tensors details.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
print(input_details)
print(output_details)

interpreter.set_tensor(input_details[0]['index'], tf.cast(test_features, tf.float32))

interpreter.invoke()

# The function `get_tensor()` returns a copy of the tensor data.
# Use `tensor()` in order to get a pointer to the tensor.
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)
input_array = []            
for item in lst:
input_array.append(float(item))
test_features = np.array(input_array).astype(np.float32) test_features = np.expand_dims(test_features, axis=0)

# Load the TFLite model and allocate tensors.
interpreter = tflite_runtime.Interpreter(model_path="food_model_250.tflite") interpreter.allocate_tensors()

# Get input and output tensors details.
input_details = interpreter.get_input_details() output_details = interpreter.get_output_details() print(input_details)
print(output_details)
interpreter.set_tensor(input_details[0]['index'], test_features) interpreter.invoke()

# The function `get_tensor()` returns a copy of the tensor data. # Use `tensor()` in order to get a pointer to the tensor. output_data = interpreter.get_tensor(output_details[0]['index']) print(output_data)

--

--

--

I am a pharmacist turned android developer and machine learning engineer. Right now I’m a senior android developer at Invisalign and a ML GDE.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Random Forest Classification

NLP to Boost Up Marketing

Regression Model Selection

Facial Expression Recognition using Deep Learning

A Simple Guide to Adaboost Algorithm in Machine Learning | Ensemble Techniques

Deduplication Deduplication

Deep Learning: Autocorrect, Spell check for short words

Get a Step Ahead With Feature Engineering

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
George Soloupis

George Soloupis

I am a pharmacist turned android developer and machine learning engineer. Right now I’m a senior android developer at Invisalign and a ML GDE.

More from Medium

Automatically Find Label Issues in Image Classification Datasets

Examples of label errors in the MNIST dataset — an image depicting “3” but labeled as “5” and another image depicting the number “7” but labeled as “4”.

Additive Margin Softmax Loss

Intelligence Images Synthetization with Python

How to Train a Sparse Neural Radiance Field, on AWS EC 2

ASCII art showing a camera icon.