import tensorflow as tf
from tensorflow import keras
import numpy as np
import visualkeras

(train_images, train_labels), (test_images, test_labels) = keras.datasets.cifar10.load_data()

# Normalize
train_images = train_images / 255.0
test_images = test_images / 255.0

# Model
model = keras.models.Sequential()
model.add(keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
model.add(keras.layers.ZeroPadding2D())
model.add(keras.layers.MaxPooling2D((2, 2)))
model.add(keras.layers.Conv2D(64, (3, 3), activation='relu'))
model.add(keras.layers.MaxPooling2D((2, 2)))
model.add(keras.layers.Conv2D(128, (3, 3), activation='relu'))

model.add(keras.layers.Flatten())
model.add(keras.layers.Dense(64, activation='relu'))
model.add(keras.layers.Dense(10))

# Train
model.compile(loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=['accuracy'], optimizer='adam')
model.fit(train_images, train_labels, epochs=1, batch_size=32, validation_data=(test_images, test_labels))

# Test
loss, accuracy = model.evaluate(test_images, test_labels)

visualkeras.layered_view(model).show()
print(accuracy)
print(loss)
