# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## Convolutional Neural Network with CIFAR10 dataset
#
# Use the CIFAR10 [dataset](https://www.cs.toronto.edu/~kriz/cifar.html), which contains 50,000 32x32 color training images, labeled over 10 categories, and 10,000 test images.
#
# As this dataset is also included in Keras datasets, we just ask the keras.datasets module for the dataset.

# ## Import Classes and Functions

# +
import numpy as np

from keras.datasets import cifar10
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D
from keras import backend as K
from keras.utils import to_categorical
# -

# ## Initialize Random Number Generator

# fix random seed for reproducibility
seed = 7
np.random.seed(seed)

# +
num_classes = 10

# input image dimensions
img_rows, img_cols = 32, 32
# -

# ## Load The Dataset
# The data, shuffled and split between train and test sets

(X_train, y_train), (X_test, y_test) = cifar10.load_data()

if K.image_data_format() == 'channels_first':
    X_train = X_train.reshape(X_train.shape[0], 3, img_rows, img_cols)
    X_test = X_test.reshape(X_test.shape[0], 3, img_rows, img_cols)
    input_shape = (3, img_rows, img_cols)
else:
    X_train = X_train.reshape(X_train.shape[0], img_rows, img_cols, 3)
    X_test = X_test.reshape(X_test.shape[0], img_rows, img_cols, 3)
    input_shape = (img_rows, img_cols, 3)

# ### Normalize the data

X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
X_train /= 255
X_test /= 255
print('X_train shape:', X_train.shape)
print(X_train.shape[0], 'train samples')
print(X_test.shape[0], 'test samples')

# ### Convert class vectors to binary class matrices

y_train = to_categorical(y_train, num_classes)
y_test = to_categorical(y_test, num_classes)


# ### Define The Neural Network Model

def create_model():
    model = Sequential()
    ## Your model here
    # model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    return model


# ### Create the Model

model = create_model()

# ### Define training parameters

batch_size = 1
epochs = 1

# ### Train the model

model.fit(X_train, y_train, batch_size=batch_size, epochs=epochs, verbose=1, validation_data=(X_test, y_test))

# ### Evaluate the model

score = model.evaluate(X_test, y_test, verbose=0)
print('Test loss:', score[0])
print('Test accuracy:', score[1])

StarcoderdataJupyterScriptsDedupFiltered