Devmurari commited on
Commit
360e44b
·
1 Parent(s): 4de7381

fix: working model for gesture complete project

Browse files
Files changed (1) hide show
  1. app.py +7 -40
app.py CHANGED
@@ -9,59 +9,26 @@ import sys
9
  from tensorflow import keras
10
  from tensorflow.keras import layers
11
 
12
- EPOCHS = 10
13
- IMG_WIDTH = 30
14
- IMG_HEIGHT = 30
15
- NUM_CATEGORIES = 43
16
- TEST_SIZE = 0.4
17
 
18
  def get_model():
19
- """
20
- Returns a compiled convolutional neural network model. Assume that the
21
- `input_shape` of the first layer is `(IMG_WIDTH, IMG_HEIGHT, 3)`.
22
- The output layer should have `NUM_CATEGORIES` units, one for each category.
23
- """
24
- # Experimenting with different architectures of a Sequential model and this is so far best for me
25
- # Accepts input with shape of (30, 30, 3)
26
- # Convolutional layer with 65 filters and relu activation function
27
- # Maxpooled by (2, 2) kernel
28
- # Second convolutional layer with higher number of filter i.e 256 and relu activation function
29
- # Flattering nd shape and Dense layer with 450 nuerons and relu activation funtion
30
- # Output layer with 43 nuerons and softmax activation function
31
-
32
- model = tf.keras.Sequential([
33
- layers.Conv2D(64, 5, input_shape = (30, 30, 3), name = "conv1", activation="relu"),
34
- layers.MaxPool2D((2, 2), name = "pool1"),
35
- layers.Conv2D(256, 3, name = "conv2", activation="relu"),
36
- layers.MaxPool2D((2, 2), name = "pool2"),
37
- layers.Flatten(),
38
- layers.Dense(450, activation = "relu", name = "dense1"),
39
- layers.Dense(NUM_CATEGORIES-1, activation = "softmax", name = "output")
40
- ])
41
-
42
- # Printing model summary and compiling with adam algorithm, categorical_crossentropy as 43 output neurons
43
  model.summary()
44
-
45
- model.compile(
46
- optimizer = "adam",
47
- loss = "categorical_crossentropy",
48
- metrics=["accuracy"]
49
- )
50
-
51
  return model
52
 
53
- # model = load_model("best_traffic_model.h5")
54
- # model.compile(optimizer="adam", loss="categorical_crossentropy")
55
 
56
  model = get_model()
57
 
58
  labels = ["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thrteen","fourteen","fifteen","sixteen","seventeen","eightteen","nineteen"]
59
 
60
  def predict(img):
61
- img = cv2.resize(img, (IMG_WIDTH, IMG_HEIGHT), interpolation=cv2.INTER_AREA)
62
  img = img.astype("float32")
63
- img = img.reshape(1, IMG_HEIGHT, IMG_WIDTH, 3)
 
 
64
  out = model.predict(img)
 
65
  cls = out.argmax()
66
  return cls
67
 
 
9
  from tensorflow import keras
10
  from tensorflow.keras import layers
11
 
 
 
 
 
 
12
 
13
  def get_model():
14
+ model = load_model("model_1.h5")
15
+ model.compile(optimizer="adam", loss="categorical_crossentropy")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  model.summary()
 
 
 
 
 
 
 
17
  return model
18
 
 
 
19
 
20
  model = get_model()
21
 
22
  labels = ["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thrteen","fourteen","fifteen","sixteen","seventeen","eightteen","nineteen"]
23
 
24
  def predict(img):
25
+ img = cv2.resize(img, (64, 64), interpolation=cv2.INTER_AREA)
26
  img = img.astype("float32")
27
+ img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
28
+ img = img.reshape(1, 64, 64, 1)
29
+ print(img.shape)
30
  out = model.predict(img)
31
+ print(out.shape)
32
  cls = out.argmax()
33
  return cls
34