Commit 3f4ff138 authored by shreyansh's avatar shreyansh

added 56 models

parent b34a1e61
This diff is collapsed.
This diff is collapsed.
...@@ -34,22 +34,38 @@ sign = { ...@@ -34,22 +34,38 @@ sign = {
23:"y" 23:"y"
} }
lastAns , consecutive = "",0
while(True): while(True):
# Capture frame-by-frame # Capture frame-by-frame
ret, frame = cap.read() ret, frame = cap.read()
cv2.rectangle(frame,(100,100),(300,300),(0,255,0),0) frame = cv2.flip(frame,1)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
roi = gray[100:300, 100:300] if ret:
resized = cv2.resize(roi, (28,28), interpolation = cv2.INTER_AREA) cv2.rectangle(frame,(100,100),(300,300),(0,255,0),0)
resized = resized.reshape(-1,28,28,1).astype(float) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
print(sign[np.argmax(model.predict(resized))]) roi = gray[100:300, 100:300]
# Our operations on the frame come here resized = cv2.resize(roi, (28,28), interpolation = cv2.INTER_AREA)
image = resized.reshape(-1,28,28,1).astype(float)
# Display the resulting frame
cv2.imshow('frame',gray) a = cv2.waitKey(1) # waits to see if `esc` is pressed
softmax_output = model.predict(image)
if cv2.waitKey(1) & 0xFF == ord('q'): if np.max(softmax_output) < 0.5:
break continue
res = np.argmax(softmax_output)
lastAns = res
if res == lastAns:
consecutive+=1
else:
consecutive = 0
if consecutive == 10:
consecutive = 0
cv2.putText(frame, sign[res], (100,400), cv2.FONT_HERSHEY_SIMPLEX, 4, (255,255,255), 4)
cv2.imshow("new",roi)
cv2.imshow("frame", frame)
if a == 27: # when `esc` is pressed
break
# When everything done, release the capture # When everything done, release the capture
cap.release() cap.release()
......
import pandas as pd import pandas as pd
import numpy as np import numpy as np
import tensorflow as tf import tensorflow as tf
from keras.models import Sequential,model_from_json,load_model from keras.models import Sequential,load_model
from keras.layers import Dense, Conv2D, Flatten, MaxPooling2D, Dropout from keras.layers import Dense, Conv2D, Flatten, MaxPooling2D, Dropout
from sklearn.preprocessing import LabelBinarizer from sklearn.preprocessing import LabelBinarizer
trainData = pd.read_csv("/content/drive/My Drive/Colab Notebooks/data/sign-language-mnist/sign_mnist_train.csv").values trainData = pd.read_csv("data/sign_mnist_train.csv").values
testData = pd.read_csv("/content/drive/My Drive/Colab Notebooks/data/sign-language-mnist/sign_mnist_test.csv").values testData = pd.read_csv("data/sign_mnist_test.csv").values
trainX,trainY = trainData[:,1:],LabelBinarizer().fit_transform(trainData[:,0:1]) trainX,trainY = trainData[:,1:],LabelBinarizer().fit_transform(trainData[:,0:1])
testX,testY = testData[:,1:],LabelBinarizer().fit_transform(testData[:,0:1]) testX,testY = testData[:,1:],LabelBinarizer().fit_transform(testData[:,0:1])
...@@ -30,7 +30,7 @@ model.add(Dense(128, activation = 'relu')) ...@@ -30,7 +30,7 @@ model.add(Dense(128, activation = 'relu'))
model.add(Dropout(0.35)) model.add(Dropout(0.35))
model.add(Dense(24, activation = 'softmax')) model.add(Dense(24, activation = 'softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) model.compile(loss='logcosh', optimizer='adamax', metrics=['accuracy'])
trainX = trainX.reshape(trainX.shape[0], 28, 28, 1) trainX = trainX.reshape(trainX.shape[0], 28, 28, 1)
testX = testX.reshape(testX.shape[0], 28, 28, 1) testX = testX.reshape(testX.shape[0], 28, 28, 1)
...@@ -39,6 +39,6 @@ model.fit(trainX, trainY, validation_data=(testX, testY), epochs=40, batch_size= ...@@ -39,6 +39,6 @@ model.fit(trainX, trainY, validation_data=(testX, testY), epochs=40, batch_size=
scores = model.evaluate(testX, testY, verbose=0) scores = model.evaluate(testX, testY, verbose=0)
model.save("/content/drive/My Drive/Colab Notebooks/data/model.h5") model.save("models/model.h5")
print("CNN Error: %.2f%%" % (100-scores[1]*100)) print("CNN Error: %.2f%%" % (100-scores[1]*100))
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
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