forked from univai-summerschool-2019/LogisticText
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keras_logistic.py
35 lines (29 loc) · 994 Bytes
/
keras_logistic.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
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Flatten
# taken from lukas/ml-class
from keras.utils import to_categorical
import wandb
from wandb.keras import WandbCallback
# logging code
run = wandb.init()
config = run.config
# load data
(X_train, y_train), (X_test, y_test) = mnist.load_data()
img_width = X_train.shape[1]
img_height = X_train.shape[2]
# one hot encode outputs
y_train = to_categorical(y_train)
y_test = to_categorical(y_test)
labels = range(10)
num_classes = y_train.shape[1]
# create model
model = Sequential()
model.add(Flatten(input_shape=(img_width, img_height)))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam',
metrics=['accuracy'])
model.summary()
# Fit the model
model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test),
callbacks=[WandbCallback(data_type="image", labels=labels, save_model=False)])