{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "executionInfo": {
     "elapsed": 3351,
     "status": "ok",
     "timestamp": 1637333185840,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "xc1bJVSQB406"
   },
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'tensorflow'",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mModuleNotFoundError\u001b[39m                       Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtensorflow\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtf\u001b[39;00m\n\u001b[32m      2\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtensorflow_hub\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mhub\u001b[39;00m\n",
      "\u001b[31mModuleNotFoundError\u001b[39m: No module named 'tensorflow'"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import tensorflow_hub as hub"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 34,
     "status": "ok",
     "timestamp": 1637333185844,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "dN3hGdXso2Y9",
    "outputId": "fa57a1eb-76d0-4185-abbc-299cc76f6e20"
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'tf' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mNameError\u001b[39m                                 Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mtf\u001b[49m.__version__, hub.__version__\n",
      "\u001b[31mNameError\u001b[39m: name 'tf' is not defined"
     ]
    }
   ],
   "source": [
    "tf.__version__, hub.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 30,
     "status": "ok",
     "timestamp": 1637333186929,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "AkoYVaJfo4nE",
    "outputId": "159a089c-03d0-413f-d0c3-c5443fb9d3d8"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GPU Available\n"
     ]
    }
   ],
   "source": [
    "print('GPU','Available') if tf.config.list_physical_devices('GPU') \\\n",
    "                         else ('Not available')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 206
    },
    "executionInfo": {
     "elapsed": 24,
     "status": "ok",
     "timestamp": 1637333186932,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "uGm1KdoS6mob",
    "outputId": "fa853427-34a0-4492-db3c-96c5a5a0f332"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>breed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000bec180eb18c7604dcecc8fe0dba07</td>\n",
       "      <td>boston_bull</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>001513dfcb2ffafc82cccf4d8bbaba97</td>\n",
       "      <td>dingo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>001cdf01b096e06d78e9e5112d419397</td>\n",
       "      <td>pekinese</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>00214f311d5d2247d5dfe4fe24b2303d</td>\n",
       "      <td>bluetick</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0021f9ceb3235effd7fcde7f7538ed62</td>\n",
       "      <td>golden_retriever</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 id             breed\n",
       "0  000bec180eb18c7604dcecc8fe0dba07       boston_bull\n",
       "1  001513dfcb2ffafc82cccf4d8bbaba97             dingo\n",
       "2  001cdf01b096e06d78e9e5112d419397          pekinese\n",
       "3  00214f311d5d2247d5dfe4fe24b2303d          bluetick\n",
       "4  0021f9ceb3235effd7fcde7f7538ed62  golden_retriever"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "labels_csv = pd.read_csv('/content/drive/MyDrive/Dog_vision/labels.csv')\n",
    "labels_csv.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 406
    },
    "executionInfo": {
     "elapsed": 3227,
     "status": "ok",
     "timestamp": 1637333190142,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "d7PwyfX6DvMV",
    "outputId": "c9ed5774-ccd1-4d78-84a4-3bc7ac28520c"
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 100684 characters]\n",
      "text/plain": [
       "<Figure size 1440x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "labels_csv['breed'].value_counts().plot.bar(figsize=(20, 10));"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 27,
     "status": "ok",
     "timestamp": 1637333190143,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "fcaxx4QNDyzj",
    "outputId": "ea99ff08-e190-4148-9dda-ca1c88899ab3"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "82.0"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels_csv['breed'].value_counts().median()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 361
    },
    "executionInfo": {
     "elapsed": 46671,
     "status": "ok",
     "timestamp": 1637333236805,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "wD5KwBxhF2zZ",
    "outputId": "507b11aa-8566-4766-facb-1e045841e2d7"
   },
   "outputs": [
    {
     "data": {
      "image/jpeg": "[encoded data, 53512 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from IPython.display import Image\n",
    "Image('/content/drive/MyDrive/Dog_vision/train/00214f311d5d2247d5dfe4fe24b2303d.jpg')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "L4LHa0YIGPrx"
   },
   "source": [
    "getting images and their labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 206
    },
    "executionInfo": {
     "elapsed": 657,
     "status": "ok",
     "timestamp": 1637333237443,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "ybswGR0WGYon",
    "outputId": "e9be25ff-cfda-47bf-ebc2-9f513fc399c3"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>breed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000bec180eb18c7604dcecc8fe0dba07</td>\n",
       "      <td>boston_bull</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>001513dfcb2ffafc82cccf4d8bbaba97</td>\n",
       "      <td>dingo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>001cdf01b096e06d78e9e5112d419397</td>\n",
       "      <td>pekinese</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>00214f311d5d2247d5dfe4fe24b2303d</td>\n",
       "      <td>bluetick</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0021f9ceb3235effd7fcde7f7538ed62</td>\n",
       "      <td>golden_retriever</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 id             breed\n",
       "0  000bec180eb18c7604dcecc8fe0dba07       boston_bull\n",
       "1  001513dfcb2ffafc82cccf4d8bbaba97             dingo\n",
       "2  001cdf01b096e06d78e9e5112d419397          pekinese\n",
       "3  00214f311d5d2247d5dfe4fe24b2303d          bluetick\n",
       "4  0021f9ceb3235effd7fcde7f7538ed62  golden_retriever"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels_csv.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "executionInfo": {
     "elapsed": 85,
     "status": "ok",
     "timestamp": 1637333237446,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "Jfsxu0ONGh__"
   },
   "outputs": [],
   "source": [
    "filenames= [\"/content/drive/MyDrive/Dog_vision/train/\" + fname \n",
    "            + '.jpg' for fname in labels_csv['id']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "executionInfo": {
     "elapsed": 84,
     "status": "ok",
     "timestamp": 1637333237447,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "UXUITbJEHDmg"
   },
   "outputs": [],
   "source": [
    "import os\n",
    "if len(os.listdir('/content/drive/MyDrive/Dog_vision/train/')) != len(filenames):\n",
    "  print('not allf files were imported')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "executionInfo": {
     "elapsed": 85,
     "status": "ok",
     "timestamp": 1637333237450,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "GXqek3pRU0TD"
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "labels = labels_csv['breed'].to_numpy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 84,
     "status": "ok",
     "timestamp": 1637333237451,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "VMsSKTqKVwLy",
    "outputId": "2720c77a-b6d1-4eaa-bef9-463a15e69e36"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['boston_bull', 'dingo', 'pekinese', ..., 'airedale',\n",
       "       'miniature_pinscher', 'chesapeake_bay_retriever'], dtype=object)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 80,
     "status": "ok",
     "timestamp": 1637333237454,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "SnL8YegyVw0z",
    "outputId": "849a8b58-1af2-46e0-9c53-92233c9cd096"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(labels)==len(filenames)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "executionInfo": {
     "elapsed": 77,
     "status": "ok",
     "timestamp": 1637333237455,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "iJ03PtoJV7zv"
   },
   "outputs": [],
   "source": [
    "unique_breeds = np.unique(labels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 76,
     "status": "ok",
     "timestamp": 1637333237456,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "r3uDBjnTdW2v",
    "outputId": "6cde4ebf-cbfe-43a9-fadf-8d1e7051425f"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['affenpinscher', 'afghan_hound', 'african_hunting_dog', 'airedale',\n",
       "       'american_staffordshire_terrier', 'appenzeller',\n",
       "       'australian_terrier', 'basenji', 'basset', 'beagle',\n",
       "       'bedlington_terrier', 'bernese_mountain_dog',\n",
       "       'black-and-tan_coonhound', 'blenheim_spaniel', 'bloodhound',\n",
       "       'bluetick', 'border_collie', 'border_terrier', 'borzoi',\n",
       "       'boston_bull', 'bouvier_des_flandres', 'boxer',\n",
       "       'brabancon_griffon', 'briard', 'brittany_spaniel', 'bull_mastiff',\n",
       "       'cairn', 'cardigan', 'chesapeake_bay_retriever', 'chihuahua',\n",
       "       'chow', 'clumber', 'cocker_spaniel', 'collie',\n",
       "       'curly-coated_retriever', 'dandie_dinmont', 'dhole', 'dingo',\n",
       "       'doberman', 'english_foxhound', 'english_setter',\n",
       "       'english_springer', 'entlebucher', 'eskimo_dog',\n",
       "       'flat-coated_retriever', 'french_bulldog', 'german_shepherd',\n",
       "       'german_short-haired_pointer', 'giant_schnauzer',\n",
       "       'golden_retriever', 'gordon_setter', 'great_dane',\n",
       "       'great_pyrenees', 'greater_swiss_mountain_dog', 'groenendael',\n",
       "       'ibizan_hound', 'irish_setter', 'irish_terrier',\n",
       "       'irish_water_spaniel', 'irish_wolfhound', 'italian_greyhound',\n",
       "       'japanese_spaniel', 'keeshond', 'kelpie', 'kerry_blue_terrier',\n",
       "       'komondor', 'kuvasz', 'labrador_retriever', 'lakeland_terrier',\n",
       "       'leonberg', 'lhasa', 'malamute', 'malinois', 'maltese_dog',\n",
       "       'mexican_hairless', 'miniature_pinscher', 'miniature_poodle',\n",
       "       'miniature_schnauzer', 'newfoundland', 'norfolk_terrier',\n",
       "       'norwegian_elkhound', 'norwich_terrier', 'old_english_sheepdog',\n",
       "       'otterhound', 'papillon', 'pekinese', 'pembroke', 'pomeranian',\n",
       "       'pug', 'redbone', 'rhodesian_ridgeback', 'rottweiler',\n",
       "       'saint_bernard', 'saluki', 'samoyed', 'schipperke',\n",
       "       'scotch_terrier', 'scottish_deerhound', 'sealyham_terrier',\n",
       "       'shetland_sheepdog', 'shih-tzu', 'siberian_husky', 'silky_terrier',\n",
       "       'soft-coated_wheaten_terrier', 'staffordshire_bullterrier',\n",
       "       'standard_poodle', 'standard_schnauzer', 'sussex_spaniel',\n",
       "       'tibetan_mastiff', 'tibetan_terrier', 'toy_poodle', 'toy_terrier',\n",
       "       'vizsla', 'walker_hound', 'weimaraner', 'welsh_springer_spaniel',\n",
       "       'west_highland_white_terrier', 'whippet',\n",
       "       'wire-haired_fox_terrier', 'yorkshire_terrier'], dtype=object)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unique_breeds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 66,
     "status": "ok",
     "timestamp": 1637333237457,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "tYnAi_fBdbYO",
    "outputId": "9f66a4a3-5148-4d62-e505-9cc4d51647df"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['boston_bull', 'dingo', 'pekinese', ..., 'airedale',\n",
       "       'miniature_pinscher', 'chesapeake_bay_retriever'], dtype=object)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 36
    },
    "executionInfo": {
     "elapsed": 58,
     "status": "ok",
     "timestamp": 1637333237458,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "V3JzeGtydjPQ",
    "outputId": "eaa54450-8f9a-4127-eef8-ffceb8a0652d"
   },
   "outputs": [
    {
     "data": {
      "application/vnd.google.colaboratory.intrinsic+json": {
       "type": "string"
      },
      "text/plain": [
       "'boston_bull'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 60,
     "status": "ok",
     "timestamp": 1637333237462,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "yRUFo9Wfdz-v",
    "outputId": "5c73f20c-d15b-457f-b9a7-ac05e8f3505d"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False,  True, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels[0] == unique_breeds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "executionInfo": {
     "elapsed": 55,
     "status": "ok",
     "timestamp": 1637333237462,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "I37_B5U6d-R1"
   },
   "outputs": [],
   "source": [
    "boolean_labels = [label == unique_breeds for label in labels]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 54,
     "status": "ok",
     "timestamp": 1637333237463,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "83OzFn2zeE3-",
    "outputId": "4d857179-a145-48f6-9b9e-1ffd91b74caf"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False,  True, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "boolean_labels[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "executionInfo": {
     "elapsed": 49,
     "status": "ok",
     "timestamp": 1637333237463,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "JzToxzvaeUmm"
   },
   "outputs": [],
   "source": [
    "X = filenames\n",
    "y = boolean_labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 48,
     "status": "ok",
     "timestamp": 1637333237464,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "iRBvjXDUoTUN",
    "outputId": "70fbbf71-267a-465f-93fe-5516adaad0bd"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['/content/drive/MyDrive/Dog_vision/train/000bec180eb18c7604dcecc8fe0dba07.jpg',\n",
       " '/content/drive/MyDrive/Dog_vision/train/001513dfcb2ffafc82cccf4d8bbaba97.jpg',\n",
       " '/content/drive/MyDrive/Dog_vision/train/001cdf01b096e06d78e9e5112d419397.jpg']"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 46,
     "status": "ok",
     "timestamp": 1637333237465,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "ScYSSShBoUwC",
    "outputId": "745add86-138d-4c2e-b7d3-fbe322267294"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False,  True, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False]),\n",
       " array([False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False,  True, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False]),\n",
       " array([False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False,  True, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False])]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "executionInfo": {
     "elapsed": 40,
     "status": "ok",
     "timestamp": 1637333237465,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "fFSzmDy-oYu8"
   },
   "outputs": [],
   "source": [
    "NUM_IMAGES = 1000 #@param {type:'slider', min:1000, max:10000}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "executionInfo": {
     "elapsed": 41,
     "status": "ok",
     "timestamp": 1637333237467,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "C4mkwE1LpCVJ"
   },
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "X_train, X_val, y_train, y_val = train_test_split(X[:NUM_IMAGES],\n",
    "                                                y[:NUM_IMAGES],\n",
    "                                                test_size=0.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 439,
     "status": "ok",
     "timestamp": 1637333237866,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "tq2XfQVCplNw",
    "outputId": "baf584ba-a657-4ab9-de61-395710c585e0"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(257, 350, 3)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from matplotlib.pyplot import imread\n",
    "image = imread(filenames[42])\n",
    "image.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 450,
     "status": "ok",
     "timestamp": 1637333243302,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "2mt5NYh5sFS4",
    "outputId": "88fccba0-036c-4d23-96f0-a22579cd9e66"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor: shape=(2, 350, 3), dtype=uint8, numpy=\n",
       "array([[[ 89, 137,  87],\n",
       "        [ 76, 124,  74],\n",
       "        [ 63, 111,  59],\n",
       "        ...,\n",
       "        [ 76, 134,  86],\n",
       "        [ 76, 134,  86],\n",
       "        [ 76, 134,  86]],\n",
       "\n",
       "       [[ 72, 119,  73],\n",
       "        [ 67, 114,  68],\n",
       "        [ 63, 111,  63],\n",
       "        ...,\n",
       "        [ 75, 131,  84],\n",
       "        [ 74, 132,  84],\n",
       "        [ 74, 131,  86]]], dtype=uint8)>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tf.constant(image)[:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "executionInfo": {
     "elapsed": 43,
     "status": "ok",
     "timestamp": 1637333243305,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "XmiwM8afsX0A"
   },
   "outputs": [],
   "source": [
    "IMG_SIZE = 224\n",
    "def process_image(image_path):\n",
    "  image = tf.io.read_file(image_path)\n",
    "  image = tf.image.decode_jpeg(image, channels=3)\n",
    "  image = tf.image.convert_image_dtype(image, tf.float32)\n",
    "  image = tf.image.resize(image, size=[IMG_SIZE, IMG_SIZE])\n",
    "  return image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "executionInfo": {
     "elapsed": 42,
     "status": "ok",
     "timestamp": 1637333243307,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "UyicqWo0GAl1"
   },
   "outputs": [],
   "source": [
    "def get_image_label(image_path, label):\n",
    "  return process_image(image_path), label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 41,
     "status": "ok",
     "timestamp": 1637333243308,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "UJlPXKWAF-Fb",
    "outputId": "784c0dde-b010-413e-d705-6ae78d3cf93a"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(<tf.Tensor: shape=(224, 224, 3), dtype=float32, numpy=\n",
       " array([[[0.3264178 , 0.5222886 , 0.3232816 ],\n",
       "         [0.2537167 , 0.44366494, 0.24117757],\n",
       "         [0.25699762, 0.4467087 , 0.23893751],\n",
       "         ...,\n",
       "         [0.29325107, 0.5189916 , 0.3215547 ],\n",
       "         [0.29721776, 0.52466875, 0.33030328],\n",
       "         [0.2948505 , 0.5223015 , 0.33406618]],\n",
       " \n",
       "        [[0.25903144, 0.4537807 , 0.27294815],\n",
       "         [0.24375686, 0.4407019 , 0.2554778 ],\n",
       "         [0.2838985 , 0.47213382, 0.28298813],\n",
       "         ...,\n",
       "         [0.2785345 , 0.5027992 , 0.31004712],\n",
       "         [0.28428748, 0.5108719 , 0.32523635],\n",
       "         [0.28821915, 0.5148036 , 0.32916805]],\n",
       " \n",
       "        [[0.20941195, 0.40692952, 0.25792548],\n",
       "         [0.24045378, 0.43900946, 0.2868911 ],\n",
       "         [0.29001117, 0.47937486, 0.32247734],\n",
       "         ...,\n",
       "         [0.26074055, 0.48414773, 0.30125174],\n",
       "         [0.27101526, 0.49454468, 0.32096273],\n",
       "         [0.27939945, 0.5029289 , 0.32934693]],\n",
       " \n",
       "        ...,\n",
       " \n",
       "        [[0.00634795, 0.03442048, 0.0258106 ],\n",
       "         [0.01408936, 0.04459917, 0.0301715 ],\n",
       "         [0.01385712, 0.04856448, 0.02839671],\n",
       "         ...,\n",
       "         [0.4220516 , 0.39761978, 0.21622123],\n",
       "         [0.47932503, 0.45370543, 0.2696505 ],\n",
       "         [0.48181024, 0.45828083, 0.27004552]],\n",
       " \n",
       "        [[0.00222061, 0.02262166, 0.03176915],\n",
       "         [0.01008397, 0.03669046, 0.02473482],\n",
       "         [0.00608852, 0.03890046, 0.01207283],\n",
       "         ...,\n",
       "         [0.36070833, 0.33803678, 0.16216145],\n",
       "         [0.42499566, 0.3976801 , 0.21701711],\n",
       "         [0.4405433 , 0.4139589 , 0.23183356]],\n",
       " \n",
       "        [[0.05608025, 0.06760229, 0.10401428],\n",
       "         [0.05441074, 0.07435255, 0.05428263],\n",
       "         [0.04734282, 0.07581793, 0.02060942],\n",
       "         ...,\n",
       "         [0.3397559 , 0.31265694, 0.14725602],\n",
       "         [0.387725  , 0.360274  , 0.18714729],\n",
       "         [0.43941984, 0.41196886, 0.23884216]]], dtype=float32)>,\n",
       " <tf.Tensor: shape=(120,), dtype=bool, numpy=\n",
       " array([False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "         True, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False])>)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process_image(X[42]), tf.constant(y[42])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "executionInfo": {
     "elapsed": 36,
     "status": "ok",
     "timestamp": 1637333243310,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "xEFEiLGrF_pz"
   },
   "outputs": [],
   "source": [
    "BATCH_SIZE = 32\n",
    "def create_data_batches(X, y=None, batch_size=BATCH_SIZE, \n",
    "                         valid_data=False, test_data=False):\n",
    "  if test_data:\n",
    "    data = tf.data.Dataset.from_tensor_slices(tf.constant(X))\n",
    "    data_batch = data.map(process_image).batch(BATCH_SIZE)\n",
    "    return data_batch\n",
    "  \n",
    "  elif valid_data:\n",
    "    data = tf.data.Dataset.from_tensor_slices((tf.constant(X),\n",
    "                                               tf.constant(y)))\n",
    "    data_batch = data.map(get_image_label).batch(BATCH_SIZE)\n",
    "    return data_batch\n",
    "  else:\n",
    "    data = tf.data.Dataset.from_tensor_slices((tf.constant(X),\n",
    "                                               tf.constant(y)))\n",
    "    data = data.shuffle(buffer_size=len(X))\n",
    "    data = data.map(get_image_label)\n",
    "    data_batch = data.batch(BATCH_SIZE)\n",
    "    return data_batch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "executionInfo": {
     "elapsed": 35,
     "status": "ok",
     "timestamp": 1637333243312,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "bg5cknExJgiM"
   },
   "outputs": [],
   "source": [
    "train_data = create_data_batches(X_train, y_train)\n",
    "val_data = create_data_batches(X_val, y_val, valid_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 33,
     "status": "ok",
     "timestamp": 1637333243313,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "eJrmeJRaLiPD",
    "outputId": "48e8ea62-0ed3-4c6f-82b7-39372b4984ad"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name=None),\n",
       "  TensorSpec(shape=(None, 120), dtype=tf.bool, name=None)),\n",
       " (TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name=None),\n",
       "  TensorSpec(shape=(None, 120), dtype=tf.bool, name=None)))"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.element_spec, val_data.element_spec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "executionInfo": {
     "elapsed": 28,
     "status": "ok",
     "timestamp": 1637333243313,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "aTASCKopLqwf"
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "def show_25_images(images, labels):\n",
    "  plt.figure(figsize=(10,10))\n",
    "  for i in range(25):\n",
    "    ax = plt.subplot(5, 5, i + 1)\n",
    "    plt.imshow(images[i])\n",
    "    plt.title(unique_breeds[labels[i].argmax()])\n",
    "    plt.axis('off')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "executionInfo": {
     "elapsed": 8482,
     "status": "ok",
     "timestamp": 1637333251769,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "FfXEOPXaRYTo"
   },
   "outputs": [],
   "source": [
    "train_images, train_labels = next(train_data.as_numpy_iterator())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 591
    },
    "executionInfo": {
     "elapsed": 3562,
     "status": "ok",
     "timestamp": 1637333255323,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "w8zXcmy9Ruhe",
    "outputId": "81862950-c6ac-4ba1-94b1-81d5c9c59ed0"
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 703592 characters]\n",
      "text/plain": [
       "<Figure size 720x720 with 25 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "show_25_images(train_images, train_labels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "executionInfo": {
     "elapsed": 23,
     "status": "ok",
     "timestamp": 1637333255326,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "NjFFMDzhSv58"
   },
   "outputs": [],
   "source": [
    "INPUT_SHAPE  = [None, IMG_SIZE, IMG_SIZE, 3]\n",
    "OUTPUT_SHAPE = len(unique_breeds)\n",
    "MODEL_URL    = 'https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "executionInfo": {
     "elapsed": 23,
     "status": "ok",
     "timestamp": 1637333255329,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "1EdnvukzN1Qv"
   },
   "outputs": [],
   "source": [
    "def create_model(input_shape=INPUT_SHAPE, \n",
    "                 ouput_shape=OUTPUT_SHAPE, \n",
    "                 model_url=MODEL_URL):\n",
    "  \n",
    "  model = tf.keras.Sequential([hub.KerasLayer(MODEL_URL),\n",
    "                               tf.keras.layers.Dense(units=OUTPUT_SHAPE,\n",
    "                                                     activation='softmax')])\n",
    "  model.compile(\n",
    "      loss=tf.keras.losses.CategoricalCrossentropy(),\n",
    "      optimizer=tf.keras.optimizers.Adam(),\n",
    "      metrics=[\"accuracy\"])\n",
    "  model.build(INPUT_SHAPE)\n",
    "  return model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 2935,
     "status": "ok",
     "timestamp": 1637333258243,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "1jCvjoZ_RJ03",
    "outputId": "5184cc08-8f32-4734-f9c4-11ae888e615b"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"sequential\"\n",
      "_________________________________________________________________\n",
      " Layer (type)                Output Shape              Param #   \n",
      "=================================================================\n",
      " keras_layer (KerasLayer)    (None, 1001)              5432713   \n",
      "                                                                 \n",
      " dense (Dense)               (None, 120)               120240    \n",
      "                                                                 \n",
      "=================================================================\n",
      "Total params: 5,552,953\n",
      "Trainable params: 120,240\n",
      "Non-trainable params: 5,432,713\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "model = create_model()\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "executionInfo": {
     "elapsed": 26,
     "status": "ok",
     "timestamp": 1637333258244,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "GkuvBIPFRN3S"
   },
   "outputs": [],
   "source": [
    "%load_ext tensorboard"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "executionInfo": {
     "elapsed": 25,
     "status": "ok",
     "timestamp": 1637333258245,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "iYXn_XGzmjlx"
   },
   "outputs": [],
   "source": [
    "import datetime\n",
    "def create_tensorboard_callback():\n",
    "  logdir = os.path.join('/content/drive/MyDrive/Dog_vision/logs',\n",
    "                        datetime.datetime.now().strftime(\"%Y%m%d-%H%M%S\"))\n",
    "  return tf.keras.callbacks.TensorBoard(logdir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "executionInfo": {
     "elapsed": 23,
     "status": "ok",
     "timestamp": 1637333258245,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "shUmva9RoJG3"
   },
   "outputs": [],
   "source": [
    "early_stopping = tf.keras.callbacks.EarlyStopping(monitor='val_accuracy',\n",
    "                                                  patience=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "executionInfo": {
     "elapsed": 19,
     "status": "ok",
     "timestamp": 1637333258246,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "RHLVLgclpGYV"
   },
   "outputs": [],
   "source": [
    " NUM_EPOCHS = 100 #@param {type:'slider', min:10, max:100, step:10}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 19,
     "status": "ok",
     "timestamp": 1637333258247,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "7s7ix8oTqkIR",
    "outputId": "db872dac-f6d2-486f-af07-8dfdb8fac612"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GPU\n"
     ]
    }
   ],
   "source": [
    "print('GPU') if tf.config.list_physical_devices(\"GPU\") else ('no gpu')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "executionInfo": {
     "elapsed": 498,
     "status": "ok",
     "timestamp": 1637333258733,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "vpE3bDifqtmK"
   },
   "outputs": [],
   "source": [
    "def train_model():\n",
    "   model = create_model()\n",
    "\n",
    "   tensorboard = create_tensorboard_callback()\n",
    "\n",
    "   model.fit(x=train_data,\n",
    "             epochs=NUM_EPOCHS,\n",
    "             validation_data=val_data,\n",
    "             validation_freq=1,\n",
    "             callbacks=[tensorboard, early_stopping])\n",
    "   return model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 399193,
     "status": "ok",
     "timestamp": 1637333657922,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "HFB2gzsvru_Q",
    "outputId": "9d8fe67e-e373-4ba3-b76f-2af2b227e9b3"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/100\n",
      "25/25 [==============================] - 277s 10s/step - loss: 4.5847 - accuracy: 0.0962 - val_loss: 3.3633 - val_accuracy: 0.2650\n",
      "Epoch 2/100\n",
      "25/25 [==============================] - 5s 192ms/step - loss: 1.6661 - accuracy: 0.6700 - val_loss: 2.1173 - val_accuracy: 0.4750\n",
      "Epoch 3/100\n",
      "25/25 [==============================] - 5s 193ms/step - loss: 0.5798 - accuracy: 0.9312 - val_loss: 1.6391 - val_accuracy: 0.6000\n",
      "Epoch 4/100\n",
      "25/25 [==============================] - 4s 176ms/step - loss: 0.2464 - accuracy: 0.9925 - val_loss: 1.4632 - val_accuracy: 0.6000\n",
      "Epoch 5/100\n",
      "25/25 [==============================] - 4s 175ms/step - loss: 0.1444 - accuracy: 0.9987 - val_loss: 1.3932 - val_accuracy: 0.6150\n",
      "Epoch 6/100\n",
      "25/25 [==============================] - 5s 194ms/step - loss: 0.0983 - accuracy: 1.0000 - val_loss: 1.3383 - val_accuracy: 0.6350\n",
      "Epoch 7/100\n",
      "25/25 [==============================] - 5s 190ms/step - loss: 0.0737 - accuracy: 1.0000 - val_loss: 1.3194 - val_accuracy: 0.6300\n",
      "Epoch 8/100\n",
      "25/25 [==============================] - 5s 192ms/step - loss: 0.0586 - accuracy: 1.0000 - val_loss: 1.2924 - val_accuracy: 0.6450\n",
      "Epoch 9/100\n",
      "25/25 [==============================] - 5s 193ms/step - loss: 0.0482 - accuracy: 1.0000 - val_loss: 1.2740 - val_accuracy: 0.6450\n",
      "Epoch 10/100\n",
      "25/25 [==============================] - 5s 190ms/step - loss: 0.0406 - accuracy: 1.0000 - val_loss: 1.2637 - val_accuracy: 0.6450\n",
      "Epoch 11/100\n",
      "25/25 [==============================] - 4s 175ms/step - loss: 0.0350 - accuracy: 1.0000 - val_loss: 1.2505 - val_accuracy: 0.6500\n",
      "Epoch 12/100\n",
      "25/25 [==============================] - 4s 174ms/step - loss: 0.0305 - accuracy: 1.0000 - val_loss: 1.2384 - val_accuracy: 0.6600\n",
      "Epoch 13/100\n",
      "25/25 [==============================] - 5s 191ms/step - loss: 0.0269 - accuracy: 1.0000 - val_loss: 1.2307 - val_accuracy: 0.6550\n",
      "Epoch 14/100\n",
      "25/25 [==============================] - 4s 177ms/step - loss: 0.0240 - accuracy: 1.0000 - val_loss: 1.2233 - val_accuracy: 0.6600\n",
      "Epoch 15/100\n",
      "25/25 [==============================] - 5s 192ms/step - loss: 0.0215 - accuracy: 1.0000 - val_loss: 1.2140 - val_accuracy: 0.6600\n"
     ]
    }
   ],
   "source": [
    "model = train_model()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 821
    },
    "executionInfo": {
     "elapsed": 5391,
     "status": "ok",
     "timestamp": 1637333663292,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "mOaZBCXSrz5X",
    "outputId": "81b44985-eb22-4601-ff0d-ac19428355da"
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "\n",
       "        (async () => {\n",
       "            const url = new URL(await google.colab.kernel.proxyPort(6006, {'cache': true}));\n",
       "            url.searchParams.set('tensorboardColab', 'true');\n",
       "            const iframe = document.createElement('iframe');\n",
       "            iframe.src = url;\n",
       "            iframe.setAttribute('width', '100%');\n",
       "            iframe.setAttribute('height', '800');\n",
       "            iframe.setAttribute('frameborder', 0);\n",
       "            document.body.appendChild(iframe);\n",
       "        })();\n",
       "    "
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%tensorboard --logdir drive/MyDrive/Dog_vision/logs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 1694,
     "status": "ok",
     "timestamp": 1637333664969,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "c_Xs4abt4aWE",
    "outputId": "c9b4712c-1eff-414e-cdaf-5e0c92ac274c"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7/7 [==============================] - 2s 150ms/step\n"
     ]
    }
   ],
   "source": [
    "predictions = model.predict(val_data, verbose=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 38,
     "status": "ok",
     "timestamp": 1637333664974,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "T7rVxmMG4t4i",
    "outputId": "9aa99f22-73da-47a5-fee0-f215b2307698"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2.37517506e-05, 1.08347484e-03, 1.33848470e-03, 7.62868847e-04,\n",
       "       3.23438071e-05, 1.09674787e-04, 4.51313611e-03, 6.48410351e-04,\n",
       "       1.52265675e-05, 7.60145194e-05, 2.71843486e-02, 3.59222649e-05,\n",
       "       1.86960933e-05, 8.77837738e-05, 1.39074962e-06, 7.51742118e-05,\n",
       "       4.33197152e-03, 2.80195451e-03, 2.34106134e-04, 7.29767498e-06,\n",
       "       7.60466673e-06, 5.33435741e-05, 4.46059021e-05, 5.95351121e-05,\n",
       "       2.59856461e-04, 1.79010908e-06, 5.69148688e-05, 1.52366294e-03,\n",
       "       1.11840125e-02, 2.30224920e-03, 1.32070056e-06, 1.32250480e-05,\n",
       "       5.22807422e-05, 2.03903411e-02, 1.44456635e-05, 3.02676170e-04,\n",
       "       8.44195529e-05, 1.48276828e-04, 1.66250087e-04, 4.16365743e-04,\n",
       "       5.23248920e-04, 1.28824642e-04, 3.78139055e-04, 9.13480380e-06,\n",
       "       1.56121227e-04, 1.87315527e-05, 1.06885171e-04, 2.91426363e-03,\n",
       "       3.85248532e-05, 2.13955755e-05, 1.67273738e-05, 5.45230054e-04,\n",
       "       2.68229887e-05, 3.33514217e-05, 4.44465804e-05, 2.11968762e-03,\n",
       "       5.61466150e-04, 7.10345432e-03, 1.39436788e-05, 1.11859255e-02,\n",
       "       6.38140142e-02, 1.91026211e-05, 4.63897413e-05, 4.65230114e-04,\n",
       "       4.11591842e-04, 1.94534168e-05, 3.25458287e-03, 7.97001030e-06,\n",
       "       1.10645255e-03, 5.24093139e-06, 1.46464241e-04, 5.29821124e-03,\n",
       "       3.75195450e-05, 3.03164677e-04, 7.53838522e-03, 8.83177490e-05,\n",
       "       8.16858592e-05, 2.55880896e-02, 1.90102719e-06, 2.12757313e-03,\n",
       "       1.27599912e-03, 3.55687916e-05, 1.96474968e-04, 6.72326074e-04,\n",
       "       3.63617910e-05, 8.80562766e-07, 3.99641503e-05, 1.95548982e-05,\n",
       "       5.77649371e-06, 6.68756780e-04, 1.60901400e-04, 2.38240045e-05,\n",
       "       2.58952641e-05, 1.28580341e-02, 2.13178337e-05, 3.49328446e-04,\n",
       "       1.42246819e-04, 6.01569891e-01, 1.80973788e-04, 1.10460373e-04,\n",
       "       2.72650650e-04, 3.78378958e-04, 1.56020746e-04, 9.53856332e-04,\n",
       "       1.03792571e-03, 1.21827361e-04, 2.83773802e-03, 1.13242113e-05,\n",
       "       1.38886153e-05, 1.93870655e-04, 3.02577464e-05, 1.25211885e-03,\n",
       "       1.55413384e-03, 1.17568423e-04, 6.16629550e-05, 3.26696248e-03,\n",
       "       2.40357965e-03, 8.06917474e-02, 6.90231621e-02, 4.53920307e-04],\n",
       "      dtype=float32)"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predictions[42]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 36
    },
    "executionInfo": {
     "elapsed": 26,
     "status": "ok",
     "timestamp": 1637333664974,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "r8ZvXk6BiEc8",
    "outputId": "a90ff9fc-f27a-44d3-9636-2ebad6a2f811"
   },
   "outputs": [
    {
     "data": {
      "application/vnd.google.colaboratory.intrinsic+json": {
       "type": "string"
      },
      "text/plain": [
       "'toy_terrier'"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unique_breeds[111]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 36
    },
    "executionInfo": {
     "elapsed": 25,
     "status": "ok",
     "timestamp": 1637333664976,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "OC7yn05DiOZT",
    "outputId": "c9b76021-c7c2-4369-811e-73d4b0f8adb0"
   },
   "outputs": [
    {
     "data": {
      "application/vnd.google.colaboratory.intrinsic+json": {
       "type": "string"
      },
      "text/plain": [
       "'siberian_husky'"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def get_pred_label(prediction_probabilities):\n",
    "  return unique_breeds[np.argmax(prediction_probabilities)]\n",
    "\n",
    "pred_label = get_pred_label(predictions[81])\n",
    "pred_label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "executionInfo": {
     "elapsed": 24,
     "status": "ok",
     "timestamp": 1637333664978,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "tqyCtCvEj-xZ"
   },
   "outputs": [],
   "source": [
    "def unbatchify(data):\n",
    "  images = []\n",
    "  labels = []\n",
    "  for image,label in data.unbatch().as_numpy_iterator():\n",
    "    images.append(image)\n",
    "    labels.append(unique_breeds[np.argmax(label)])\n",
    "  return images, labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "executionInfo": {
     "elapsed": 1852,
     "status": "ok",
     "timestamp": 1637333666808,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "svQo38BNlP_Y"
   },
   "outputs": [],
   "source": [
    "val_images, val_labels = unbatchify(val_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "executionInfo": {
     "elapsed": 38,
     "status": "ok",
     "timestamp": 1637333666810,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "9BXUHRBymKE5"
   },
   "outputs": [],
   "source": [
    "def plot_pred(prediction_probabilities, labels, images, n=1):\n",
    "  pred_prob, true_label, image = prediction_probabilities[n], labels[n], images[n]\n",
    "\n",
    "  pred_label = get_pred_label(pred_prob)\n",
    "  plt.imshow(image)\n",
    "  plt.xticks([])\n",
    "  plt.yticks([])\n",
    "  if pred_label == true_label:\n",
    "    color = 'green'\n",
    "  else: \n",
    "    color = 'red'\n",
    "  plt.title(\"Expected: {}\\n Certainty:{:2.0f}%\\n Actual: {}\".format(pred_label,\n",
    "                                   np.max(pred_prob)*100,\n",
    "                                   true_label),\n",
    "            color=color)\n",
    "  \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 298
    },
    "executionInfo": {
     "elapsed": 38,
     "status": "ok",
     "timestamp": 1637333666812,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "qAb5FyqbR7UA",
    "outputId": "5421e0c7-0a25-4324-b560-5734059101e9"
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 91976 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_pred(prediction_probabilities=predictions,\n",
    "           labels=val_labels,\n",
    "           images=val_images,\n",
    "           n=199)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "executionInfo": {
     "elapsed": 30,
     "status": "ok",
     "timestamp": 1637333666813,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "7RcFKvZsWmY9"
   },
   "outputs": [],
   "source": [
    "def plot_pred_conf(prediction_probabilities, labels, n=1):\n",
    "  \"\"\"\n",
    "  Plots the top 10 highest prediction confidences along with\n",
    "  the truth label for sample n.\n",
    "  \"\"\"\n",
    "  pred_prob, true_label = prediction_probabilities[n], labels[n]\n",
    "\n",
    "  # Get the predicted label\n",
    "  pred_label = get_pred_label(pred_prob)\n",
    "\n",
    "  # Find the top 10 prediction confidence indexes\n",
    "  top_10_pred_indexes = pred_prob.argsort()[-10:][::-1]\n",
    "  # Find the top 10 prediction confidence values\n",
    "  top_10_pred_values = pred_prob[top_10_pred_indexes]\n",
    "  # Find the top 10 prediction labels\n",
    "  top_10_pred_labels = unique_breeds[top_10_pred_indexes]\n",
    "\n",
    "  # Setup plot\n",
    "  top_plot = plt.bar(np.arange(len(top_10_pred_labels)), \n",
    "                     top_10_pred_values, \n",
    "                     color=\"grey\")\n",
    "  plt.xticks(np.arange(len(top_10_pred_labels)),\n",
    "             labels=top_10_pred_labels,\n",
    "             rotation=\"vertical\")\n",
    "\n",
    "  # Change color of true label\n",
    "  if np.isin(true_label, top_10_pred_labels):\n",
    "    top_plot[np.argmax(top_10_pred_labels == true_label)].set_color(\"green\")\n",
    "  else:\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 401
    },
    "executionInfo": {
     "elapsed": 30,
     "status": "ok",
     "timestamp": 1637333666814,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "LFz2cFsDR_9T",
    "outputId": "832cfa9b-3349-48c3-fb20-85212c6b32b4"
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 15964 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_pred_conf(prediction_probabilities=predictions, labels=labels,n=9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 562
    },
    "executionInfo": {
     "elapsed": 4438,
     "status": "ok",
     "timestamp": 1637333671225,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "D820oC3c9SPU",
    "outputId": "9a534f65-048c-4269-a326-7a45ddcd2aa0"
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 992476 characters]\n",
      "text/plain": [
       "<Figure size 1440x1080 with 12 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "i_multiplier = 0\n",
    "num_rows = 3\n",
    "num_cols = 2\n",
    "num_images = num_rows * num_cols\n",
    "plt.figure(figsize=(10 * num_cols, 5 * num_rows))\n",
    "for i in range(num_images):\n",
    "  plt.subplot(num_rows, 2*num_cols, 2*i+1)\n",
    "  plot_pred(prediction_probabilities=predictions,\n",
    "            labels=val_labels,\n",
    "            images=val_images,\n",
    "            n=i+i_multiplier)\n",
    "  plt.subplot(num_rows, 2 * num_cols, 2 * i +2)\n",
    "  plot_pred_conf(prediction_probabilities=predictions,\n",
    "                 labels=val_labels,\n",
    "                 n=i+i_multiplier)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "executionInfo": {
     "elapsed": 14,
     "status": "ok",
     "timestamp": 1637333671227,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "Odhah_pM_NED"
   },
   "outputs": [],
   "source": [
    "def save_model(model, suffix=None):\n",
    "  modeldir = os.path.join('/content/drive/MyDrive/Dog_vision/models',\n",
    "                          datetime.datetime.now().strftime(\"%Y%m%d-%H%M%s\"))\n",
    "  model_path = modeldir + '-' + suffix + '.h5' \n",
    "  model.save(model_path)\n",
    "  return model_path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "executionInfo": {
     "elapsed": 13,
     "status": "ok",
     "timestamp": 1637333671228,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "lMxafewiDbNp"
   },
   "outputs": [],
   "source": [
    "def load_model(model_path):\n",
    "  model = tf.keras.models.load_model(model_path,\n",
    "                                     custom_objects={'KerasLayer':hub.KerasLayer})\n",
    "  return model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 54
    },
    "executionInfo": {
     "elapsed": 494,
     "status": "ok",
     "timestamp": 1637333671710,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "bma1FcS2EDaX",
    "outputId": "d0711ffb-cc05-4fa3-f1e4-5a237708654b"
   },
   "outputs": [
    {
     "data": {
      "application/vnd.google.colaboratory.intrinsic+json": {
       "type": "string"
      },
      "text/plain": [
       "'/content/drive/MyDrive/Dog_vision/models/20211119-14541637333668-1000-images-mobilenetv2-Adam.h5'"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "save_model(model, suffix='1000-images-mobilenetv2-Adam')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "executionInfo": {
     "elapsed": 3987,
     "status": "ok",
     "timestamp": 1637333675684,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "UjDbIsU1ESBJ"
   },
   "outputs": [],
   "source": [
    "loaded_1000_image_model = load_model('/content/drive/MyDrive/Dog_vision/models/20211119-12011637323282-1000-images-mobilenetv2-Adam.h5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 2178,
     "status": "ok",
     "timestamp": 1637333677855,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "D1jNItA8FDjA",
    "outputId": "b8ae8176-3597-4ae6-862d-87dd7ef0776e"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7/7 [==============================] - 2s 120ms/step - loss: 0.2164 - accuracy: 0.9550\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[0.21640217304229736, 0.9549999833106995]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "loaded_1000_image_model.evaluate(val_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "executionInfo": {
     "elapsed": 26,
     "status": "ok",
     "timestamp": 1637333677856,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "FZJvg0f9GN3A"
   },
   "outputs": [],
   "source": [
    "full_data = create_data_batches(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 23,
     "status": "ok",
     "timestamp": 1637333677858,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "yXQ0AIi5HJSJ",
    "outputId": "04ebb8cf-bf1f-43e5-db9c-c15af3fb69cd"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<BatchDataset shapes: ((None, 224, 224, 3), (None, 120)), types: (tf.float32, tf.bool)>"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "full_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "executionInfo": {
     "elapsed": 3200,
     "status": "ok",
     "timestamp": 1637333681049,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "Gsg5Tj-kHLzB"
   },
   "outputs": [],
   "source": [
    "full_model = create_model(full_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "executionInfo": {
     "elapsed": 14,
     "status": "ok",
     "timestamp": 1637333681051,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "pFqiWNipHizT"
   },
   "outputs": [],
   "source": [
    "full_model_tensorboard = create_tensorboard_callback()\n",
    "full_model_early_stopping = tf.keras.callbacks.EarlyStopping(monitor='accuracy',\n",
    "                                                            patience=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 3515963,
     "status": "ok",
     "timestamp": 1637337197002,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "IjI2Ps6wIZ1W",
    "outputId": "8347460c-d5ae-4d93-e525-9801d4422d3e"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/100\n",
      "320/320 [==============================] - 2104s 7s/step - loss: 1.3447 - accuracy: 0.6702\n",
      "Epoch 2/100\n",
      "320/320 [==============================] - 51s 158ms/step - loss: 0.3978 - accuracy: 0.8831\n",
      "Epoch 3/100\n",
      "320/320 [==============================] - 53s 167ms/step - loss: 0.2371 - accuracy: 0.9356\n",
      "Epoch 4/100\n",
      "320/320 [==============================] - 54s 167ms/step - loss: 0.1548 - accuracy: 0.9640\n",
      "Epoch 5/100\n",
      "320/320 [==============================] - 53s 167ms/step - loss: 0.1055 - accuracy: 0.9779\n",
      "Epoch 6/100\n",
      "320/320 [==============================] - 53s 164ms/step - loss: 0.0769 - accuracy: 0.9856\n",
      "Epoch 7/100\n",
      "320/320 [==============================] - 53s 165ms/step - loss: 0.0585 - accuracy: 0.9920\n",
      "Epoch 8/100\n",
      "320/320 [==============================] - 53s 165ms/step - loss: 0.0466 - accuracy: 0.9945\n",
      "Epoch 9/100\n",
      "320/320 [==============================] - 53s 164ms/step - loss: 0.0377 - accuracy: 0.9959\n",
      "Epoch 10/100\n",
      "320/320 [==============================] - 54s 167ms/step - loss: 0.0313 - accuracy: 0.9974\n",
      "Epoch 11/100\n",
      "320/320 [==============================] - 53s 165ms/step - loss: 0.0261 - accuracy: 0.9978\n",
      "Epoch 12/100\n",
      "320/320 [==============================] - 53s 166ms/step - loss: 0.0227 - accuracy: 0.9980\n",
      "Epoch 13/100\n",
      "320/320 [==============================] - 51s 160ms/step - loss: 0.0203 - accuracy: 0.9984\n",
      "Epoch 14/100\n",
      "320/320 [==============================] - 52s 161ms/step - loss: 0.0173 - accuracy: 0.9989\n",
      "Epoch 15/100\n",
      "320/320 [==============================] - 54s 169ms/step - loss: 0.0153 - accuracy: 0.9988\n",
      "Epoch 16/100\n",
      "320/320 [==============================] - 54s 168ms/step - loss: 0.0134 - accuracy: 0.9991\n",
      "Epoch 17/100\n",
      "320/320 [==============================] - 54s 168ms/step - loss: 0.0146 - accuracy: 0.9983\n",
      "Epoch 18/100\n",
      "320/320 [==============================] - 53s 167ms/step - loss: 0.0125 - accuracy: 0.9985\n",
      "Epoch 19/100\n",
      "320/320 [==============================] - 55s 171ms/step - loss: 0.0117 - accuracy: 0.9987\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x7f1a18b20b50>"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"full_model.fit(x=full_data,\n",
    "               epochs=NUM_EPOCHS,\n",
    "               callbacks=[full_model_early_stopping,\n",
    "                          full_model_tensorboard])\n",
    "                          \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 54
    },
    "executionInfo": {
     "elapsed": 681,
     "status": "ok",
     "timestamp": 1637337197672,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "0BacILahL2hu",
    "outputId": "878cbd6c-d20f-4453-b1aa-f73164164fe8"
   },
   "outputs": [
    {
     "data": {
      "application/vnd.google.colaboratory.intrinsic+json": {
       "type": "string"
      },
      "text/plain": [
       "'/content/drive/MyDrive/Dog_vision/models/20211119-15531637337196-full-image-set-mobilnetv2-Adam.h5'"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#save_model(full_model, suffix='full-image-set-mobilnetv2-Adam')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 301
    },
    "executionInfo": {
     "elapsed": 43076,
     "status": "error",
     "timestamp": 1637337516056,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "Am1Rs7HGMBtR",
    "outputId": "547cdae5-c9b0-4de6-f010-830c7677ba0e"
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "ignored",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-72-5d1ea2f4c2a4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mtest_path\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'drive/MyDrive/Dog_vision/test/'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mtest_filenames\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mtest_path\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mfnane\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mfname\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlistdir\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtest_path\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      3\u001b[0m \u001b[0mtest_filenames\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-72-5d1ea2f4c2a4>\u001b[0m in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mtest_path\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'drive/MyDrive/Dog_vision/test/'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mtest_filenames\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mtest_path\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mfnane\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mfname\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlistdir\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtest_path\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      3\u001b[0m \u001b[0mtest_filenames\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'fnane' is not defined"
     ]
    }
   ],
   "source": [
    "test_path = 'drive/MyDrive/Dog_vision/test/'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 366,
     "status": "ok",
     "timestamp": 1637337535113,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "Var_8QOH6rWL",
    "outputId": "69126b7c-1ac7-421f-d67b-dc72856485c8"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['drive/MyDrive/Dog_vision/test/e5ded7a736b3336729463af8d74a09c9.jpg',\n",
       " 'drive/MyDrive/Dog_vision/test/e6ed62f411426a4f7e26e6ccdbaf7ecc.jpg',\n",
       " 'drive/MyDrive/Dog_vision/test/e2faaf5e760a6189d0980e6355864b4c.jpg',\n",
       " 'drive/MyDrive/Dog_vision/test/dcc047e682db75bbcebdec2288192f1d.jpg',\n",
       " 'drive/MyDrive/Dog_vision/test/dd2228d2fbb3ddc8fb350106c2d989ef.jpg',\n",
       " 'drive/MyDrive/Dog_vision/test/def9a16cb97a7cdd10d6465d642f6bf4.jpg',\n",
       " 'drive/MyDrive/Dog_vision/test/de4223b8c5ca7b80d34d1cd2b5e62351.jpg',\n",
       " 'drive/MyDrive/Dog_vision/test/e6e1e02b07347a522f96eba87d29a5c0.jpg',\n",
       " 'drive/MyDrive/Dog_vision/test/dcb9aeaf9f1a5c11e95509376d8788ca.jpg',\n",
       " 'drive/MyDrive/Dog_vision/test/dd3eb4338145e614d325a917a35e5a1e.jpg']"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_filenames = [test_path + fname for fname in os.listdir(test_path)]\n",
    "test_filenames[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 416,
     "status": "ok",
     "timestamp": 1637337552594,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "6EPKCD_r7A9W",
    "outputId": "d3a90416-8779-45b4-9fbe-56eede6d08ee"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10358"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(test_filenames)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {
    "executionInfo": {
     "elapsed": 566,
     "status": "ok",
     "timestamp": 1637337661304,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "bz9LY2RS7FJ8"
   },
   "outputs": [],
   "source": [
    "test_data = create_data_batches(test_filenames, test_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 364,
     "status": "ok",
     "timestamp": 1637337678243,
     "user": {
      "displayName": "Андреан Грудев",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
      "userId": "07665041226487960419"
     },
     "user_tz": -120
    },
    "id": "WBA7q25b7fnN",
    "outputId": "b4058bf6-032b-475b-c203-27db1608ce46"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<BatchDataset shapes: (None, 224, 224, 3), types: tf.float32>"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "20vcZ4a77j4K"
   },
   "outputs": [],
   "source": [
    "test_predictions = loaded_full_model.predict(test_data,\n",
    "                                             vebose=1)"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "authorship_tag": "ABX9TyP7eq2MgN7ESkpkNT/YwTeV",
   "collapsed_sections": [],
   "mount_file_id": "1FC-MXvsOgfzQ9QG_v5DGAN_drx649q-p",
   "name": "Dog vision.ipynb",
   "provenance": []
  },
  "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.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
