-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcifar0.py
44 lines (33 loc) · 1.15 KB
/
cifar0.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
'''
Basic Keras Code for a single-layer neural network
'''
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
# Import Dataset
from data_loader import DataLoader
cifar = DataLoader()
# Training Parameters
batch_size = 128
epochs = 10
# Network Parameters
_WIDTH = 32; _HEIGHT = 32; _CHANNELS = 3
NUM_INPUTS = _WIDTH * _HEIGHT * _CHANNELS
NUM_OUTPUTS = 10
model = Sequential()
model.add(Dense(NUM_OUTPUTS, activation='softmax', input_dim=NUM_INPUTS))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['categorical_accuracy'])
model.summary()
# Train the model, iterating on the data in batches of 32 samples
model.fit(cifar.x_train, cifar.y_train, epochs=epochs, batch_size=batch_size)
# Evaluate
print('')
print('Evaluate:')
loss_and_metrics = model.evaluate(cifar.x_test, cifar.y_test, verbose=1)
print('')
print('Summary: Loss over the test dataset: %.2f, Accuracy: %.2f' % (loss_and_metrics[0], loss_and_metrics[1]))