My project is a sign language project user interface using Tkinter to predict the gesture on Realtime.
Here is my code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
train = pd.read_csv('train.csv')
test = pd.read_csv('test.csv')
train.head()
labels= train['label'].values
plt.figure(figsize =(18,8))
sns.countplot(x=labels)
train.drop('label',axis=1,inplace=True)
images = train.values
images= np.array([np.reshape(i, (28, 28))for i in images])
images= np.array([i.flatten() for i in images])
from sklearn.preprocessing import LabelBinarizer
label_binrizer = LabelBinarizer()
labels = label_binrizer.fit_transform(labels)
labels
index = 2
print(labels[index])
plt.imshow(images[index].reshape(28,28))
import cv2
import numpy as np
for i in range(0,10):
rand = np.random.randint(0, len(images))
input_im = images[rand]
sample = input_im.reshape(28,28).astype(np.uint8)
sample = cv2.resize(sample, None, fx=10, fy=10, interpolation = cv2.INTER_CUBIC)
cv2.imshow("sample image", sample)
cv2.waitKey(0)
cv2.destroyAllWindows()
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(images, labels, test_size = 0.3, random_state = 101)
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Conv2D, MaxPooling2D, Flatten, Dropout
batch_size= 128
num_classes= 24
epochs= 10
from tensorflow.keras.layers import Conv2D, MaxPooling2D
from tensorflow.keras import backend as K
from tensorflow.keras.optimizers import Adam
from keras.models import Sequential
from keras.layers import Dense, Activation, Flatten, Dropout
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.20))
model.add(Dense(num_classes, activation= 'softmax'))
x_train = x_train / 255
x_test = x_test / 255
x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)
x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)
plt.imshow(x_train[0].reshape(28,28))
model.compile(loss = 'categorical_crossentropy',
optimizer = Adam(),
metrics=['accuracy'])
print(model.summary())
history = model.fit(x_train, y_train, validation_data= (x_test, y_test), epochs=epochs, batch_size=batch_size)
plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.title("Accuracy")
plt.xlabel('epoch')
plt.ylabel('accuracy')
plt.legend(['train', 'test'])
plt.show()
model.save("sign_mnist_cnn_50_epochs.hs")
print("Model Saved")
test_labels= test['label']
test.drop('label', axis= 1, inplace= True)
test_images= test.values
test_images= np.array([np.reshape(i, (28, 28)) for i in test_images])
test_images= np.array([i.flatten()for i in test_images])
test_labels= label_binrizer.fit_transform(test_labels)
test_images= test_images.reshape(test_images.shape[0], 28, 28, 1)
test_images.shape
y_pred= model.predict(test_images)
from sklearn.metrics import accuracy_score
accuracy_score(test_labels, y_pred.round())
def getLetter(result):
classLabels= {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'}
try:
res= int(result)
return classLabels[res]
except:
return "Error"
What I have tried:
Yes I have tried a lot. I hope sincerely that code project will help me.