diff --git a/Auto_ML_CNN_Modelipynb.ipynb b/Auto_ML_CNN_Modelipynb.ipynb
new file mode 100644
index 0000000..9588099
--- /dev/null
+++ b/Auto_ML_CNN_Modelipynb.ipynb
@@ -0,0 +1,669 @@
+{
+ "nbformat": 4,
+ "nbformat_minor": 0,
+ "metadata": {
+ "colab": {
+ "provenance": [],
+ "gpuType": "T4",
+ "authorship_tag": "ABX9TyMHPCvyOHgzetGRESdRyaeQ",
+ "include_colab_link": true
+ },
+ "kernelspec": {
+ "name": "python3",
+ "display_name": "Python 3"
+ },
+ "language_info": {
+ "name": "python"
+ },
+ "accelerator": "GPU"
+ },
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "view-in-github",
+ "colab_type": "text"
+ },
+ "source": [
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "##Imports"
+ ],
+ "metadata": {
+ "id": "dAPowyAl6pRw"
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "id": "6hjD592w6JUT"
+ },
+ "outputs": [],
+ "source": [
+ "import tensorflow_datasets as tfds\n",
+ "import matplotlib.pyplot as plt\n",
+ "import matplotlib.image as mpimg\n",
+ "import random\n",
+ "import tensorflow as tf\n",
+ "import pathlib\n",
+ "import numpy as np\n",
+ "import os\n",
+ "import shutil\n",
+ "import tensorflow as tf"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "##Functions"
+ ],
+ "metadata": {
+ "id": "E4weg6rY6rwH"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "#Function to load TensorFlow Dataset Food101 - 101 classes of different food\n",
+ "def load_dataset():\n",
+ " (train_dataset, val_dataset), info = tfds.load(\n",
+ " \"food101\",\n",
+ " split = ['train[:5%]','validation[:5%]'],\n",
+ " shuffle_files = True,\n",
+ " as_supervised = True, #returns as (img, label) instead of dict\n",
+ " with_info = True,\n",
+ " )\n",
+ " #print(info)\n",
+ " print(\"train_dataset: \", len(train_dataset))\n",
+ " print(\"val_dataset: \",len(val_dataset))\n",
+ "\n",
+ " return train_dataset, val_dataset, info"
+ ],
+ "metadata": {
+ "id": "LL3njLLB6ehX"
+ },
+ "execution_count": 7,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "#resize images to [224,224] without normalization because effifientNet normalizes in the layer\n",
+ "def preprocess_img(image,label):\n",
+ " resized_image = tf.image.resize(image, [224, 224])\n",
+ " resized_image = tf.expand_dims(resized_image, axis=-1)\n",
+ " print(\"image shape: \", resized_image)\n",
+ " return tf.cast(resized_image,tf.float32), label"
+ ],
+ "metadata": {
+ "id": "nmmTUkyN628f"
+ },
+ "execution_count": 16,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "def plot_loss_curves(history):\n",
+ "\n",
+ " loss = history.history[\"loss\"]\n",
+ " val_loss = history.history[\"val_loss\"]\n",
+ "\n",
+ " accuracy = history.history[\"accuracy\"]\n",
+ " val_accuracy = history.history[\"val_accuracy\"]\n",
+ "\n",
+ " epochs = range(len(history.history[\"loss\"]))\n",
+ "\n",
+ " #plot loss\n",
+ " plt.plot(epochs, loss, label=\"training_loss\")\n",
+ " plt.plot(epochs, val_loss, label=\"val_loss\")\n",
+ " plt.title(\"Loss\")\n",
+ " plt.xlabel(\"Epochs\")\n",
+ " plt.legend()\n",
+ "\n",
+ " #plot accuracy\n",
+ " plt.figure()\n",
+ " plt.plot(epochs, accuracy, label=\"training_accuracy\")\n",
+ " plt.plot(epochs, val_accuracy, label=\"val_accuracy\")\n",
+ " plt.title(\"Accuracy\")\n",
+ " plt.xlabel(\"Epochs\")\n",
+ " plt.legend();"
+ ],
+ "metadata": {
+ "id": "szbr23437Mqi"
+ },
+ "execution_count": 17,
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "##Data Preperation"
+ ],
+ "metadata": {
+ "id": "tLza7Qk76tvV"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "train_dataset, val_dataset, info = load_dataset()"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "A9Kz4Eon6ljA",
+ "outputId": "25eda139-a4de-4893-d8fc-1a70a0b5bf78"
+ },
+ "execution_count": 18,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "train_dataset: 3788\n",
+ "val_dataset: 1262\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "BATCH_SIZE = 64\n",
+ "#TRATIN\n",
+ "train_dataset = train_dataset.map(preprocess_img, num_parallel_calls = tf.data.experimental.AUTOTUNE).cache().batch(BATCH_SIZE).prefetch(tf.data.experimental.AUTOTUNE)\n",
+ "\n",
+ "#VALIDATION\n",
+ "val_dataset = val_dataset.map(preprocess_img).batch(BATCH_SIZE).prefetch(tf.data.experimental.AUTOTUNE)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "CMXJtWx47ahf",
+ "outputId": "20d701ca-6cd0-4103-a763-4b3000d11054"
+ },
+ "execution_count": 19,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "image shape: Tensor(\"ExpandDims:0\", shape=(224, 224, 3, 1), dtype=float32)\n",
+ "image shape: Tensor(\"ExpandDims:0\", shape=(224, 224, 3, 1), dtype=float32)\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "import tensorflow as tf\n",
+ "from tensorflow import keras\n",
+ "from tensorflow.keras import layers\n",
+ "from tensorflow.keras.layers.experimental import preprocessing\n",
+ "\n",
+ "# Create a data augmentation stage with horizontal flipping, rotations, zooms\n",
+ "data_augmentation = keras.Sequential([\n",
+ " preprocessing.RandomFlip(\"horizontal\"),\n",
+ " preprocessing.RandomRotation(0.2),\n",
+ " preprocessing.RandomZoom(0.2),\n",
+ " preprocessing.RandomHeight(0.2),\n",
+ " preprocessing.RandomWidth(0.2)\n",
+ "], name =\"data_augmentation\")"
+ ],
+ "metadata": {
+ "id": "GpVs-AT57wCC"
+ },
+ "execution_count": 20,
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "#Implement Transfer Learning Model with EfficientNetB0"
+ ],
+ "metadata": {
+ "id": "CZSJK7Ok8IL4"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "import tensorflow_hub as hub\n",
+ "from tensorflow.keras import layers\n",
+ "\n",
+ "input_shape = (224,224,3)\n",
+ "base_model = tf.keras.applications.EfficientNetB0(include_top = False)\n",
+ "base_model.trainable = False\n",
+ "\n",
+ "#input layer\n",
+ "inputs = layers.Input(shape = input_shape, name = \"input_layer\")\n",
+ "\n",
+ "x = data_augmentation(inputs)\n",
+ "x = base_model(x, training = False)\n",
+ "x = layers.GlobalAveragePooling2D(name=\"global_average_pooling_layer\")(x) #if its just a layer put on RHS (above are models so they go into it)\n",
+ "outputs = layers.Dense(101, activation = \"softmax\", name = \"output_layer\")(x)\n",
+ "model = keras.Model(inputs,outputs)\n",
+ "\n",
+ "model.compile(loss=\"sparse_categorical_crossentropy\",\n",
+ " optimizer = tf.keras.optimizers.Adam(),\n",
+ " metrics = [\"accuracy\"])\n",
+ "\n",
+ "model_history= model.fit(train_dataset,\n",
+ " epochs = 4,\n",
+ " steps_per_epoch = len(train_dataset),\n",
+ " validation_data = val_dataset,\n",
+ " validation_steps = len(val_dataset))"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "RAtM-s1k7y1h",
+ "outputId": "5bc61b12-509a-49fd-9dae-ff00ae3e173e"
+ },
+ "execution_count": 51,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Epoch 1/4\n",
+ "60/60 [==============================] - 32s 424ms/step - loss: 4.0614 - accuracy: 0.1426 - val_loss: 3.2882 - val_accuracy: 0.3368\n",
+ "Epoch 2/4\n",
+ "60/60 [==============================] - 27s 457ms/step - loss: 2.9565 - accuracy: 0.4002 - val_loss: 2.6337 - val_accuracy: 0.4287\n",
+ "Epoch 3/4\n",
+ "60/60 [==============================] - 23s 384ms/step - loss: 2.3832 - accuracy: 0.5034 - val_loss: 2.3108 - val_accuracy: 0.4699\n",
+ "Epoch 4/4\n",
+ "60/60 [==============================] - 24s 405ms/step - loss: 2.0615 - accuracy: 0.5657 - val_loss: 2.1247 - val_accuracy: 0.5016\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "#Fine Tune Model"
+ ],
+ "metadata": {
+ "id": "ofVYQP1c8QRi"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "initial_epochs = 5\n",
+ "fine_tune_epochs = initial_epochs + 4\n",
+ "\n",
+ "model.compile(loss=\"sparse_categorical_crossentropy\",\n",
+ " optimizer = tf.keras.optimizers.Adam(0.001),\n",
+ " metrics = [\"accuracy\"])\n",
+ "\n",
+ "model_history_finetune = model.fit(train_dataset,\n",
+ " epochs = fine_tune_epochs,\n",
+ " validation_data = val_dataset,\n",
+ " validation_steps = len(val_dataset),\n",
+ " initial_epoch = model_history.epoch[-1])#start fine tuing from previous epoch\n",
+ ""
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "xR0_DCEI8VB5",
+ "outputId": "7e37d979-8eec-43ba-eee8-4cb16e953c4e"
+ },
+ "execution_count": 52,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Epoch 4/10\n",
+ "60/60 [==============================] - 33s 418ms/step - loss: 1.8680 - accuracy: 0.5884 - val_loss: 1.9955 - val_accuracy: 0.5182\n",
+ "Epoch 5/10\n",
+ "60/60 [==============================] - 24s 401ms/step - loss: 1.6358 - accuracy: 0.6365 - val_loss: 1.9145 - val_accuracy: 0.5269\n",
+ "Epoch 6/10\n",
+ "60/60 [==============================] - 22s 365ms/step - loss: 1.4951 - accuracy: 0.6661 - val_loss: 1.8569 - val_accuracy: 0.5341\n",
+ "Epoch 7/10\n",
+ "60/60 [==============================] - 21s 353ms/step - loss: 1.3688 - accuracy: 0.6924 - val_loss: 1.8310 - val_accuracy: 0.5396\n",
+ "Epoch 8/10\n",
+ "60/60 [==============================] - 21s 347ms/step - loss: 1.2724 - accuracy: 0.7204 - val_loss: 1.8024 - val_accuracy: 0.5396\n",
+ "Epoch 9/10\n",
+ "60/60 [==============================] - 19s 318ms/step - loss: 1.1820 - accuracy: 0.7381 - val_loss: 1.7921 - val_accuracy: 0.5420\n",
+ "Epoch 10/10\n",
+ "60/60 [==============================] - 19s 321ms/step - loss: 1.1143 - accuracy: 0.7603 - val_loss: 1.7726 - val_accuracy: 0.5380\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "#Update plot loss curves function that have been fit multiple times (before and after fine tuning)\n",
+ "def compare_history(original_history, new_history, initial_epochs = 5):\n",
+ " acc = original_history.history[\"accuracy\"]\n",
+ " loss = original_history.history[\"loss\"]\n",
+ "\n",
+ " val_acc = original_history.history[\"val_accuracy\"]\n",
+ " val_loss = original_history.history[\"val_loss\"]\n",
+ "\n",
+ " #combine original history\n",
+ "\n",
+ " total_acc = acc + new_history.history[\"accuracy\"]\n",
+ " total_loss = loss + new_history.history[\"loss\"]\n",
+ "\n",
+ " total_val_acc = val_acc + new_history.history[\"val_accuracy\"]\n",
+ " total_val_loss = val_loss + new_history.history[\"val_loss\"]\n",
+ "\n",
+ " #accuracy\n",
+ " plt.figure(figsize=(8,8))\n",
+ " plt.subplot(2,1,1)\n",
+ " plt.plot(total_acc, label = \"Training Accuracy\")\n",
+ " plt.plot(total_val_acc, label = \"Val Accuracy\")\n",
+ " plt.plot([initial_epochs-1, initial_epochs-1],plt.ylim(), label = \"Start Fine Tuning\")\n",
+ " plt.legend(loc=\"lower right\")\n",
+ " plt.title(\"Training and Validation Accuracy\")\n",
+ "\n",
+ " #loss\n",
+ " plt.figure(figsize=(8,8))\n",
+ " plt.subplot(2,1,2)\n",
+ " plt.plot(total_loss, label = \"Training Loss\")\n",
+ " plt.plot(total_val_loss, label = \"Val Loss\")\n",
+ " plt.plot([initial_epochs-1, initial_epochs-1],plt.ylim(), label = \"Start Fine Tuning\")\n",
+ " plt.legend(loc=\"upper right\")\n",
+ " plt.title(\"Training and Validation Loss\")\n",
+ "\n",
+ "compare_history(model_history, model_history_finetune, 5)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 709
+ },
+ "id": "HM9Z7JZw8gUG",
+ "outputId": "516b9fd0-3c69-4d53-c4a1-c3f737b763c3"
+ },
+ "execution_count": 54,
+ "outputs": [
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "