0

I am building a project to classify different types of vibrations using edge impulse studio. I collected data from my sensor and trained the model and downloaded its .tflite file from the dashboard:

tflite file from edge impulse

To load the model into my python program I have used the following code:

# Load TFLite model interpreter = tf.lite.Interpreter(model_path = "/content/ei-testing-nn-classifier-tensorflow-lite-float32-model.lite") 

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

# Allocate tensors 
interpreter.allocate_tensors()

After this I have to provide an array of features to my model that it will be classifying. For this I have used:

features = [
    # paste processed features from edge impulse studio here
]

# convert features to numpy array of expected data type
np_features = np.array(features)
input_type = input_details[0]['dtype']
np_features = np_features.astype(input_type)

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

# input_data = np.array(np_features, dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], np_features)

interpreter.invoke()

# Classifying
output_data = interpreter.get_tensor(output_details[0]['index'])
output_data

In the features list on line 1, I can not pass the raw features that my sensor has collected as the inference expects processed features on which the model was trained.

So for this I have acquired raw data from my sensor, sent it to edge impulse studio and from there I copied the processed features generated from it:

processed features from edge impulse

And pasted them in my features array:

features = [0.1992, 0.0000, 0.0000, 0.1992, 0.0586, 0.0000, 0.0586, 0.3477, 0.3477, 0.3086, 0.3086, 0.3516, 0.3516, 0.2031, 0.2031, 0.3516, 0.2773, 0.1758, 0.2969, 0.2813, 0.2070, 0.1992, 0.2852, 0.4375, 0.4180, 0.4102, 0.5703, 0.5742, 0.4375, 0.4805, 0.4922, 0.4570, 0.4609, 0.4023, 0.4063, 0.4336, 0.3906, 0.4102, 0.3906, 0.4609, 0.1875, ... ]

But this is inefficient, and I want a method to convert the raw features from my sensor into processed features (on which my model is trained), within my python program.

James Z
  • 12,209
  • 10
  • 24
  • 44
Valeed
  • 1
  • 1

1 Answers1

0

You can find the Python code for the data processing here: https://github.com/edgeimpulse/processing-blocks - pass your raw data through the respective block and then call TFLite.

Alternatively (and preferably) on Linux and macOS use Edge Impulse for Linux' Python SDK. That actually does both the pre-processing, inference and post-processing in one go.

Jan Jongboom
  • 26,598
  • 9
  • 83
  • 120