ColdSlim commited on
Commit
27e248a
·
verified ·
1 Parent(s): 8093719

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +63 -0
  2. requirements.txt +6 -0
  3. tflite_inference.py +74 -0
README.md CHANGED
@@ -1,3 +1,66 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ tags:
4
+ - tensorflow-lite
5
+ - edge-ai
6
+ - asl-recognition
7
+ - mediapipe
8
+ - computer-vision
9
+ - gesture-recognition
10
+ library_name: tensorflow
11
+ inference: false
12
+ datasets: []
13
+ model-index:
14
+ - name: ASL-TFLite-Edge
15
+ results: []
16
  ---
17
+
18
+ # ASL-TFLite-Edge
19
+
20
+ This repository contains a TensorFlow Lite model trained to recognize American Sign Language (ASL) fingerspelling gestures using hand landmark data. The model is optimized for real-time inference on edge devices.
21
+
22
+ ## 🧠 Model Details
23
+
24
+ - **Format:** TensorFlow Lite (.tflite)
25
+ - **Input:** 64x64 RGB image (generated from hand landmarks via Mediapipe)
26
+ - **Output:** Softmax probabilities over 59 ASL character classes (including a padding token)
27
+ - **Frameworks:** TensorFlow, Mediapipe
28
+
29
+ ## 📁 Files Included
30
+
31
+ - `asl_model.tflite` – The TFLite model file for ASL recognition
32
+ - `inference_args.json` – JSON file containing the selected columns used for inference from parquet data
33
+ - `tflite_inference.py` – Inference script to run predictions from raw `.parquet` landmark files
34
+
35
+ ## 🚀 How to Run Inference
36
+
37
+ ### Requirements
38
+ ```bash
39
+ pip install -r requirements.txt
40
+ ```
41
+
42
+ ### Run the Script
43
+ ```bash
44
+ python tflite_inference.py path/to/sample.parquet
45
+ ```
46
+
47
+ ### Output
48
+ ```bash
49
+ Predicted class index: 5
50
+ ```
51
+ >🔁 You can map this class index back to the character using your `char_to_num` mapping used during training.
52
+
53
+ ## 📌 Example Workflow
54
+ 1. Extract right-hand landmark data from Mediapipe and store it in a `.parquet` file.
55
+
56
+ 2. Ensure it contains the same selected_columns as in `inference_args.json`.
57
+
58
+ 3. Run `tflite_inference.py` to get the predicted class.
59
+
60
+ ## 🧾 License
61
+ This project is licensed under the Apache 2.0 License.
62
+
63
+ ## 👨‍💻 Author
64
+ Developed by Manik Sheokand
65
+
66
+ For sign language fingerspelling Recognition on edge devices using TensorFlow Lite
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ tensorflow>=2.9.0
2
+ mediapipe>=0.10.0
3
+ pandas
4
+ scikit-image
5
+ pyarrow
6
+ matplotlib
tflite_inference.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ import json
4
+ import tensorflow as tf
5
+ import mediapipe as mp
6
+ from skimage.transform import resize
7
+ import matplotlib.pyplot as plt
8
+ from mediapipe.framework.formats import landmark_pb2
9
+ from PIL import Image
10
+
11
+ # Load selected columns for inference
12
+ with open("inference_args.json", "r") as f:
13
+ SEL_COLS = json.load(f)["selected_columns"]
14
+
15
+ # Load TFLite model
16
+ interpreter = tf.lite.Interpreter(model_path="asl_model.tflite")
17
+ interpreter.allocate_tensors()
18
+ input_details = interpreter.get_input_details()
19
+ output_details = interpreter.get_output_details()
20
+
21
+ # Drawing utilities
22
+ mp_drawing = mp.solutions.drawing_utils
23
+ mp_drawing_styles = mp.solutions.drawing_styles
24
+ mp_hands = mp.solutions.hands
25
+
26
+ def load_relevant_data_subset(pq_path):
27
+ return pd.read_parquet(pq_path, columns=SEL_COLS)
28
+
29
+ def draw_hand_landmarks(seq_df):
30
+ images = []
31
+ for seq_idx in range(len(seq_df)):
32
+ x_hand = seq_df.iloc[seq_idx].filter(regex="x_right_hand.*").values
33
+ y_hand = seq_df.iloc[seq_idx].filter(regex="y_right_hand.*").values
34
+ z_hand = seq_df.iloc[seq_idx].filter(regex="z_right_hand.*").values
35
+
36
+ right_hand_image = np.zeros((600, 600, 3))
37
+ right_hand_landmarks = landmark_pb2.NormalizedLandmarkList()
38
+
39
+ for x, y, z in zip(x_hand, y_hand, z_hand):
40
+ right_hand_landmarks.landmark.add(x=x, y=y, z=z)
41
+
42
+ mp_drawing.draw_landmarks(
43
+ right_hand_image,
44
+ right_hand_landmarks,
45
+ mp_hands.HAND_CONNECTIONS,
46
+ landmark_drawing_spec=mp_drawing_styles.get_default_hand_landmarks_style()
47
+ )
48
+ images.append(right_hand_image)
49
+ return images
50
+
51
+ def preprocess_image(image):
52
+ img = resize(image, (64, 64), preserve_range=True).astype(np.float32) / 255.0
53
+ return np.expand_dims(img, axis=0)
54
+
55
+ def predict_from_parquet(parquet_path):
56
+ df = load_relevant_data_subset(parquet_path)
57
+ image_seq = draw_hand_landmarks(df)
58
+ if not image_seq:
59
+ raise ValueError("No hand image generated.")
60
+ img = preprocess_image(image_seq[len(image_seq) // 2])
61
+ interpreter.set_tensor(input_details[0]['index'], img)
62
+ interpreter.invoke()
63
+ output = interpreter.get_tensor(output_details[0]['index'])
64
+ prediction = np.argmax(output)
65
+ return prediction
66
+
67
+ if __name__ == "__main__":
68
+ import sys
69
+ if len(sys.argv) < 2:
70
+ print("Usage: python tflite_inference.py <parquet_file_path>")
71
+ else:
72
+ parquet_file = sys.argv[1]
73
+ pred = predict_from_parquet(parquet_file)
74
+ print("Predicted class index:", pred)