<jupyter_start><jupyter_text>Network<jupyter_code># first layer for Keras functional api
img_input = keras.Input(shape=(28, 28, 1), name="img")
print(img_input.shape)
print(img_input.dtype)
# rest of the model using pre-defined layers from Keras api

from keras.layers import Conv2D, BatchNormalization, Dropout, Input, Dense, Flatten

l1 = Conv2D(filters  = 100,
            kernel_size = (5,5),
            strides = (1,1),
            padding = 'same',
            activation = 'relu',
            use_bias = True,
            kernel_initializer = 'glorot_uniform')(img_input)

l2 = Conv2D(filters  = 25,
            kernel_size = (5,5),
            strides = (1,1),
            padding = 'same',
            activation = 'relu',
            use_bias = True,
            kernel_initializer = 'glorot_uniform')(l1)

l2_flat = Flatten()(l2)

prediction = Dense(10,activation = 'softmax')(l2_flat)
from keras.models import Model
from keras.optimizers import Adam
# define model and optimizer.
inzvaNet = Model(inputs=img_input, outputs=prediction)

# our optimizer
opt = Adam(lr = 0.001)

# we compile to start the weights etc.
# sparse categorical to automatically one-hot encode!
# point out that in previous it was logits
inzvaNet.compile(optimizer=opt,
               loss='sparse_categorical_crossentropy',
               metrics=['accuracy'])
# final check of model before training
inzvaNet.summary()
# training
history = inzvaNet.fit(x_train, y_train, batch_size=128, epochs=3, validation_split=0.1)
# test model on test data
test_scores = inzvaNet.evaluate(x_test, y_test, verbose=2)
print("Test loss:", test_scores[0])
print("Test accuracy:", test_scores[1])<jupyter_output>313/313 - 3s - loss: 0.0707 - accuracy: 0.9789
Test loss: 0.07065042108297348
Test accuracy: 0.9789000153541565
{'fraction_non_alphanumeric': 0.1109253065774805, 'fraction_numerical': 0.05239687848383501, 'mean_word_length': 3.532828282828283, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '662850', 'license': 'MIT', 'n_tokens_mistral': 654, 'n_tokens_neox': 595, 'n_words': 152, 'path': 'Applied AI Study Group #4 - January 2021/Week 1/Lecture Notebooks/2-mnist_classification_conv_kerasF.ipynb', 'repo_name': 'cerob/Applied-AI-Study-Group', 'size': '1794'}