-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtuning_code.py
71 lines (45 loc) · 1.51 KB
/
tuning_code.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
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
"""Accuracy Improvement in MNIST
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1BCf27MUqnJ5okc_aZDtFutphPSVfq79x
"""
from keras.datasets import mnist
dataset = mnist.load_data('mymnist.db')
len(dataset)
train , test = dataset
len(train)
X_train , y_train = train
X_train.shape
X_test , y_test = test
X_test.shape
X_train.shape
X_train_1d = X_train.reshape(-1 , 28,28,1)
X_test_1d = X_test.reshape(-1 , 28,28,1)
X_test_1d.shape
X_train_1d.shape
X_train = X_train_1d.astype('float32')
X_test = X_test_1d.astype('float32')
from keras.utils.np_utils import to_categorical
y_train_cat = to_categorical(y_train)
y_train_cat
from keras.models import Sequential
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Dense
from keras.layers import Flatten
from keras.layers import BatchNormalization
model = Sequential()
model.add(Conv2D(filters=32, kernel_size=(3, 3), activation='relu', kernel_initializer='he_uniform', input_shape=(28, 28, 1)))
model.add(BatchNormalization())
model.add(MaxPooling2D((2, 2)))
model.add(Flatten())
model.add(Dense(100, activation='relu', kernel_initializer='he_uniform'))
model.add(BatchNormalization())
model.add(Dense(10, activation='softmax'))
model.summary()
from keras.optimizers import RMSprop
model.compile(optimizer=RMSprop(), loss='categorical_crossentropy',
metrics=['accuracy']
)
h = model.fit(X_train, y_train_cat, epochs=10)