How can i use the model after the classificaiton in python format

I have did train my model and i wanted to use it in pyhton to do the real time clasificaion how can i do that

Hi @Joker147,

Please see our Python SDK documentation: Linux Python SDK - Edge Impulse Documentation

This one is only if i want to run the model into the microcontroller but i want it to run in the python frame

I still can’t understand how to run the model on my desktop the instructions in the mentioned documents are confusing and not clear

Can anyone tell me how to use the model on my desktop for the real time classification ?

You might need to provide more details for others to understand your use case and where you are struggling.
Anyhow, I asked something similar earlier this year and was able to get a model up and running in Python, see this post.

1 Like

I was trying to capture what is your project about but it seems to be complicated to understand since I don’t have much knowledge about the code and how to run it

What model have you trained, image classification, anomaly detection? Also, can you make the project in Edge Impulse public?
To be able to receive help, you need to help us understand what you are trying to achieve.

Hi @ThomasVikstrom
My model is to classify EMG signal so i need to run the model using the sensor to classify it in the real-time now i wanted to test it on my desktop offline where i copy the raw features and paste it into the specific section of the code and run it once it confirmed then i can proceed with the real-time
my project ID : 145299

1 Like

Ok, thx for the info and for making the project public. I see you’ve combined classification with spectral analysis and anomaly detection in same project which is something I don’t have experience of.

If this would have been raw data (as I’ve myself used with Python), the steps for an unoptimized float32 version would’ve been to download the tflite file from the EI dashboard and put the name in the Python-code into the model_path variable. Then copy paste features from the sample to be classified into features (within the square brackets [ ] ).
But in your case the model is expecting 210 features as input (and not the initial 500 raw data), so I’m not sure how to populate those with your model. Perhaps the solution is to use the Python-SDK as was proposed earlier in this thread.

import numpy as np
import tensorflow as tf

# Location of tflite model file
model_path = "<your own file downloaded from dashboard.lite"

# Processed features (copy from Edge Impulse Project)
features = []

# Convert the feature list to a NumPy array of type float32
np_features = np.array(features, dtype=np.float32)

# Add dimension to input sample (TFLite model expects (# samples, data))
np_features = np.expand_dims(np_features, axis=0)

# Load TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path=model_path)

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

# Allocate tensors
interpreter.allocate_tensors()

# Print the input and output details of the model
print(input_details)
print(output_details)

# Create input tensor out of raw features
interpreter.set_tensor(input_details[0]['index'], np_features)

# Run inference
interpreter.invoke()

# output_details[0]['index'] = the index which provides the input
output_data = interpreter.get_tensor(output_details[0]['index'])

# Print the results of inference
print("Inference output is {}".format(output_data))
1 Like