1 line
2.2 KiB
Plaintext
1 line
2.2 KiB
Plaintext
{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["# Exercises for Lecture 14 (Convolutional neural networks)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["import numpy as np\n", "import tensorflow as tf\n", "from tensorflow import keras\n", "\n", "# To make this notebook's output stable across runs\n", "def reset_state(seed=42):\n", " tf.keras.backend.clear_session()\n", " tf.random.set_seed(seed)\n", " np.random.seed(seed)"]}, {"cell_type": "markdown", "metadata": {"slideshow": {"slide_type": "subslide"}}, "source": ["## Exercise 1: Build a deeper CNN architecture for fashion MNIST than considered in the corresponding lecture to achieves a better classification accuracy."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Following the guiding CNN design principles covered in the lecture to construct a better CNN architecture."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Load and set up data."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# Load fashion MNIST data\n", "(X_train_full, y_train_full), (X_test, y_test) = keras.datasets.fashion_mnist.load_data()\n", "X_train, X_valid = X_train_full[:-30000], X_train_full[-30000:]\n", "y_train, y_valid = y_train_full[:-30000], y_train_full[-30000:]\n", "\n", "# Standardize\n", "X_mean = X_train.mean(axis=0, keepdims=True)\n", "X_std = X_train.std(axis=0, keepdims=True) + 1e-7\n", "X_train = (X_train - X_mean) / X_std\n", "X_valid = (X_valid - X_mean) / X_std\n", "X_test = (X_test - X_mean) / X_std\n", "\n", "# Add final channel axis (one channel)\n", "X_train = X_train[..., np.newaxis]\n", "X_valid = X_valid[..., np.newaxis]\n", "X_test = X_test[..., np.newaxis]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Build and fit new model, and evaluate its performance."]}], "metadata": {"celltoolbar": "Tags", "kernelspec": {"display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.12"}}, "nbformat": 4, "nbformat_minor": 4} |