45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import numpy as np
|
|
from tensorflow import keras
|
|
from keras.constraints import maxnorm
|
|
from keras.utils import np_utils
|
|
|
|
seed = 21
|
|
|
|
from keras.datasets import cifar10
|
|
'''
|
|
The CIFAR-10 dataset
|
|
(Canadian Institute for Advanced Research, 10 classes)
|
|
is a subset of the Tiny Images dataset and
|
|
consists of 60000 32x32 color images.
|
|
'''
|
|
|
|
# loading the data
|
|
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
|
|
|
|
#Normalize the inputs from 0-255 to between 0 and 1 by dividing by 255
|
|
x_train = x_train.astype('float32')
|
|
x_test = x_test.astype('float32')
|
|
x_train = x_train/255.0
|
|
x_test = x_test/255.0
|
|
|
|
# One-hot encode outputs
|
|
'''
|
|
Another thing we'll need to do to get the data ready for the network is to one-hot encode the values.
|
|
Lets not go into the specifics of one-hot encoding here, but for now know that the images can't be used by the network as they are,
|
|
they need to be encoded first and
|
|
one-hot encoding is best used when doing binary classification.
|
|
'''
|
|
y_train = np_utils.to_categorical(y_train)
|
|
y_test = np_utils.to_categorical(y_test)
|
|
class_num = y_test.shape[1]
|
|
|
|
|
|
model = keras.Sequential()
|
|
model.add(keras.layers.layer1)
|
|
model.add(keras.layers.layer2)
|
|
model.add(keras.layers.layer3)
|
|
|
|
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy', 'val_accuracy'])
|
|
|
|
print(model.summary())
|