Commit 8c7d7df9 authored by shreyansh's avatar shreyansh

model added

parent 3ff16728
{
"python.pythonPath": "/home/shreyansh/.conda/envs/ml725/bin/python"
}
\ No newline at end of file
......@@ -7,15 +7,47 @@ cap = cv2.VideoCapture(0)
model = tf.keras.models.load_model("models/model.h5")
print("Loaded model from disk")
sign = {
0:"a",
1:"b",
2:"c",
3:"d",
4:"e",
5:"f",
6:"g",
7:"h",
8:"i",
9:"k",
10:"l",
11:"m",
12:"n",
13:"o",
14:"p",
15:"q",
16:"r",
17:"s",
18:"t",
19:"u",
20:"v",
21:"w",
22:"x",
23:"y"
}
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
cv2.rectangle(frame,(100,100),(300,300),(0,255,0),0)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
roi = gray[100:300, 100:300]
resized = cv2.resize(roi, (28,28), interpolation = cv2.INTER_AREA)
resized = resized.reshape(-1,28,28,1).astype(float)
print(sign[np.argmax(model.predict(resized))])
# Our operations on the frame come here
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
......
import pandas as pd
import numpy as np
import tensorflow as tf
from keras.models import Sequential,model_from_json,load_model
from keras.layers import Dense, Conv2D, Flatten, MaxPooling2D, Dropout
from sklearn.preprocessing import LabelBinarizer
trainData = pd.read_csv("/content/drive/My Drive/Colab Notebooks/data/sign-language-mnist/sign_mnist_train.csv").values
testData = pd.read_csv("/content/drive/My Drive/Colab Notebooks/data/sign-language-mnist/sign_mnist_test.csv").values
trainX,trainY = trainData[:,1:],LabelBinarizer().fit_transform(trainData[:,0:1])
testX,testY = testData[:,1:],LabelBinarizer().fit_transform(testData[:,0:1])
trainX = np.divide(trainX,255)
testX = np.divide(testX,255)
# create model
model = Sequential()
model.add(Conv2D(64, kernel_size=(3,3), activation = 'relu', input_shape=(28, 28 ,1) ))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Conv2D(64, kernel_size = (3, 3), activation = 'relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Conv2D(64, kernel_size = (3, 3), activation = 'relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Flatten())
model.add(Dense(128, activation = 'relu'))
model.add(Dropout(0.35))
model.add(Dense(24, activation = 'softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
trainX = trainX.reshape(trainX.shape[0], 28, 28, 1)
testX = testX.reshape(testX.shape[0], 28, 28, 1)
model.fit(trainX, trainY, validation_data=(testX, testY), epochs=40, batch_size=128)
# Final evaluation of the model
scores = model.evaluate(testX, testY, verbose=0)
model.save("/content/drive/My Drive/Colab Notebooks/data/model.h5")
print("CNN Error: %.2f%%" % (100-scores[1]*100))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment