File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ import numpy as np
3
+ import matplotlib .pyplot as plt
4
+ import cv2
5
+ import tensorflow as tf
6
+
7
+ def training_NN ():
8
+ mnist = tf .keras .datasets .mnist
9
+ (x_train , y_train ), (x_test , y_test ) = mnist .load_data ()
10
+
11
+ x_train = tf .keras .utils .normalize (x_train , axis = 1 )
12
+ x_test = tf .keras .utils .normalize (x_test , axis = 1 )
13
+
14
+ model = tf .keras .models .Sequential ()
15
+ model .add (tf .keras .layers .Flatten (input_shape = (28 , 28 )))
16
+ model .add (tf .keras .layers .Dense (128 , activation = 'relu' ))
17
+ model .add (tf .keras .layers .Dense (128 , activation = 'relu' ))
18
+ model .add (tf .keras .layers .Dense (10 , activation = 'softmax' ))
19
+
20
+ model .compile (optimizer = 'adam' , loss = 'sparse_categorical_crossentropy' , metrics = ['accuracy' ])
21
+
22
+ model .fit (x_train , y_train , epochs = 3 )
23
+ model .save ('handwritten.model' )
24
+
25
+
26
+
27
+ def load_model ():
28
+ model = tr .keras .models .load_model ('handwritten.model' )
29
+
30
+ def main ():
31
+ # training_NN()
32
+ load_model ()
You can’t perform that action at this time.
0 commit comments