JefferyJapheth commited on
Commit
27ae852
1 Parent(s): 03fbdcd

modified make prediction and added inv_index_to_class = {v: k for k, v in index_to_class.items()}

Browse files
Files changed (1) hide show
  1. app.py +52 -3
app.py CHANGED
@@ -7,6 +7,42 @@ import numpy as np
7
  import tensorflow as tf
8
  import tensorflow.lite as tflite
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # Initialize MediaPipe solutions
11
  mp_hands = mp.solutions.hands
12
  mp_pose = mp.solutions.pose
@@ -64,11 +100,24 @@ def extract_landmarks(frame):
64
 
65
  # Make prediction
66
  def make_prediction(processed_landmarks):
67
- inputs = np.array([processed_landmarks])
 
 
68
  interpreter.set_tensor(input_details[0]['index'], inputs)
 
 
69
  interpreter.invoke()
70
- outputs = interpreter.get_tensor(output_details[0]['index'])
71
- return outputs[0].argmax()
 
 
 
 
 
 
 
 
 
72
 
73
 
74
  # Gradio Interface Function
 
7
  import tensorflow as tf
8
  import tensorflow.lite as tflite
9
 
10
+ index_to_class = {
11
+ "TV": 0, "after": 1, "airplane": 2, "all": 3, "alligator": 4, "animal": 5, "another": 6, "any": 7, "apple": 8,
12
+ "arm": 9, "aunt": 10, "awake": 11, "backyard": 12, "bad": 13, "balloon": 14, "bath": 15, "because": 16, "bed": 17,
13
+ "bedroom": 18, "bee": 19, "before": 20, "beside": 21, "better": 22, "bird": 23, "black": 24, "blow": 25, "blue": 26,
14
+ "boat": 27, "book": 28, "boy": 29, "brother": 30, "brown": 31, "bug": 32, "bye": 33, "callonphone": 34, "can": 35,
15
+ "car": 36, "carrot": 37, "cat": 38, "cereal": 39, "chair": 40, "cheek": 41, "child": 42, "chin": 43,
16
+ "chocolate": 44, "clean": 45, "close": 46, "closet": 47, "cloud": 48, "clown": 49, "cow": 50, "cowboy": 51,
17
+ "cry": 52, "cut": 53, "cute": 54, "dad": 55, "dance": 56, "dirty": 57, "dog": 58, "doll": 59, "donkey": 60,
18
+ "down": 61, "drawer": 62, "drink": 63, "drop": 64, "dry": 65, "dryer": 66, "duck": 67, "ear": 68, "elephant": 69,
19
+ "empty": 70, "every": 71, "eye": 72, "face": 73, "fall": 74, "farm": 75, "fast": 76, "feet": 77, "find": 78,
20
+ "fine": 79, "finger": 80, "finish": 81, "fireman": 82, "first": 83, "fish": 84, "flag": 85, "flower": 86,
21
+ "food": 87, "for": 88, "frenchfries": 89, "frog": 90, "garbage": 91, "gift": 92, "giraffe": 93, "girl": 94,
22
+ "give": 95, "glasswindow": 96, "go": 97, "goose": 98, "grandma": 99, "grandpa": 100, "grass": 101, "green": 102,
23
+ "gum": 103, "hair": 104, "happy": 105, "hat": 106, "hate": 107, "have": 108, "haveto": 109, "head": 110,
24
+ "hear": 111, "helicopter": 112, "hello": 113, "hen": 114, "hesheit": 115, "hide": 116, "high": 117, "home": 118,
25
+ "horse": 119, "hot": 120, "hungry": 121, "icecream": 122, "if": 123, "into": 124, "jacket": 125, "jeans": 126,
26
+ "jump": 127, "kiss": 128, "kitty": 129, "lamp": 130, "later": 131, "like": 132, "lion": 133, "lips": 134,
27
+ "listen": 135, "look": 136, "loud": 137, "mad": 138, "make": 139, "man": 140, "many": 141, "milk": 142,
28
+ "minemy": 143, "mitten": 144, "mom": 145, "moon": 146, "morning": 147, "mouse": 148, "mouth": 149, "nap": 150,
29
+ "napkin": 151, "night": 152, "no": 153, "noisy": 154, "nose": 155, "not": 156, "now": 157, "nuts": 158, "old": 159,
30
+ "on": 160, "open": 161, "orange": 162, "outside": 163, "owie": 164, "owl": 165, "pajamas": 166, "pen": 167,
31
+ "pencil": 168, "penny": 169, "person": 170, "pig": 171, "pizza": 172, "please": 173, "police": 174, "pool": 175,
32
+ "potty": 176, "pretend": 177, "pretty": 178, "puppy": 179, "puzzle": 180, "quiet": 181, "radio": 182, "rain": 183,
33
+ "read": 184, "red": 185, "refrigerator": 186, "ride": 187, "room": 188, "sad": 189, "same": 190, "say": 191,
34
+ "scissors": 192, "see": 193, "shhh": 194, "shirt": 195, "shoe": 196, "shower": 197, "sick": 198, "sleep": 199,
35
+ "sleepy": 200, "smile": 201, "snack": 202, "snow": 203, "stairs": 204, "stay": 205, "sticky": 206, "store": 207,
36
+ "story": 208, "stuck": 209, "sun": 210, "table": 211, "talk": 212, "taste": 213, "thankyou": 214, "that": 215,
37
+ "there": 216, "think": 217, "thirsty": 218, "tiger": 219, "time": 220, "tomorrow": 221, "tongue": 222, "tooth": 223,
38
+ "toothbrush": 224, "touch": 225, "toy": 226, "tree": 227, "uncle": 228, "underwear": 229, "up": 230, "vacuum": 231,
39
+ "wait": 232, "wake": 233, "water": 234, "wet": 235, "weus": 236, "where": 237, "white": 238, "who": 239, "why": 240,
40
+ "will": 241, "wolf": 242, "yellow": 243, "yes": 244, "yesterday": 245, "yourself": 246, "yucky": 247, "zebra": 248,
41
+ "zipper": 249
42
+ }
43
+
44
+ inv_index_to_class = {v: k for k, v in index_to_class.items()}
45
+
46
  # Initialize MediaPipe solutions
47
  mp_hands = mp.solutions.hands
48
  mp_pose = mp.solutions.pose
 
100
 
101
  # Make prediction
102
  def make_prediction(processed_landmarks):
103
+ inputs = np.array(processed_landmarks, dtype=np.float32)
104
+
105
+ # Set the input tensor for the TFLite model
106
  interpreter.set_tensor(input_details[0]['index'], inputs)
107
+
108
+ # Invoke the TFLite interpreter to perform inference
109
  interpreter.invoke()
110
+
111
+ # Get the output tensor of the TFLite model
112
+ output_data = interpreter.get_tensor(output_details[0]['index'])
113
+
114
+ # Find the index of the predicted class
115
+ index = np.argmax(output_data)
116
+
117
+ # Map the index to the corresponding class label using the index_to_class dictionary
118
+ prediction = inv_index_to_class[index]
119
+
120
+ return prediction
121
 
122
 
123
  # Gradio Interface Function