<jupyter_start><jupyter_text>Convolutional Neural Network in Keras Bulding a Convolutional Neural Network to classify Fashion-MNIST accessories.  Set seed for reproducibility<jupyter_code>import numpy as np
np.random.seed(42)<jupyter_output><empty_output><jupyter_text>Load dependencies<jupyter_code>import os
import keras
from keras.datasets import fashion_mnist
from keras.models import Sequential
from keras.layers import Layer, Activation, Dense, Dropout, Conv2D, MaxPooling2D, Flatten, LeakyReLU, BatchNormalization
from keras.callbacks import TensorBoard, ModelCheckpoint, EarlyStopping

from keras import backend as K
from keras.utils.generic_utils import get_custom_objects

from keras_contrib.layers.advanced_activations import SineReLU<jupyter_output><empty_output><jupyter_text>Load data<jupyter_code>(X_train, y_train), (X_test, y_test) = fashion_mnist.load_data()<jupyter_output><empty_output><jupyter_text>Preprocess dataFlatten and normalise input data.<jupyter_code>X_train = X_train.reshape(-1, 28, 28, 1)
X_test = X_test.reshape(-1, 28, 28, 1)

X_train = X_train.astype("float32")/255.
X_test = X_test.astype("float32")/255.
# One-hot encoded categories
n_classes = 10
y_train = keras.utils.to_categorical(y_train, n_classes)
y_test = keras.utils.to_categorical(y_test, n_classes)<jupyter_output><empty_output><jupyter_text>Test Predictions<jupyter_code>model_output = 'model_output/weights-cnn-fashion-mnist.hdf5'
saved_model = keras.models.load_model(model_output)<jupyter_output><empty_output><jupyter_text>Test Final Accuracy<jupyter_code>final_loss, final_acc = saved_model.evaluate(X_test, y_test, verbose = 1)
print("Final loss: {0:.4f}, final accuracy: {1:.4f}".format(final_loss, final_acc))<jupyter_output><empty_output><jupyter_text>Log model and metrics in MLFlow<jupyter_code># If it doesn't show anything is because you forgot to copy the known_hosts. Please read the README again and make sure something sensible appears here.
!cat ~/.ssh/known_hosts
import mlflow
import mlflow.keras

mlflow.tracking.set_tracking_uri('http://ekholabs-mlflow:5500')

with mlflow.start_run(experiment_id=2, source_version='0.0.1') as run:
    mlflow.log_param(key='backend', value='tensorflow')
    mlflow.log_param(key='backend_version', value='1.10.0')
    mlflow.log_metric('final_loss', final_loss)
    mlflow.log_metric('final_accuracy', final_acc)
    mlflow.log_artifact(model_output)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10258514567090685, 'fraction_numerical': 0.01887566680344686, 'mean_word_length': 8.063197026022305, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '254941', 'license': 'Apache-2.0', 'n_tokens_mistral': 907, 'n_tokens_neox': 851, 'n_words': 169, 'path': 'notebooks/conv-net-in-keras.ipynb', 'repo_name': 'bluekidds/ai-engineering', 'size': '2437'}