# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/Arshad221b/Sign-Language-Recognition-/blob/master/ASL2.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="imJ4pdxMFuob" colab_type="code" outputId="00e50642-4322-4f4e-e497-011de77529b8" colab={"base_uri": "https://localhost:8080/", "height": 74}
import keras
import numpy as np
import pandas as pd
import cv2 
from keras.models import Sequential 
from keras.layers import Conv2D,MaxPooling2D, Dense,Flatten
from keras.datasets import mnist 
import matplotlib.pyplot as plt
from keras.utils import np_utils
from keras.optimizers import SGD

# + id="qIP4zEpGGYl1" colab_type="code" outputId="fc05d15f-6713-4e3b-f9e6-849225009a4d" colab={"base_uri": "https://localhost:8080/", "height": 403}
# !pip install PyDrive

# + id="ijUASkTROl6D" colab_type="code" colab={}
import os
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

# + id="2yEzz9S4RdR9" colab_type="code" colab={}
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

# + id="Z6DDOrSbRqA3" colab_type="code" colab={}
download = drive.CreateFile({'id': '1wG0gS-bqjV6yz1YveuxkvHT5_2DOuT05'})
download.GetContentFile('train.csv')
train = pd.read_csv('train.csv')

# + id="2Rc5CNhVRs4b" colab_type="code" colab={}
download = drive.CreateFile({'id': '1q_Zwlu3RncjKq1YpiVtkiMPxIIueGRYB'})
download.GetContentFile('test.csv')
test = pd.read_csv('test.csv')

# + id="Bzui153jR012" colab_type="code" outputId="fa16d255-5c14-4976-b736-839e39a32c61" colab={"base_uri": "https://localhost:8080/", "height": 499}
display(train.info())

display(test.info())

display(train.head(n = 2))
display(test.head(n = 2))

# + id="Yim557wpbSf_" colab_type="code" colab={}
train_Y = train['label']
test_Y = test['label']
train_X = train.drop(['label'],axis = 1)
test_X = test.drop(['label'],axis = 1)

# + id="PyiXHi2DkT4r" colab_type="code" colab={}
train_X = train_X.astype('float32') / 255
test_X = test_X.astype('float32')/255

# + id="RpKOAcYvi-wS" colab_type="code" outputId="d640461b-356f-4c33-e1e4-1a46cd289040" colab={"base_uri": "https://localhost:8080/", "height": 1062}
display(train_Y)


# + id="zRdBQOJ0bVvF" colab_type="code" colab={}

train_X = train_X.values.reshape(27455,784)
test_X = test_X.values.reshape(7172,784)
train_Y = keras.utils.to_categorical(train_Y,26)
test_Y = keras.utils.to_categorical(test_Y,26)

# + id="00fdB0Yvl1d8" colab_type="code" colab={}
model = Sequential()
model.add(Dense(units=128,activation="relu",input_shape=(784,)))
model.add(Dense(units=128,activation="relu"))
model.add(Dense(units=128,activation="relu"))
model.add(Dense(units=128,activation="relu"))
model.add(Dense(units=128,activation="relu"))
model.add(Dense(units=26,activation="softmax"))

# + id="QIfU7or-fcAM" colab_type="code" outputId="a570dd53-470a-4dd2-f202-090fdd291622" colab={"base_uri": "https://localhost:8080/", "height": 3359}
model.compile(optimizer=SGD(0.001),loss="categorical_crossentropy",metrics=["accuracy"])
model.fit(train_X,train_Y,batch_size=32,epochs=100,verbose=1)

# + id="tmXKzSMSfgDS" colab_type="code" outputId="226ed580-45e6-479e-9576-2fc469348fd5" colab={"base_uri": "https://localhost:8080/", "height": 92}
accuracy = model.evaluate(x=test_X,y=test_Y,batch_size=32)
print("Accuracy: ",accuracy[1])

# + id="QFWBt201hlEf" colab_type="code" outputId="14a91e7e-72a3-479d-ec39-789c06ad6168" colab={"base_uri": "https://localhost:8080/", "height": 74}
img = test_X[1]
test_img = img.reshape((1,784))
img_class = model.predict_classes(test_img)
prediction = img_class[0]
classname = img_class[0]
print("Class: ",classname)


# + id="5Yzwqb7Fhojk" colab_type="code" outputId="a22d2978-ca5e-4dd3-fee1-afdb1a1a82e8" colab={"base_uri": "https://localhost:8080/", "height": 382}
img = img.reshape((28,28))
plt.imshow(img)
plt.title(classname)
plt.show()

# + id="3NldTeSghsHB" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 94} outputId="2ce7b919-50c1-4cde-b2c7-05a8f2d8d717"
model.save_weights('model_weights.h5')
weights_file = drive.CreateFile({'title' : 'model_weights.h5'})
weights_file.SetContentFile('model_weights.h5')
weights_file.Upload()
drive.CreateFile({'id': weights_file.get('id')})

# + id="b3MJfJrWyGNH" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 94} outputId="9ccecde1-5cca-4397-f338-72155c24d8a2"
model.save('model.h5')
weights_file = drive.CreateFile({'title' : 'model.h5'})
weights_file.SetContentFile('model.h5')
weights_file.Upload()
drive.CreateFile({'id': weights_file.get('id')})

# + id="WFgvZoNXqsCJ" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 173} outputId="b5894724-4551-4efd-ffe9-41c446c360f7"
# !pip install h5py pyyaml 

# + id="y7SmbytZx6Wa" colab_type="code" colab={}


StarcoderdataJupyterScriptsDedupFiltered