Classify Gesture Embedding
This function takes the gesture embedding and classifies it into one of the predefined static gestures.
Key Implementation
Function: classify_gesture in hand_landmark.py
def classify_gesture(gesture_embedding, gesture_classifier_model, gesture_labels, confidence_threshold=0.5):
"""Classify gesture from embedding"""
try:
# Run gesture classification
classification_results = gesture_classifier_model([gesture_embedding])
# Get raw probabilities for each gesture class
raw_probabilities = list(classification_results.values())[0][0] # Remove batch dimension
# Apply sigmoid activation
final_probabilities = [1.0 / (1.0 + np.exp(-score)) for score in raw_probabilities]
# Find the gesture with highest probability from sigmoid-activated scores
predicted_class = np.argmax(final_probabilities)
confidence = final_probabilities[predicted_class]
# Only return gesture if confidence is above threshold
if confidence > confidence_threshold:
return gesture_labels[predicted_class], confidence
else:
return "None", 0.0
except Exception as e:
print(f"Error in gesture classification: {e}")
return "None", 0.0