-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.py
29 lines (24 loc) · 995 Bytes
/
Model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from tensorflow import keras
import pandas as pd
# Creates model file for use in Main.py
def generate_model():
data_dir = "landmarks.csv"
hands = pd.read_csv("landmarks.csv")
hand_features = hands.copy()
hand_labels = hand_features.pop('actual')
hand_features = np.array(hand_features).astype('float32')
normalize = keras.layers.Normalization()
normalize.adapt(hand_features)
hand_model = tf.keras.Sequential([
keras.layers.Dense(1000),
keras.layers.Dense(500),
keras.layers.Dense(200),
keras.layers.Dense(19, activation='softmax') # Must equal number of items being classified
])
hand_model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False), optimizer = 'adam', metrics=['accuracy'])
hand_model.fit(x=hand_features, y=hand_labels, epochs=25)
hand_model.save('Models\\model2.h5')
generate_model()