Skip to content

Commit e168187

Browse files
committed
New project: asl letters
1 parent 8405154 commit e168187

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

keras-sign/perceptron.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# A very simple perceptron for classifying american sign language letters
2+
3+
import signdata
4+
from string import ascii_lowercase
5+
import numpy as np
6+
from keras.models import Sequential
7+
from keras.layers import Dense, Flatten, Dropout, BatchNormalization
8+
from keras.utils import np_utils
9+
import wandb
10+
from wandb.keras import WandbCallback
11+
12+
13+
# logging code
14+
run = wandb.init()
15+
config = run.config
16+
17+
# load data
18+
(X_test, y_test) = signdata.load_test_data()
19+
(X_train, y_train) = signdata.load_train_data()
20+
21+
img_width = X_test.shape[1]
22+
img_height = X_test.shape[2]
23+
24+
# one hot encode outputs
25+
y_train = np_utils.to_categorical(y_train)
26+
y_test = np_utils.to_categorical(y_test)
27+
28+
num_classes = y_train.shape[1]
29+
30+
# you may want to normalize the data here..
31+
32+
# create model
33+
model=Sequential()
34+
model.add(Flatten(input_shape=(img_width, img_height)))
35+
model.add(Dense(num_classes, activation='softmax'))
36+
model.compile(loss='categorical_crossentropy', optimizer='adam',
37+
metrics=['accuracy'])
38+
39+
# Fit the model
40+
model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test),
41+
callbacks=[WandbCallback(data_type="image", labels=ascii_lowercase)])

keras-sign/signdata.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os.path
2+
import numpy as np
3+
import pandas as pd
4+
import wandb
5+
6+
if not os.path.isfile('sign_mnist_train.csv'):
7+
raise ("Can't find data file, please go to https://www.kaggle.com/datamunge/sign-language-mnist and download sign-language-mnist.zip and then unzip in the local directory")
8+
9+
def load_train_data():
10+
df=pd.read_csv('sign_mnist_train.csv')
11+
X = df.values[:,1:].reshape(-1,28,28)
12+
y = df.values[:,0]
13+
return X, y
14+
15+
def load_test_data():
16+
df=pd.read_csv('sign_mnist_test.csv')
17+
X = df.values[:,1:].reshape(-1,28,28)
18+
y = df.values[:,0]
19+
return X, y
20+
21+
X,y = load_train_data()
22+
test_X, test_y = load_test_data()
23+
print(X.shape)
24+
print(y.shape)

0 commit comments

Comments
 (0)