-
Notifications
You must be signed in to change notification settings - Fork 0
/
fisher_pool.py
31 lines (24 loc) · 1.07 KB
/
fisher_pool.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
import keras
import numpy as np
from keras.datasets import mnist
import matplotlib.pyplot as plt
model = keras.models.Sequential()
model.add(keras.layers.Conv2D(3,3,input_shape=(56,56,1)))
model.add(keras.layers.pooling.MaxPool2D(2))
model.add(keras.layers.Conv2D(3,3))
model.add(keras.layers.pooling.MaxPool2D(2))
model.add(keras.layers.Flatten())
model.add(keras.layers.Dense(10,activation='softmax'))
model.compile(optimizer='SGD',loss='categorical_crossentropy')
def get_data():
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train=x_train.repeat(2,1).repeat(2,2).reshape([-1,56,56,1])
x_test=x_test.repeat(2,1).repeat(2,2).reshape([-1,56,56,1])
x_train=x_train+np.random.random(x_train.shape)
x_test=x_test+np.random.random(x_test.shape)
t_train = np.zeros([y_train.shape[0],10])
t_train[np.arange(t_train.shape[0]),y_train]=1
t_test = np.zeros([y_test.shape[0],10])
t_test[np.arange(t_test.shape[0]),y_test]=1
return((x_train, t_train), (x_test, t_test))
model.fit(x_train,t_train, epochs=2,validation_data = (x_test,t_test))