kdevoe commited on
Commit
55803b2
·
verified ·
1 Parent(s): af6d83a

Changing model to cnn

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -5,16 +5,16 @@ import cv2
5
  import tensorflow as tf
6
  from tensorflow.keras.models import load_model
7
 
8
- IMG_HEIGHT = 96
9
- IMG_WIDTH = 96
10
 
11
  # Load the saved Keras model
12
- model = load_model("model_01.keras")
13
 
14
  # Define the labels for ASL classes
15
  labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
16
  'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
17
- 'U', 'V', 'W', 'X', 'Y']
18
 
19
  def preprocess_frame(frame):
20
  """Preprocess the video frame for the ASL model."""
@@ -44,10 +44,15 @@ def preprocess_frame(frame):
44
 
45
  return frame
46
 
 
 
 
 
 
47
 
48
  def predict_asl(frame):
49
  """Predict the ASL sign and return the label and probabilities."""
50
- processed_frame = preprocess_frame(frame)
51
  predictions = model.predict(processed_frame) # Predict probabilities
52
  predicted_label = labels[np.argmax(predictions)] # Get the class with the highest probability
53
 
 
5
  import tensorflow as tf
6
  from tensorflow.keras.models import load_model
7
 
8
+ IMG_HEIGHT = 64
9
+ IMG_WIDTH = 64
10
 
11
  # Load the saved Keras model
12
+ model = load_model("cnn_1.keras")
13
 
14
  # Define the labels for ASL classes
15
  labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
16
  'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
17
+ 'U', 'V', 'W', 'X', 'Y', 'Z', 'del', 'nothing', 'space']
18
 
19
  def preprocess_frame(frame):
20
  """Preprocess the video frame for the ASL model."""
 
44
 
45
  return frame
46
 
47
+ def preprocess_frame_cnn(frame):
48
+ img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
49
+ img = np.expand_dims(cv2.resize(img, (64, 64)), axis = 0)
50
+ return img
51
+
52
 
53
  def predict_asl(frame):
54
  """Predict the ASL sign and return the label and probabilities."""
55
+ processed_frame = preprocess_frame_cnn(frame)
56
  predictions = model.predict(processed_frame) # Predict probabilities
57
  predicted_label = labels[np.argmax(predictions)] # Get the class with the highest probability
58