-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
39 lines (29 loc) · 1.16 KB
/
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
30
31
32
33
34
35
36
37
38
39
# Importing Required Libraries
import tensorflow as tf
import tensorflow.keras as tfk
from tensorflow.keras import datasets
from tensorflow.keras.layers import Flatten,Dense
from tensorflow.keras import Sequential
# Calling the MNIST Data Set which contains Pictures of Hand written digits
mnist=datasets.mnist
# Splitting the data into Testing set and Training Set
(x_train,y_train),(x_test,y_test)=mnist.load_data()
x_train=x_train/255.0
x_test=x_test/255.0
# Creating the Model
# Here we are creating a Sequential Model which will have 3 Layers i.e
# 1.Flat Layer for Input
# 2. Dense Layer with 128 units and relu activation
# 3. Dense Layer with 10 units and softmax activation
model=Sequential()
model.add(Flatten(input_shape=(28,28)))
model.add(Dense(128,activation="relu"))
model.add(Dense(10,activation="softmax"))
# Printing the Summary of the Model that was Created
model.summary()
# Compiling the Model
model.compile(optimizer="adam",loss="sparse_categorical_crossentropy",metrics=["accuracy"])
# Training the Model
model.fit(x_train,y_train,epochs=100)
# And Finally Saving the Model For Future Use.
model.save("number_recognition.model")