wafa_ath
wafa_ath
DIIDevHeads IoT Integration Server
Created by wafa_ath on 9/27/2024 in #edge-networking
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?
4 replies