-
Notifications
You must be signed in to change notification settings - Fork 0
/
MNIST.py
58 lines (48 loc) · 1.25 KB
/
MNIST.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
sys.path.append(r'.\Python Files')
import numpy as np
from mnist import MNIST
import training
# defining variables
l_hiddenLayers = [96]
batch_size = 1
lrate = 0.1
epoch = 1
title = 'MNIST'
# importing database
mndata = MNIST(r'.\Datasets\MNIST')
x_train, y_train = mndata.load_training()
x_test, y_test = mndata.load_testing()
# converting training database to usable format
temp = y_train
y_train = []
for i in temp:
temp_list = []
for j in range(10):
if i == j:
temp_list.append(1)
else:
temp_list.append(0)
y_train.append(temp_list)
train_inputs = np.array(x_train)
train_inputs = np.float_(train_inputs)
train_inputs /= 255
train_outputs = np.array(y_train)
# converting testing database to usable format
temp = y_test
y_test = []
for i in temp:
temp_list = []
for j in range(10):
if i == j:
temp_list.append(1)
else:
temp_list.append(0)
y_test.append(temp_list)
test_inputs = np.array(x_test)
test_inputs = np.float_(test_inputs)
test_inputs /= 255
test_outputs = np.array(y_test)
variables = (l_hiddenLayers, batch_size, lrate, epoch)
train, test = (train_inputs, train_outputs), (test_inputs, test_outputs)
training.main(variables, train, test, title)