Fixing IndexError in Gesture Recognition with TinyML on ESP32

After resolving the previous issues in my gesture recognition project on the ESP32 with TinyML, I’m now encountering a new problem. The program crashes intermittently with the following error:
IndexError: index 3 is out of bounds for axis 0 with size 3
IndexError: index 3 is out of bounds for axis 0 with size 3
This happens when I try to run inference. Here’s the relevant section of the code:
def get_sensor_data():
accel = mpu.accel
return np.array([accel.x, accel.y, accel.z]) # Collect accelerometer data

while True:
try:
data = get_sensor_data()
gesture = predict_gesture(data) # Run inference on sensor data

if gesture == "wave":
print("Wave gesture detected!")
elif gesture == "swipe":
print("Swipe gesture detected!")
else:
print("No gesture detected")

time.sleep(0.3)

except Exception as e:
print("Error:", e)
time.sleep(1)
def get_sensor_data():
accel = mpu.accel
return np.array([accel.x, accel.y, accel.z]) # Collect accelerometer data

while True:
try:
data = get_sensor_data()
gesture = predict_gesture(data) # Run inference on sensor data

if gesture == "wave":
print("Wave gesture detected!")
elif gesture == "swipe":
print("Swipe gesture detected!")
else:
print("No gesture detected")

time.sleep(0.3)

except Exception as e:
print("Error:", e)
time.sleep(1)
It seems the error occurs when passing data to the predict_gesture function. I suspect that the shape of the data might be incorrect or the model is expecting more input features than provided. How can I fix this IndexError and ensure the sensor data has the correct shape for inference?
3 Replies
Marvee Amasi
Marvee Amasi3mo ago
@wafa_ath that predict_gesture function expects more input features. Attimes the model expects additional sensor data as gyroscope readings or multiple time series samples. So u need to verify what shape the model expects and adjust your data collection
wafa_ath
wafa_ath3mo ago
Thanks for pointing that out, I’ll check the model to see if it needs more data like the gyroscope readings or extra time steps. I’ll update my code and try again
Want results from more Discord servers?
Add your server