From 7d8be32ba84af4cacf7ffd714b2f702b683bbade Mon Sep 17 00:00:00 2001 From: scott Date: Mon, 3 Jan 2022 13:32:42 -0700 Subject: [PATCH] commit before checkout 428e0379efc3cff3f85154e42ed544a5f982ade3 for ref --- Shoe Classifier-Copy1.ipynb | 471 --- Shoe Classifier_InceptionResNetV2.ipynb | 2787 +++++++++++++++++ Shoe Classifier_VGG16.ipynb | 529 ++++ ...ifier.ipynb => Shoe Classifier_VGG19.ipynb | 386 ++- Shoe Classifier_Xception.ipynb | 857 +++++ ebay_api.py | 91 +- 6 files changed, 4418 insertions(+), 703 deletions(-) delete mode 100644 Shoe Classifier-Copy1.ipynb create mode 100644 Shoe Classifier_InceptionResNetV2.ipynb create mode 100644 Shoe Classifier_VGG16.ipynb rename Shoe Classifier.ipynb => Shoe Classifier_VGG19.ipynb (66%) create mode 100644 Shoe Classifier_Xception.ipynb diff --git a/Shoe Classifier-Copy1.ipynb b/Shoe Classifier-Copy1.ipynb deleted file mode 100644 index 41c374f..0000000 --- a/Shoe Classifier-Copy1.ipynb +++ /dev/null @@ -1,471 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "572dc7fb", - "metadata": {}, - "outputs": [], - "source": [ - "from matplotlib import pyplot as plt\n", - "from matplotlib.image import imread\n", - "import pandas as pd\n", - "from collections import Counter\n", - "import json\n", - "import os\n", - "import re\n", - "import tempfile\n", - "import numpy as np\n", - "from os.path import exists\n", - "from imblearn.under_sampling import RandomUnderSampler\n", - "from PIL import ImageFile\n", - "import sklearn as sk\n", - "from sklearn.model_selection import train_test_split, StratifiedShuffleSplit\n", - "import tensorflow as tf\n", - "import tensorflow.keras\n", - "from tensorflow.keras.preprocessing.image import ImageDataGenerator\n", - "from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dense, Dropout, Flatten, Activation\n", - "from tensorflow.keras.models import Sequential\n", - "from tensorflow.keras.optimizers import Adam\n", - "# custom modules\n", - "import image_faults\n", - "\n", - "ImageFile.LOAD_TRUNCATED_IMAGES = True" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "def add_regularization(model, regularizer=tf.keras.regularizers.l2(0.0001)):\n", - "\n", - " if not isinstance(regularizer, tf.keras.regularizers.Regularizer):\n", - " print(\"Regularizer must be a subclass of tf.keras.regularizers.Regularizer\")\n", - " return model\n", - "\n", - " for layer in model.layers:\n", - " for attr in ['kernel_regularizer']:\n", - " if hasattr(layer, attr):\n", - " setattr(layer, attr, regularizer)\n", - "\n", - " # When we change the layers attributes, the change only happens in the model config file\n", - " model_json = model.to_json()\n", - "\n", - " # Save the weights before reloading the model.\n", - " tmp_weights_path = os.path.join(tempfile.gettempdir(), 'tmp_weights.h5')\n", - " model.save_weights(tmp_weights_path)\n", - "\n", - " # load the model from the config\n", - " model = tf.keras.models.model_from_json(model_json)\n", - " \n", - " # Reload the model weights\n", - " model.load_weights(tmp_weights_path, by_name=True)\n", - " return model" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "a5c72863", - "metadata": {}, - "outputs": [], - "source": [ - "# image_faults.faulty_images() # removes faulty images\n", - "df = pd.read_csv('expanded_class.csv', index_col=[0], low_memory=False)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "1057a442", - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{source:target} dictionary created @ /tf/training_images\n" - ] - } - ], - "source": [ - "def dict_pics():\n", - " target_dir = os.getcwd() + os.sep + \"training_images\"\n", - " with open('temp_pics_source_list.txt') as f:\n", - " temp_pics_source_list = json.load(f)\n", - " dict_pics = {k:target_dir + os.sep + re.search(r'[^/]+(?=/\\$_|.jpg)', k, re.IGNORECASE).group() + '.jpg' for k in temp_pics_source_list}\n", - " print(\"{source:target} dictionary created @ \" + target_dir)\n", - " return dict_pics\n", - "\n", - "dict_pics = dict_pics()\n", - "blah = pd.Series(df.PictureURL)\n", - "df = df.drop(labels=['PictureURL'], axis=1)\n", - "blah = blah.apply(lambda x: dict_pics[x])\n", - "df = pd.concat([blah, df],axis=1)\n", - "df = df.groupby('PrimaryCategoryID').filter(lambda x: len(x)>25) # removes cat outliers\n", - "# removes non-existent image paths" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "7a6146e6", - "metadata": {}, - "outputs": [], - "source": [ - "df['PrimaryCategoryID'] = df['PrimaryCategoryID'].astype(str) # pandas thinks ids are ints\n", - "\n", - "df=df.sample(frac=1)" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "undersample = RandomUnderSampler(sampling_strategy='auto')\n", - "train, y_under = undersample.fit_resample(df, df['PrimaryCategoryID'])\n", - "# print(Counter(train['PrimaryCategoryID']))" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "506aa5cf", - "metadata": {}, - "outputs": [], - "source": [ - "train, test = train_test_split(train, test_size=0.1, random_state=42)\n", - "# stratify=train['PrimaryCategoryID']\n", - "# train['PrimaryCategoryID'].value_counts()" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "4d72eb90", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Found 5110 validated image filenames belonging to 13 classes.\n", - "Found 1277 validated image filenames belonging to 13 classes.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/usr/local/lib/python3.8/dist-packages/keras_preprocessing/image/dataframe_iterator.py:279: UserWarning: Found 1 invalid image filename(s) in x_col=\"PictureURL\". These filename(s) will be ignored.\n", - " warnings.warn(\n" - ] - } - ], - "source": [ - "datagen = ImageDataGenerator(rescale=1./255., \n", - " validation_split=.2,\n", - " #samplewise_std_normalization=True,\n", - " #horizontal_flip= True,\n", - " #vertical_flip= True,\n", - " #width_shift_range= 0.2,\n", - " #height_shift_range= 0.2,\n", - " #rotation_range= 90,\n", - " preprocessing_function=tf.keras.applications.vgg16.preprocess_input)\n", - "train_generator=datagen.flow_from_dataframe(\n", - " dataframe=train[:len(train)],\n", - " directory='./training_images',\n", - " x_col='PictureURL',\n", - " y_col='PrimaryCategoryID',\n", - " batch_size=32,\n", - " seed=42,\n", - " shuffle=True,\n", - " target_size=(224,224),\n", - " subset='training'\n", - " )\n", - "validation_generator=datagen.flow_from_dataframe(\n", - " dataframe=train[:len(train)], # is using train right?\n", - " directory='./training_images',\n", - " x_col='PictureURL',\n", - " y_col='PrimaryCategoryID',\n", - " batch_size=32,\n", - " seed=42,\n", - " shuffle=True,\n", - " target_size=(224,224),\n", - " subset='validation'\n", - " )" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "7b70f37f", - "metadata": {}, - "outputs": [], - "source": [ - "imgs, labels = next(train_generator)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "1ed54bf5", - "metadata": {}, - "outputs": [], - "source": [ - "def plotImages(images_arr):\n", - " fig, axes = plt.subplots(1, 10, figsize=(20,20))\n", - " axes = axes.flatten()\n", - " for img, ax in zip( images_arr, axes):\n", - " ax.imshow(img)\n", - " ax.axis('off')\n", - " plt.tight_layout()\n", - " plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "85934565", - "metadata": {}, - "outputs": [], - "source": [ - "#plotImages(imgs)\n", - "#print(labels)" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "6322bcad", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n" - ] - } - ], - "source": [ - "physical_devices = tf.config.list_physical_devices('GPU')\n", - "print(len(physical_devices))\n", - "tf.config.experimental.set_memory_growth(physical_devices[0], True)" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "07fd25c6", - "metadata": {}, - "outputs": [], - "source": [ - "# see https://www.kaggle.com/dmitrypukhov/cnn-with-imagedatagenerator-flow-from-dataframe for train/test/val split \n", - "# example\n", - "\n", - "# may need to either create a test dataset from the original dataset or just download a new one" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "b31af79e", - "metadata": {}, - "outputs": [], - "source": [ - "vgg19_model = tf.keras.applications.vgg16.VGG16(weights='imagenet')\n" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "fe06f2bf", - "metadata": {}, - "outputs": [], - "source": [ - "model = Sequential()\n", - "for layer in vgg19_model.layers[:-1]:\n", - " model.add(layer)" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "id": "7d3cc82c", - "metadata": {}, - "outputs": [], - "source": [ - "for layer in model.layers:\n", - " layer.trainable = True" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "id": "ea620129", - "metadata": {}, - "outputs": [], - "source": [ - "#model.add(Dropout(.5))\n", - "#model.add(Dense(64, activation='softmax'))\n", - "# model.add(Dropout(.25))\n", - "model.add(Dense(units=13, activation='softmax'))" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "id": "c774d787", - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "model = add_regularization(model)\n", - "#model.summary()\n" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "id": "fd5d1246", - "metadata": {}, - "outputs": [], - "source": [ - "model.compile(optimizer=Adam(learning_rate=1e-5), loss='categorical_crossentropy',\n", - " metrics=['accuracy'])\n", - "# sparse_categorical_crossentropy" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "id": "9cd2ba27", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Epoch 1/30\n", - "160/160 [==============================] - 59s 360ms/step - loss: 2.7627 - accuracy: 0.1125 - val_loss: 2.7406 - val_accuracy: 0.1237\n", - "Epoch 2/30\n", - "160/160 [==============================] - 56s 351ms/step - loss: 2.7151 - accuracy: 0.1399 - val_loss: 2.7219 - val_accuracy: 0.1402\n", - "Epoch 3/30\n", - "160/160 [==============================] - 56s 351ms/step - loss: 2.6875 - accuracy: 0.1566 - val_loss: 2.6897 - val_accuracy: 0.1629\n", - "Epoch 4/30\n", - "160/160 [==============================] - 56s 353ms/step - loss: 2.6820 - accuracy: 0.1726 - val_loss: 2.6867 - val_accuracy: 0.1684\n", - "Epoch 5/30\n", - "160/160 [==============================] - 57s 355ms/step - loss: 2.6579 - accuracy: 0.1771 - val_loss: 2.6919 - val_accuracy: 0.1558\n", - "Epoch 6/30\n", - "160/160 [==============================] - 56s 353ms/step - loss: 2.6361 - accuracy: 0.1994 - val_loss: 2.6813 - val_accuracy: 0.1832\n", - "Epoch 7/30\n", - "160/160 [==============================] - 56s 352ms/step - loss: 2.6196 - accuracy: 0.2084 - val_loss: 2.6592 - val_accuracy: 0.1950\n", - "Epoch 8/30\n", - "160/160 [==============================] - 57s 353ms/step - loss: 2.6031 - accuracy: 0.2172 - val_loss: 2.6693 - val_accuracy: 0.1770\n", - "Epoch 9/30\n", - "160/160 [==============================] - 57s 355ms/step - loss: 2.5878 - accuracy: 0.2274 - val_loss: 2.6543 - val_accuracy: 0.2091\n", - "Epoch 10/30\n", - "160/160 [==============================] - 56s 350ms/step - loss: 2.5687 - accuracy: 0.2450 - val_loss: 2.6551 - val_accuracy: 0.1942\n", - "Epoch 11/30\n", - "160/160 [==============================] - 57s 354ms/step - loss: 2.5543 - accuracy: 0.2568 - val_loss: 2.6591 - val_accuracy: 0.2020\n", - "Epoch 12/30\n", - "160/160 [==============================] - 56s 352ms/step - loss: 2.5403 - accuracy: 0.2685 - val_loss: 2.6513 - val_accuracy: 0.1973\n", - "Epoch 13/30\n", - "160/160 [==============================] - 56s 352ms/step - loss: 2.5311 - accuracy: 0.2695 - val_loss: 2.6445 - val_accuracy: 0.2060\n", - "Epoch 14/30\n", - "160/160 [==============================] - 56s 351ms/step - loss: 2.5217 - accuracy: 0.2775 - val_loss: 2.6476 - val_accuracy: 0.2044\n", - "Epoch 15/30\n", - "160/160 [==============================] - 56s 351ms/step - loss: 2.5147 - accuracy: 0.2830 - val_loss: 2.6419 - val_accuracy: 0.2036\n", - "Epoch 16/30\n", - "160/160 [==============================] - 56s 351ms/step - loss: 2.5084 - accuracy: 0.2851 - val_loss: 2.6396 - val_accuracy: 0.2200\n", - "Epoch 17/30\n", - "160/160 [==============================] - 56s 348ms/step - loss: 2.5025 - accuracy: 0.2879 - val_loss: 2.6463 - val_accuracy: 0.2302\n", - "Epoch 18/30\n", - "160/160 [==============================] - 56s 350ms/step - loss: 2.4971 - accuracy: 0.2918 - val_loss: 2.6346 - val_accuracy: 0.2208\n", - "Epoch 19/30\n", - "160/160 [==============================] - 56s 353ms/step - loss: 2.4924 - accuracy: 0.2967 - val_loss: 2.6366 - val_accuracy: 0.2208\n", - "Epoch 20/30\n", - "160/160 [==============================] - 57s 354ms/step - loss: 2.4882 - accuracy: 0.2988 - val_loss: 2.6317 - val_accuracy: 0.2271\n", - "Epoch 21/30\n", - "160/160 [==============================] - 56s 349ms/step - loss: 2.4854 - accuracy: 0.3004 - val_loss: 2.6431 - val_accuracy: 0.2240\n", - "Epoch 22/30\n", - "160/160 [==============================] - 56s 352ms/step - loss: 2.4784 - accuracy: 0.3068 - val_loss: 2.6345 - val_accuracy: 0.2114\n", - "Epoch 23/30\n", - "160/160 [==============================] - 57s 354ms/step - loss: 2.4722 - accuracy: 0.3106 - val_loss: 2.6276 - val_accuracy: 0.2294\n", - "Epoch 24/30\n", - "160/160 [==============================] - 57s 354ms/step - loss: 2.4687 - accuracy: 0.3100 - val_loss: 2.6383 - val_accuracy: 0.2177\n", - "Epoch 25/30\n", - "160/160 [==============================] - 57s 354ms/step - loss: 2.4649 - accuracy: 0.3108 - val_loss: 2.6322 - val_accuracy: 0.2122\n", - "Epoch 26/30\n", - "160/160 [==============================] - 57s 354ms/step - loss: 2.4644 - accuracy: 0.3141 - val_loss: 2.6243 - val_accuracy: 0.2247\n", - "Epoch 27/30\n", - "160/160 [==============================] - 56s 352ms/step - loss: 2.4599 - accuracy: 0.3188 - val_loss: 2.6332 - val_accuracy: 0.2138\n", - "Epoch 28/30\n", - "160/160 [==============================] - 57s 353ms/step - loss: 2.4550 - accuracy: 0.3229 - val_loss: 2.6287 - val_accuracy: 0.2232\n", - "Epoch 29/30\n", - "160/160 [==============================] - 57s 354ms/step - loss: 2.4502 - accuracy: 0.3217 - val_loss: 2.6216 - val_accuracy: 0.2287\n", - "Epoch 30/30\n", - "160/160 [==============================] - 56s 351ms/step - loss: 2.4506 - accuracy: 0.3190 - val_loss: 2.6329 - val_accuracy: 0.1793\n" - ] - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "model.fit(x=train_generator,\n", - " steps_per_epoch=len(train_generator),\n", - " validation_data=validation_generator,\n", - " validation_steps=len(validation_generator),\n", - " epochs=30,\n", - " verbose=1)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "63f791af", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.10" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/Shoe Classifier_InceptionResNetV2.ipynb b/Shoe Classifier_InceptionResNetV2.ipynb new file mode 100644 index 0000000..fc9ce7f --- /dev/null +++ b/Shoe Classifier_InceptionResNetV2.ipynb @@ -0,0 +1,2787 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "572dc7fb", + "metadata": {}, + "outputs": [], + "source": [ + "from matplotlib import pyplot as plt\n", + "from matplotlib.image import imread\n", + "import pandas as pd\n", + "from collections import Counter\n", + "import json\n", + "import os\n", + "import re\n", + "import tempfile\n", + "import numpy as np\n", + "from os.path import exists\n", + "from imblearn.under_sampling import RandomUnderSampler\n", + "from PIL import ImageFile\n", + "import sklearn as sk\n", + "from sklearn.model_selection import train_test_split, StratifiedShuffleSplit\n", + "import tensorflow as tf\n", + "import tensorflow.keras\n", + "from tensorflow.keras.preprocessing.image import ImageDataGenerator\n", + "from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dense, Dropout, Flatten, Activation\n", + "from tensorflow.keras.models import Sequential\n", + "from tensorflow.keras.optimizers import Adam\n", + "# custom modules\n", + "import image_faults\n", + "\n", + "ImageFile.LOAD_TRUNCATED_IMAGES = True" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def add_regularization(model, regularizer=tf.keras.regularizers.l2(0.0001)):\n", + "\n", + " if not isinstance(regularizer, tf.keras.regularizers.Regularizer):\n", + " print(\"Regularizer must be a subclass of tf.keras.regularizers.Regularizer\")\n", + " return model\n", + "\n", + " for layer in model.layers:\n", + " for attr in ['kernel_regularizer']:\n", + " if hasattr(layer, attr):\n", + " setattr(layer, attr, regularizer)\n", + "\n", + " # When we change the layers attributes, the change only happens in the model config file\n", + " model_json = model.to_json()\n", + "\n", + " # Save the weights before reloading the model.\n", + " tmp_weights_path = os.path.join(tempfile.gettempdir(), 'tmp_weights.h5')\n", + " model.save_weights(tmp_weights_path)\n", + "\n", + " # load the model from the config\n", + " model = tf.keras.models.model_from_json(model_json)\n", + " \n", + " # Reload the model weights\n", + " model.load_weights(tmp_weights_path, by_name=True)\n", + " return model" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "a5c72863", + "metadata": {}, + "outputs": [], + "source": [ + "# image_faults.faulty_images() # removes faulty images\n", + "df = pd.read_csv('expanded_class.csv', index_col=[0], low_memory=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "1057a442", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{source:target} dictionary created @ /tf/training_images\n" + ] + } + ], + "source": [ + "def dict_pics():\n", + " target_dir = os.getcwd() + os.sep + \"training_images\"\n", + " with open('temp_pics_source_list.txt') as f:\n", + " temp_pics_source_list = json.load(f)\n", + " dict_pics = {k:target_dir + os.sep + re.search(r'[^/]+(?=/\\$_|.jpg)', k, re.IGNORECASE).group() + '.jpg' for k in temp_pics_source_list}\n", + " print(\"{source:target} dictionary created @ \" + target_dir)\n", + " return dict_pics\n", + "\n", + "dict_pics = dict_pics()\n", + "blah = pd.Series(df.PictureURL)\n", + "df = df.drop(labels=['PictureURL'], axis=1)\n", + "blah = blah.apply(lambda x: dict_pics[x])\n", + "df = pd.concat([blah, df],axis=1)\n", + "df = df.groupby('PrimaryCategoryID').filter(lambda x: len(x)>25) # removes cat outliers\n", + "# removes non-existent image paths" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "7a6146e6", + "metadata": {}, + "outputs": [], + "source": [ + "df['PrimaryCategoryID'] = df['PrimaryCategoryID'].astype(str) # pandas thinks ids are ints\n", + "\n", + "df=df.sample(frac=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "undersample = RandomUnderSampler(sampling_strategy='auto')\n", + "train, y_under = undersample.fit_resample(df, df['PrimaryCategoryID'])\n", + "#print(Counter(train['PrimaryCategoryID']))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "506aa5cf", + "metadata": {}, + "outputs": [], + "source": [ + "train, test = train_test_split(train, test_size=0.2, random_state=42)\n", + "# stratify=train['PrimaryCategoryID']\n", + "# train['PrimaryCategoryID'].value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "4d72eb90", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found 4542 validated image filenames belonging to 13 classes.\n", + "Found 1135 validated image filenames belonging to 13 classes.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.8/dist-packages/keras_preprocessing/image/dataframe_iterator.py:279: UserWarning: Found 1 invalid image filename(s) in x_col=\"PictureURL\". These filename(s) will be ignored.\n", + " warnings.warn(\n" + ] + } + ], + "source": [ + "datagen = ImageDataGenerator(rescale=1./255., \n", + " validation_split=.2,\n", + " #samplewise_std_normalization=True,\n", + " #horizontal_flip= True,\n", + " #vertical_flip= True,\n", + " #width_shift_range= 0.2,\n", + " #height_shift_range= 0.2,\n", + " #rotation_range= 90,\n", + " preprocessing_function=tf.keras.applications.inception_resnet_v2.preprocess_input)\n", + "train_generator=datagen.flow_from_dataframe(\n", + " dataframe=train[:len(train)],\n", + " directory='./training_images',\n", + " x_col='PictureURL',\n", + " y_col='PrimaryCategoryID',\n", + " batch_size=32,\n", + " seed=42,\n", + " shuffle=True,\n", + " target_size=(299,299),\n", + " subset='training'\n", + " )\n", + "validation_generator=datagen.flow_from_dataframe(\n", + " dataframe=train[:len(train)], # is using train right?\n", + " directory='./training_images',\n", + " x_col='PictureURL',\n", + " y_col='PrimaryCategoryID',\n", + " batch_size=32,\n", + " seed=42,\n", + " shuffle=True,\n", + " target_size=(299,299),\n", + " subset='validation'\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "7b70f37f", + "metadata": {}, + "outputs": [], + "source": [ + "imgs, labels = next(train_generator)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "1ed54bf5", + "metadata": {}, + "outputs": [], + "source": [ + "def plotImages(images_arr):\n", + " fig, axes = plt.subplots(1, 10, figsize=(20,20))\n", + " axes = axes.flatten()\n", + " for img, ax in zip( images_arr, axes):\n", + " ax.imshow(img)\n", + " ax.axis('off')\n", + " plt.tight_layout()\n", + " plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "85934565", + "metadata": {}, + "outputs": [], + "source": [ + "#plotImages(imgs)\n", + "#print(labels)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "6322bcad", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ], + "source": [ + "physical_devices = tf.config.list_physical_devices('GPU')\n", + "print(len(physical_devices))\n", + "tf.config.experimental.set_memory_growth(physical_devices[0], True)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "07fd25c6", + "metadata": {}, + "outputs": [], + "source": [ + "# see https://www.kaggle.com/dmitrypukhov/cnn-with-imagedatagenerator-flow-from-dataframe for train/test/val split \n", + "# example\n", + "\n", + "# may need to either create a test dataset from the original dataset or just download a new one" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "b31af79e", + "metadata": {}, + "outputs": [], + "source": [ + "base_model = tf.keras.applications.inception_resnet_v2.InceptionResNetV2(include_top=False, weights='imagenet', pooling='avg')\n", + "#base_model.summary()" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "fe06f2bf", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Model: \"model\"\n", + "__________________________________________________________________________________________________\n", + " Layer (type) Output Shape Param # Connected to \n", + "==================================================================================================\n", + " input_1 (InputLayer) [(None, None, None, 0 [] \n", + " 3)] \n", + " \n", + " conv2d (Conv2D) (None, None, None, 864 ['input_1[0][0]'] \n", + " 32) \n", + " \n", + " batch_normalization (BatchNorm (None, None, None, 96 ['conv2d[0][0]'] \n", + " alization) 32) \n", + " \n", + " activation (Activation) (None, None, None, 0 ['batch_normalization[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_1 (Conv2D) (None, None, None, 9216 ['activation[0][0]'] \n", + " 32) \n", + " \n", + " batch_normalization_1 (BatchNo (None, None, None, 96 ['conv2d_1[0][0]'] \n", + " rmalization) 32) \n", + " \n", + " activation_1 (Activation) (None, None, None, 0 ['batch_normalization_1[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_2 (Conv2D) (None, None, None, 18432 ['activation_1[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_2 (BatchNo (None, None, None, 192 ['conv2d_2[0][0]'] \n", + " rmalization) 64) \n", + " \n", + " activation_2 (Activation) (None, None, None, 0 ['batch_normalization_2[0][0]'] \n", + " 64) \n", + " \n", + " max_pooling2d (MaxPooling2D) (None, None, None, 0 ['activation_2[0][0]'] \n", + " 64) \n", + " \n", + " conv2d_3 (Conv2D) (None, None, None, 5120 ['max_pooling2d[0][0]'] \n", + " 80) \n", + " \n", + " batch_normalization_3 (BatchNo (None, None, None, 240 ['conv2d_3[0][0]'] \n", + " rmalization) 80) \n", + " \n", + " activation_3 (Activation) (None, None, None, 0 ['batch_normalization_3[0][0]'] \n", + " 80) \n", + " \n", + " conv2d_4 (Conv2D) (None, None, None, 138240 ['activation_3[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_4 (BatchNo (None, None, None, 576 ['conv2d_4[0][0]'] \n", + " rmalization) 192) \n", + " \n", + " activation_4 (Activation) (None, None, None, 0 ['batch_normalization_4[0][0]'] \n", + " 192) \n", + " \n", + " max_pooling2d_1 (MaxPooling2D) (None, None, None, 0 ['activation_4[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_8 (Conv2D) (None, None, None, 12288 ['max_pooling2d_1[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_8 (BatchNo (None, None, None, 192 ['conv2d_8[0][0]'] \n", + " rmalization) 64) \n", + " \n", + " activation_8 (Activation) (None, None, None, 0 ['batch_normalization_8[0][0]'] \n", + " 64) \n", + " \n", + " conv2d_6 (Conv2D) (None, None, None, 9216 ['max_pooling2d_1[0][0]'] \n", + " 48) \n", + " \n", + " conv2d_9 (Conv2D) (None, None, None, 55296 ['activation_8[0][0]'] \n", + " 96) \n", + " \n", + " batch_normalization_6 (BatchNo (None, None, None, 144 ['conv2d_6[0][0]'] \n", + " rmalization) 48) \n", + " \n", + " batch_normalization_9 (BatchNo (None, None, None, 288 ['conv2d_9[0][0]'] \n", + " rmalization) 96) \n", + " \n", + " activation_6 (Activation) (None, None, None, 0 ['batch_normalization_6[0][0]'] \n", + " 48) \n", + " \n", + " activation_9 (Activation) (None, None, None, 0 ['batch_normalization_9[0][0]'] \n", + " 96) \n", + " \n", + " average_pooling2d (AveragePool (None, None, None, 0 ['max_pooling2d_1[0][0]'] \n", + " ing2D) 192) \n", + " \n", + " conv2d_5 (Conv2D) (None, None, None, 18432 ['max_pooling2d_1[0][0]'] \n", + " 96) \n", + " \n", + " conv2d_7 (Conv2D) (None, None, None, 76800 ['activation_6[0][0]'] \n", + " 64) \n", + " \n", + " conv2d_10 (Conv2D) (None, None, None, 82944 ['activation_9[0][0]'] \n", + " 96) \n", + " \n", + " conv2d_11 (Conv2D) (None, None, None, 12288 ['average_pooling2d[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_5 (BatchNo (None, None, None, 288 ['conv2d_5[0][0]'] \n", + " rmalization) 96) \n", + " \n", + " batch_normalization_7 (BatchNo (None, None, None, 192 ['conv2d_7[0][0]'] \n", + " rmalization) 64) \n", + " \n", + " batch_normalization_10 (BatchN (None, None, None, 288 ['conv2d_10[0][0]'] \n", + " ormalization) 96) \n", + " \n", + " batch_normalization_11 (BatchN (None, None, None, 192 ['conv2d_11[0][0]'] \n", + " ormalization) 64) \n", + " \n", + " activation_5 (Activation) (None, None, None, 0 ['batch_normalization_5[0][0]'] \n", + " 96) \n", + " \n", + " activation_7 (Activation) (None, None, None, 0 ['batch_normalization_7[0][0]'] \n", + " 64) \n", + " \n", + " activation_10 (Activation) (None, None, None, 0 ['batch_normalization_10[0][0]'] \n", + " 96) \n", + " \n", + " activation_11 (Activation) (None, None, None, 0 ['batch_normalization_11[0][0]'] \n", + " 64) \n", + " \n", + " mixed_5b (Concatenate) (None, None, None, 0 ['activation_5[0][0]', \n", + " 320) 'activation_7[0][0]', \n", + " 'activation_10[0][0]', \n", + " 'activation_11[0][0]'] \n", + " \n", + " conv2d_15 (Conv2D) (None, None, None, 10240 ['mixed_5b[0][0]'] \n", + " 32) \n", + " \n", + " batch_normalization_15 (BatchN (None, None, None, 96 ['conv2d_15[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " activation_15 (Activation) (None, None, None, 0 ['batch_normalization_15[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_13 (Conv2D) (None, None, None, 10240 ['mixed_5b[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_16 (Conv2D) (None, None, None, 13824 ['activation_15[0][0]'] \n", + " 48) \n", + " \n", + " batch_normalization_13 (BatchN (None, None, None, 96 ['conv2d_13[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_16 (BatchN (None, None, None, 144 ['conv2d_16[0][0]'] \n", + " ormalization) 48) \n", + " \n", + " activation_13 (Activation) (None, None, None, 0 ['batch_normalization_13[0][0]'] \n", + " 32) \n", + " \n", + " activation_16 (Activation) (None, None, None, 0 ['batch_normalization_16[0][0]'] \n", + " 48) \n", + " \n", + " conv2d_12 (Conv2D) (None, None, None, 10240 ['mixed_5b[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_14 (Conv2D) (None, None, None, 9216 ['activation_13[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_17 (Conv2D) (None, None, None, 27648 ['activation_16[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_12 (BatchN (None, None, None, 96 ['conv2d_12[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_14 (BatchN (None, None, None, 96 ['conv2d_14[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_17 (BatchN (None, None, None, 192 ['conv2d_17[0][0]'] \n", + " ormalization) 64) \n", + " \n", + " activation_12 (Activation) (None, None, None, 0 ['batch_normalization_12[0][0]'] \n", + " 32) \n", + " \n", + " activation_14 (Activation) (None, None, None, 0 ['batch_normalization_14[0][0]'] \n", + " 32) \n", + " \n", + " activation_17 (Activation) (None, None, None, 0 ['batch_normalization_17[0][0]'] \n", + " 64) \n", + " \n", + " block35_1_mixed (Concatenate) (None, None, None, 0 ['activation_12[0][0]', \n", + " 128) 'activation_14[0][0]', \n", + " 'activation_17[0][0]'] \n", + " \n", + " block35_1_conv (Conv2D) (None, None, None, 41280 ['block35_1_mixed[0][0]'] \n", + " 320) \n", + " \n", + " block35_1 (Lambda) (None, None, None, 0 ['mixed_5b[0][0]', \n", + " 320) 'block35_1_conv[0][0]'] \n", + " \n", + " block35_1_ac (Activation) (None, None, None, 0 ['block35_1[0][0]'] \n", + " 320) \n", + " \n", + " conv2d_21 (Conv2D) (None, None, None, 10240 ['block35_1_ac[0][0]'] \n", + " 32) \n", + " \n", + " batch_normalization_21 (BatchN (None, None, None, 96 ['conv2d_21[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " activation_21 (Activation) (None, None, None, 0 ['batch_normalization_21[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_19 (Conv2D) (None, None, None, 10240 ['block35_1_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_22 (Conv2D) (None, None, None, 13824 ['activation_21[0][0]'] \n", + " 48) \n", + " \n", + " batch_normalization_19 (BatchN (None, None, None, 96 ['conv2d_19[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_22 (BatchN (None, None, None, 144 ['conv2d_22[0][0]'] \n", + " ormalization) 48) \n", + " \n", + " activation_19 (Activation) (None, None, None, 0 ['batch_normalization_19[0][0]'] \n", + " 32) \n", + " \n", + " activation_22 (Activation) (None, None, None, 0 ['batch_normalization_22[0][0]'] \n", + " 48) \n", + " \n", + " conv2d_18 (Conv2D) (None, None, None, 10240 ['block35_1_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_20 (Conv2D) (None, None, None, 9216 ['activation_19[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_23 (Conv2D) (None, None, None, 27648 ['activation_22[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_18 (BatchN (None, None, None, 96 ['conv2d_18[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_20 (BatchN (None, None, None, 96 ['conv2d_20[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_23 (BatchN (None, None, None, 192 ['conv2d_23[0][0]'] \n", + " ormalization) 64) \n", + " \n", + " activation_18 (Activation) (None, None, None, 0 ['batch_normalization_18[0][0]'] \n", + " 32) \n", + " \n", + " activation_20 (Activation) (None, None, None, 0 ['batch_normalization_20[0][0]'] \n", + " 32) \n", + " \n", + " activation_23 (Activation) (None, None, None, 0 ['batch_normalization_23[0][0]'] \n", + " 64) \n", + " \n", + " block35_2_mixed (Concatenate) (None, None, None, 0 ['activation_18[0][0]', \n", + " 128) 'activation_20[0][0]', \n", + " 'activation_23[0][0]'] \n", + " \n", + " block35_2_conv (Conv2D) (None, None, None, 41280 ['block35_2_mixed[0][0]'] \n", + " 320) \n", + " \n", + " block35_2 (Lambda) (None, None, None, 0 ['block35_1_ac[0][0]', \n", + " 320) 'block35_2_conv[0][0]'] \n", + " \n", + " block35_2_ac (Activation) (None, None, None, 0 ['block35_2[0][0]'] \n", + " 320) \n", + " \n", + " conv2d_27 (Conv2D) (None, None, None, 10240 ['block35_2_ac[0][0]'] \n", + " 32) \n", + " \n", + " batch_normalization_27 (BatchN (None, None, None, 96 ['conv2d_27[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " activation_27 (Activation) (None, None, None, 0 ['batch_normalization_27[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_25 (Conv2D) (None, None, None, 10240 ['block35_2_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_28 (Conv2D) (None, None, None, 13824 ['activation_27[0][0]'] \n", + " 48) \n", + " \n", + " batch_normalization_25 (BatchN (None, None, None, 96 ['conv2d_25[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_28 (BatchN (None, None, None, 144 ['conv2d_28[0][0]'] \n", + " ormalization) 48) \n", + " \n", + " activation_25 (Activation) (None, None, None, 0 ['batch_normalization_25[0][0]'] \n", + " 32) \n", + " \n", + " activation_28 (Activation) (None, None, None, 0 ['batch_normalization_28[0][0]'] \n", + " 48) \n", + " \n", + " conv2d_24 (Conv2D) (None, None, None, 10240 ['block35_2_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_26 (Conv2D) (None, None, None, 9216 ['activation_25[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_29 (Conv2D) (None, None, None, 27648 ['activation_28[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_24 (BatchN (None, None, None, 96 ['conv2d_24[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_26 (BatchN (None, None, None, 96 ['conv2d_26[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_29 (BatchN (None, None, None, 192 ['conv2d_29[0][0]'] \n", + " ormalization) 64) \n", + " \n", + " activation_24 (Activation) (None, None, None, 0 ['batch_normalization_24[0][0]'] \n", + " 32) \n", + " \n", + " activation_26 (Activation) (None, None, None, 0 ['batch_normalization_26[0][0]'] \n", + " 32) \n", + " \n", + " activation_29 (Activation) (None, None, None, 0 ['batch_normalization_29[0][0]'] \n", + " 64) \n", + " \n", + " block35_3_mixed (Concatenate) (None, None, None, 0 ['activation_24[0][0]', \n", + " 128) 'activation_26[0][0]', \n", + " 'activation_29[0][0]'] \n", + " \n", + " block35_3_conv (Conv2D) (None, None, None, 41280 ['block35_3_mixed[0][0]'] \n", + " 320) \n", + " \n", + " block35_3 (Lambda) (None, None, None, 0 ['block35_2_ac[0][0]', \n", + " 320) 'block35_3_conv[0][0]'] \n", + " \n", + " block35_3_ac (Activation) (None, None, None, 0 ['block35_3[0][0]'] \n", + " 320) \n", + " \n", + " conv2d_33 (Conv2D) (None, None, None, 10240 ['block35_3_ac[0][0]'] \n", + " 32) \n", + " \n", + " batch_normalization_33 (BatchN (None, None, None, 96 ['conv2d_33[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " activation_33 (Activation) (None, None, None, 0 ['batch_normalization_33[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_31 (Conv2D) (None, None, None, 10240 ['block35_3_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_34 (Conv2D) (None, None, None, 13824 ['activation_33[0][0]'] \n", + " 48) \n", + " \n", + " batch_normalization_31 (BatchN (None, None, None, 96 ['conv2d_31[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_34 (BatchN (None, None, None, 144 ['conv2d_34[0][0]'] \n", + " ormalization) 48) \n", + " \n", + " activation_31 (Activation) (None, None, None, 0 ['batch_normalization_31[0][0]'] \n", + " 32) \n", + " \n", + " activation_34 (Activation) (None, None, None, 0 ['batch_normalization_34[0][0]'] \n", + " 48) \n", + " \n", + " conv2d_30 (Conv2D) (None, None, None, 10240 ['block35_3_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_32 (Conv2D) (None, None, None, 9216 ['activation_31[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_35 (Conv2D) (None, None, None, 27648 ['activation_34[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_30 (BatchN (None, None, None, 96 ['conv2d_30[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_32 (BatchN (None, None, None, 96 ['conv2d_32[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_35 (BatchN (None, None, None, 192 ['conv2d_35[0][0]'] \n", + " ormalization) 64) \n", + " \n", + " activation_30 (Activation) (None, None, None, 0 ['batch_normalization_30[0][0]'] \n", + " 32) \n", + " \n", + " activation_32 (Activation) (None, None, None, 0 ['batch_normalization_32[0][0]'] \n", + " 32) \n", + " \n", + " activation_35 (Activation) (None, None, None, 0 ['batch_normalization_35[0][0]'] \n", + " 64) \n", + " \n", + " block35_4_mixed (Concatenate) (None, None, None, 0 ['activation_30[0][0]', \n", + " 128) 'activation_32[0][0]', \n", + " 'activation_35[0][0]'] \n", + " \n", + " block35_4_conv (Conv2D) (None, None, None, 41280 ['block35_4_mixed[0][0]'] \n", + " 320) \n", + " \n", + " block35_4 (Lambda) (None, None, None, 0 ['block35_3_ac[0][0]', \n", + " 320) 'block35_4_conv[0][0]'] \n", + " \n", + " block35_4_ac (Activation) (None, None, None, 0 ['block35_4[0][0]'] \n", + " 320) \n", + " \n", + " conv2d_39 (Conv2D) (None, None, None, 10240 ['block35_4_ac[0][0]'] \n", + " 32) \n", + " \n", + " batch_normalization_39 (BatchN (None, None, None, 96 ['conv2d_39[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " activation_39 (Activation) (None, None, None, 0 ['batch_normalization_39[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_37 (Conv2D) (None, None, None, 10240 ['block35_4_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_40 (Conv2D) (None, None, None, 13824 ['activation_39[0][0]'] \n", + " 48) \n", + " \n", + " batch_normalization_37 (BatchN (None, None, None, 96 ['conv2d_37[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_40 (BatchN (None, None, None, 144 ['conv2d_40[0][0]'] \n", + " ormalization) 48) \n", + " \n", + " activation_37 (Activation) (None, None, None, 0 ['batch_normalization_37[0][0]'] \n", + " 32) \n", + " \n", + " activation_40 (Activation) (None, None, None, 0 ['batch_normalization_40[0][0]'] \n", + " 48) \n", + " \n", + " conv2d_36 (Conv2D) (None, None, None, 10240 ['block35_4_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_38 (Conv2D) (None, None, None, 9216 ['activation_37[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_41 (Conv2D) (None, None, None, 27648 ['activation_40[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_36 (BatchN (None, None, None, 96 ['conv2d_36[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_38 (BatchN (None, None, None, 96 ['conv2d_38[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_41 (BatchN (None, None, None, 192 ['conv2d_41[0][0]'] \n", + " ormalization) 64) \n", + " \n", + " activation_36 (Activation) (None, None, None, 0 ['batch_normalization_36[0][0]'] \n", + " 32) \n", + " \n", + " activation_38 (Activation) (None, None, None, 0 ['batch_normalization_38[0][0]'] \n", + " 32) \n", + " \n", + " activation_41 (Activation) (None, None, None, 0 ['batch_normalization_41[0][0]'] \n", + " 64) \n", + " \n", + " block35_5_mixed (Concatenate) (None, None, None, 0 ['activation_36[0][0]', \n", + " 128) 'activation_38[0][0]', \n", + " 'activation_41[0][0]'] \n", + " \n", + " block35_5_conv (Conv2D) (None, None, None, 41280 ['block35_5_mixed[0][0]'] \n", + " 320) \n", + " \n", + " block35_5 (Lambda) (None, None, None, 0 ['block35_4_ac[0][0]', \n", + " 320) 'block35_5_conv[0][0]'] \n", + " \n", + " block35_5_ac (Activation) (None, None, None, 0 ['block35_5[0][0]'] \n", + " 320) \n", + " \n", + " conv2d_45 (Conv2D) (None, None, None, 10240 ['block35_5_ac[0][0]'] \n", + " 32) \n", + " \n", + " batch_normalization_45 (BatchN (None, None, None, 96 ['conv2d_45[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " activation_45 (Activation) (None, None, None, 0 ['batch_normalization_45[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_43 (Conv2D) (None, None, None, 10240 ['block35_5_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_46 (Conv2D) (None, None, None, 13824 ['activation_45[0][0]'] \n", + " 48) \n", + " \n", + " batch_normalization_43 (BatchN (None, None, None, 96 ['conv2d_43[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_46 (BatchN (None, None, None, 144 ['conv2d_46[0][0]'] \n", + " ormalization) 48) \n", + " \n", + " activation_43 (Activation) (None, None, None, 0 ['batch_normalization_43[0][0]'] \n", + " 32) \n", + " \n", + " activation_46 (Activation) (None, None, None, 0 ['batch_normalization_46[0][0]'] \n", + " 48) \n", + " \n", + " conv2d_42 (Conv2D) (None, None, None, 10240 ['block35_5_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_44 (Conv2D) (None, None, None, 9216 ['activation_43[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_47 (Conv2D) (None, None, None, 27648 ['activation_46[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_42 (BatchN (None, None, None, 96 ['conv2d_42[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_44 (BatchN (None, None, None, 96 ['conv2d_44[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_47 (BatchN (None, None, None, 192 ['conv2d_47[0][0]'] \n", + " ormalization) 64) \n", + " \n", + " activation_42 (Activation) (None, None, None, 0 ['batch_normalization_42[0][0]'] \n", + " 32) \n", + " \n", + " activation_44 (Activation) (None, None, None, 0 ['batch_normalization_44[0][0]'] \n", + " 32) \n", + " \n", + " activation_47 (Activation) (None, None, None, 0 ['batch_normalization_47[0][0]'] \n", + " 64) \n", + " \n", + " block35_6_mixed (Concatenate) (None, None, None, 0 ['activation_42[0][0]', \n", + " 128) 'activation_44[0][0]', \n", + " 'activation_47[0][0]'] \n", + " \n", + " block35_6_conv (Conv2D) (None, None, None, 41280 ['block35_6_mixed[0][0]'] \n", + " 320) \n", + " \n", + " block35_6 (Lambda) (None, None, None, 0 ['block35_5_ac[0][0]', \n", + " 320) 'block35_6_conv[0][0]'] \n", + " \n", + " block35_6_ac (Activation) (None, None, None, 0 ['block35_6[0][0]'] \n", + " 320) \n", + " \n", + " conv2d_51 (Conv2D) (None, None, None, 10240 ['block35_6_ac[0][0]'] \n", + " 32) \n", + " \n", + " batch_normalization_51 (BatchN (None, None, None, 96 ['conv2d_51[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " activation_51 (Activation) (None, None, None, 0 ['batch_normalization_51[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_49 (Conv2D) (None, None, None, 10240 ['block35_6_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_52 (Conv2D) (None, None, None, 13824 ['activation_51[0][0]'] \n", + " 48) \n", + " \n", + " batch_normalization_49 (BatchN (None, None, None, 96 ['conv2d_49[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_52 (BatchN (None, None, None, 144 ['conv2d_52[0][0]'] \n", + " ormalization) 48) \n", + " \n", + " activation_49 (Activation) (None, None, None, 0 ['batch_normalization_49[0][0]'] \n", + " 32) \n", + " \n", + " activation_52 (Activation) (None, None, None, 0 ['batch_normalization_52[0][0]'] \n", + " 48) \n", + " \n", + " conv2d_48 (Conv2D) (None, None, None, 10240 ['block35_6_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_50 (Conv2D) (None, None, None, 9216 ['activation_49[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_53 (Conv2D) (None, None, None, 27648 ['activation_52[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_48 (BatchN (None, None, None, 96 ['conv2d_48[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_50 (BatchN (None, None, None, 96 ['conv2d_50[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_53 (BatchN (None, None, None, 192 ['conv2d_53[0][0]'] \n", + " ormalization) 64) \n", + " \n", + " activation_48 (Activation) (None, None, None, 0 ['batch_normalization_48[0][0]'] \n", + " 32) \n", + " \n", + " activation_50 (Activation) (None, None, None, 0 ['batch_normalization_50[0][0]'] \n", + " 32) \n", + " \n", + " activation_53 (Activation) (None, None, None, 0 ['batch_normalization_53[0][0]'] \n", + " 64) \n", + " \n", + " block35_7_mixed (Concatenate) (None, None, None, 0 ['activation_48[0][0]', \n", + " 128) 'activation_50[0][0]', \n", + " 'activation_53[0][0]'] \n", + " \n", + " block35_7_conv (Conv2D) (None, None, None, 41280 ['block35_7_mixed[0][0]'] \n", + " 320) \n", + " \n", + " block35_7 (Lambda) (None, None, None, 0 ['block35_6_ac[0][0]', \n", + " 320) 'block35_7_conv[0][0]'] \n", + " \n", + " block35_7_ac (Activation) (None, None, None, 0 ['block35_7[0][0]'] \n", + " 320) \n", + " \n", + " conv2d_57 (Conv2D) (None, None, None, 10240 ['block35_7_ac[0][0]'] \n", + " 32) \n", + " \n", + " batch_normalization_57 (BatchN (None, None, None, 96 ['conv2d_57[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " activation_57 (Activation) (None, None, None, 0 ['batch_normalization_57[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_55 (Conv2D) (None, None, None, 10240 ['block35_7_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_58 (Conv2D) (None, None, None, 13824 ['activation_57[0][0]'] \n", + " 48) \n", + " \n", + " batch_normalization_55 (BatchN (None, None, None, 96 ['conv2d_55[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_58 (BatchN (None, None, None, 144 ['conv2d_58[0][0]'] \n", + " ormalization) 48) \n", + " \n", + " activation_55 (Activation) (None, None, None, 0 ['batch_normalization_55[0][0]'] \n", + " 32) \n", + " \n", + " activation_58 (Activation) (None, None, None, 0 ['batch_normalization_58[0][0]'] \n", + " 48) \n", + " \n", + " conv2d_54 (Conv2D) (None, None, None, 10240 ['block35_7_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_56 (Conv2D) (None, None, None, 9216 ['activation_55[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_59 (Conv2D) (None, None, None, 27648 ['activation_58[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_54 (BatchN (None, None, None, 96 ['conv2d_54[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_56 (BatchN (None, None, None, 96 ['conv2d_56[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_59 (BatchN (None, None, None, 192 ['conv2d_59[0][0]'] \n", + " ormalization) 64) \n", + " \n", + " activation_54 (Activation) (None, None, None, 0 ['batch_normalization_54[0][0]'] \n", + " 32) \n", + " \n", + " activation_56 (Activation) (None, None, None, 0 ['batch_normalization_56[0][0]'] \n", + " 32) \n", + " \n", + " activation_59 (Activation) (None, None, None, 0 ['batch_normalization_59[0][0]'] \n", + " 64) \n", + " \n", + " block35_8_mixed (Concatenate) (None, None, None, 0 ['activation_54[0][0]', \n", + " 128) 'activation_56[0][0]', \n", + " 'activation_59[0][0]'] \n", + " \n", + " block35_8_conv (Conv2D) (None, None, None, 41280 ['block35_8_mixed[0][0]'] \n", + " 320) \n", + " \n", + " block35_8 (Lambda) (None, None, None, 0 ['block35_7_ac[0][0]', \n", + " 320) 'block35_8_conv[0][0]'] \n", + " \n", + " block35_8_ac (Activation) (None, None, None, 0 ['block35_8[0][0]'] \n", + " 320) \n", + " \n", + " conv2d_63 (Conv2D) (None, None, None, 10240 ['block35_8_ac[0][0]'] \n", + " 32) \n", + " \n", + " batch_normalization_63 (BatchN (None, None, None, 96 ['conv2d_63[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " activation_63 (Activation) (None, None, None, 0 ['batch_normalization_63[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_61 (Conv2D) (None, None, None, 10240 ['block35_8_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_64 (Conv2D) (None, None, None, 13824 ['activation_63[0][0]'] \n", + " 48) \n", + " \n", + " batch_normalization_61 (BatchN (None, None, None, 96 ['conv2d_61[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_64 (BatchN (None, None, None, 144 ['conv2d_64[0][0]'] \n", + " ormalization) 48) \n", + " \n", + " activation_61 (Activation) (None, None, None, 0 ['batch_normalization_61[0][0]'] \n", + " 32) \n", + " \n", + " activation_64 (Activation) (None, None, None, 0 ['batch_normalization_64[0][0]'] \n", + " 48) \n", + " \n", + " conv2d_60 (Conv2D) (None, None, None, 10240 ['block35_8_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_62 (Conv2D) (None, None, None, 9216 ['activation_61[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_65 (Conv2D) (None, None, None, 27648 ['activation_64[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_60 (BatchN (None, None, None, 96 ['conv2d_60[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_62 (BatchN (None, None, None, 96 ['conv2d_62[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_65 (BatchN (None, None, None, 192 ['conv2d_65[0][0]'] \n", + " ormalization) 64) \n", + " \n", + " activation_60 (Activation) (None, None, None, 0 ['batch_normalization_60[0][0]'] \n", + " 32) \n", + " \n", + " activation_62 (Activation) (None, None, None, 0 ['batch_normalization_62[0][0]'] \n", + " 32) \n", + " \n", + " activation_65 (Activation) (None, None, None, 0 ['batch_normalization_65[0][0]'] \n", + " 64) \n", + " \n", + " block35_9_mixed (Concatenate) (None, None, None, 0 ['activation_60[0][0]', \n", + " 128) 'activation_62[0][0]', \n", + " 'activation_65[0][0]'] \n", + " \n", + " block35_9_conv (Conv2D) (None, None, None, 41280 ['block35_9_mixed[0][0]'] \n", + " 320) \n", + " \n", + " block35_9 (Lambda) (None, None, None, 0 ['block35_8_ac[0][0]', \n", + " 320) 'block35_9_conv[0][0]'] \n", + " \n", + " block35_9_ac (Activation) (None, None, None, 0 ['block35_9[0][0]'] \n", + " 320) \n", + " \n", + " conv2d_69 (Conv2D) (None, None, None, 10240 ['block35_9_ac[0][0]'] \n", + " 32) \n", + " \n", + " batch_normalization_69 (BatchN (None, None, None, 96 ['conv2d_69[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " activation_69 (Activation) (None, None, None, 0 ['batch_normalization_69[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_67 (Conv2D) (None, None, None, 10240 ['block35_9_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_70 (Conv2D) (None, None, None, 13824 ['activation_69[0][0]'] \n", + " 48) \n", + " \n", + " batch_normalization_67 (BatchN (None, None, None, 96 ['conv2d_67[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_70 (BatchN (None, None, None, 144 ['conv2d_70[0][0]'] \n", + " ormalization) 48) \n", + " \n", + " activation_67 (Activation) (None, None, None, 0 ['batch_normalization_67[0][0]'] \n", + " 32) \n", + " \n", + " activation_70 (Activation) (None, None, None, 0 ['batch_normalization_70[0][0]'] \n", + " 48) \n", + " \n", + " conv2d_66 (Conv2D) (None, None, None, 10240 ['block35_9_ac[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_68 (Conv2D) (None, None, None, 9216 ['activation_67[0][0]'] \n", + " 32) \n", + " \n", + " conv2d_71 (Conv2D) (None, None, None, 27648 ['activation_70[0][0]'] \n", + " 64) \n", + " \n", + " batch_normalization_66 (BatchN (None, None, None, 96 ['conv2d_66[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_68 (BatchN (None, None, None, 96 ['conv2d_68[0][0]'] \n", + " ormalization) 32) \n", + " \n", + " batch_normalization_71 (BatchN (None, None, None, 192 ['conv2d_71[0][0]'] \n", + " ormalization) 64) \n", + " \n", + " activation_66 (Activation) (None, None, None, 0 ['batch_normalization_66[0][0]'] \n", + " 32) \n", + " \n", + " activation_68 (Activation) (None, None, None, 0 ['batch_normalization_68[0][0]'] \n", + " 32) \n", + " \n", + " activation_71 (Activation) (None, None, None, 0 ['batch_normalization_71[0][0]'] \n", + " 64) \n", + " \n", + " block35_10_mixed (Concatenate) (None, None, None, 0 ['activation_66[0][0]', \n", + " 128) 'activation_68[0][0]', \n", + " 'activation_71[0][0]'] \n", + " \n", + " block35_10_conv (Conv2D) (None, None, None, 41280 ['block35_10_mixed[0][0]'] \n", + " 320) \n", + " \n", + " block35_10 (Lambda) (None, None, None, 0 ['block35_9_ac[0][0]', \n", + " 320) 'block35_10_conv[0][0]'] \n", + " \n", + " block35_10_ac (Activation) (None, None, None, 0 ['block35_10[0][0]'] \n", + " 320) \n", + " \n", + " conv2d_73 (Conv2D) (None, None, None, 81920 ['block35_10_ac[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_73 (BatchN (None, None, None, 768 ['conv2d_73[0][0]'] \n", + " ormalization) 256) \n", + " \n", + " activation_73 (Activation) (None, None, None, 0 ['batch_normalization_73[0][0]'] \n", + " 256) \n", + " \n", + " conv2d_74 (Conv2D) (None, None, None, 589824 ['activation_73[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_74 (BatchN (None, None, None, 768 ['conv2d_74[0][0]'] \n", + " ormalization) 256) \n", + " \n", + " activation_74 (Activation) (None, None, None, 0 ['batch_normalization_74[0][0]'] \n", + " 256) \n", + " \n", + " conv2d_72 (Conv2D) (None, None, None, 1105920 ['block35_10_ac[0][0]'] \n", + " 384) \n", + " \n", + " conv2d_75 (Conv2D) (None, None, None, 884736 ['activation_74[0][0]'] \n", + " 384) \n", + " \n", + " batch_normalization_72 (BatchN (None, None, None, 1152 ['conv2d_72[0][0]'] \n", + " ormalization) 384) \n", + " \n", + " batch_normalization_75 (BatchN (None, None, None, 1152 ['conv2d_75[0][0]'] \n", + " ormalization) 384) \n", + " \n", + " activation_72 (Activation) (None, None, None, 0 ['batch_normalization_72[0][0]'] \n", + " 384) \n", + " \n", + " activation_75 (Activation) (None, None, None, 0 ['batch_normalization_75[0][0]'] \n", + " 384) \n", + " \n", + " max_pooling2d_2 (MaxPooling2D) (None, None, None, 0 ['block35_10_ac[0][0]'] \n", + " 320) \n", + " \n", + " mixed_6a (Concatenate) (None, None, None, 0 ['activation_72[0][0]', \n", + " 1088) 'activation_75[0][0]', \n", + " 'max_pooling2d_2[0][0]'] \n", + " \n", + " conv2d_77 (Conv2D) (None, None, None, 139264 ['mixed_6a[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_77 (BatchN (None, None, None, 384 ['conv2d_77[0][0]'] \n", + " ormalization) 128) \n", + " \n", + " activation_77 (Activation) (None, None, None, 0 ['batch_normalization_77[0][0]'] \n", + " 128) \n", + " \n", + " conv2d_78 (Conv2D) (None, None, None, 143360 ['activation_77[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_78 (BatchN (None, None, None, 480 ['conv2d_78[0][0]'] \n", + " ormalization) 160) \n", + " \n", + " activation_78 (Activation) (None, None, None, 0 ['batch_normalization_78[0][0]'] \n", + " 160) \n", + " \n", + " conv2d_76 (Conv2D) (None, None, None, 208896 ['mixed_6a[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_79 (Conv2D) (None, None, None, 215040 ['activation_78[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_76 (BatchN (None, None, None, 576 ['conv2d_76[0][0]'] \n", + " ormalization) 192) \n", + " \n", + " batch_normalization_79 (BatchN (None, None, None, 576 ['conv2d_79[0][0]'] \n", + " ormalization) 192) \n", + " \n", + " activation_76 (Activation) (None, None, None, 0 ['batch_normalization_76[0][0]'] \n", + " 192) \n", + " \n", + " activation_79 (Activation) (None, None, None, 0 ['batch_normalization_79[0][0]'] \n", + " 192) \n", + " \n", + " block17_1_mixed (Concatenate) (None, None, None, 0 ['activation_76[0][0]', \n", + " 384) 'activation_79[0][0]'] \n", + " \n", + " block17_1_conv (Conv2D) (None, None, None, 418880 ['block17_1_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_1 (Lambda) (None, None, None, 0 ['mixed_6a[0][0]', \n", + " 1088) 'block17_1_conv[0][0]'] \n", + " \n", + " block17_1_ac (Activation) (None, None, None, 0 ['block17_1[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_81 (Conv2D) (None, None, None, 139264 ['block17_1_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_81 (BatchN (None, None, None, 384 ['conv2d_81[0][0]'] \n", + " ormalization) 128) \n", + " \n", + " activation_81 (Activation) (None, None, None, 0 ['batch_normalization_81[0][0]'] \n", + " 128) \n", + " \n", + " conv2d_82 (Conv2D) (None, None, None, 143360 ['activation_81[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_82 (BatchN (None, None, None, 480 ['conv2d_82[0][0]'] \n", + " ormalization) 160) \n", + " \n", + " activation_82 (Activation) (None, None, None, 0 ['batch_normalization_82[0][0]'] \n", + " 160) \n", + " \n", + " conv2d_80 (Conv2D) (None, None, None, 208896 ['block17_1_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_83 (Conv2D) (None, None, None, 215040 ['activation_82[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_80 (BatchN (None, None, None, 576 ['conv2d_80[0][0]'] \n", + " ormalization) 192) \n", + " \n", + " batch_normalization_83 (BatchN (None, None, None, 576 ['conv2d_83[0][0]'] \n", + " ormalization) 192) \n", + " \n", + " activation_80 (Activation) (None, None, None, 0 ['batch_normalization_80[0][0]'] \n", + " 192) \n", + " \n", + " activation_83 (Activation) (None, None, None, 0 ['batch_normalization_83[0][0]'] \n", + " 192) \n", + " \n", + " block17_2_mixed (Concatenate) (None, None, None, 0 ['activation_80[0][0]', \n", + " 384) 'activation_83[0][0]'] \n", + " \n", + " block17_2_conv (Conv2D) (None, None, None, 418880 ['block17_2_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_2 (Lambda) (None, None, None, 0 ['block17_1_ac[0][0]', \n", + " 1088) 'block17_2_conv[0][0]'] \n", + " \n", + " block17_2_ac (Activation) (None, None, None, 0 ['block17_2[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_85 (Conv2D) (None, None, None, 139264 ['block17_2_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_85 (BatchN (None, None, None, 384 ['conv2d_85[0][0]'] \n", + " ormalization) 128) \n", + " \n", + " activation_85 (Activation) (None, None, None, 0 ['batch_normalization_85[0][0]'] \n", + " 128) \n", + " \n", + " conv2d_86 (Conv2D) (None, None, None, 143360 ['activation_85[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_86 (BatchN (None, None, None, 480 ['conv2d_86[0][0]'] \n", + " ormalization) 160) \n", + " \n", + " activation_86 (Activation) (None, None, None, 0 ['batch_normalization_86[0][0]'] \n", + " 160) \n", + " \n", + " conv2d_84 (Conv2D) (None, None, None, 208896 ['block17_2_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_87 (Conv2D) (None, None, None, 215040 ['activation_86[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_84 (BatchN (None, None, None, 576 ['conv2d_84[0][0]'] \n", + " ormalization) 192) \n", + " \n", + " batch_normalization_87 (BatchN (None, None, None, 576 ['conv2d_87[0][0]'] \n", + " ormalization) 192) \n", + " \n", + " activation_84 (Activation) (None, None, None, 0 ['batch_normalization_84[0][0]'] \n", + " 192) \n", + " \n", + " activation_87 (Activation) (None, None, None, 0 ['batch_normalization_87[0][0]'] \n", + " 192) \n", + " \n", + " block17_3_mixed (Concatenate) (None, None, None, 0 ['activation_84[0][0]', \n", + " 384) 'activation_87[0][0]'] \n", + " \n", + " block17_3_conv (Conv2D) (None, None, None, 418880 ['block17_3_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_3 (Lambda) (None, None, None, 0 ['block17_2_ac[0][0]', \n", + " 1088) 'block17_3_conv[0][0]'] \n", + " \n", + " block17_3_ac (Activation) (None, None, None, 0 ['block17_3[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_89 (Conv2D) (None, None, None, 139264 ['block17_3_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_89 (BatchN (None, None, None, 384 ['conv2d_89[0][0]'] \n", + " ormalization) 128) \n", + " \n", + " activation_89 (Activation) (None, None, None, 0 ['batch_normalization_89[0][0]'] \n", + " 128) \n", + " \n", + " conv2d_90 (Conv2D) (None, None, None, 143360 ['activation_89[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_90 (BatchN (None, None, None, 480 ['conv2d_90[0][0]'] \n", + " ormalization) 160) \n", + " \n", + " activation_90 (Activation) (None, None, None, 0 ['batch_normalization_90[0][0]'] \n", + " 160) \n", + " \n", + " conv2d_88 (Conv2D) (None, None, None, 208896 ['block17_3_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_91 (Conv2D) (None, None, None, 215040 ['activation_90[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_88 (BatchN (None, None, None, 576 ['conv2d_88[0][0]'] \n", + " ormalization) 192) \n", + " \n", + " batch_normalization_91 (BatchN (None, None, None, 576 ['conv2d_91[0][0]'] \n", + " ormalization) 192) \n", + " \n", + " activation_88 (Activation) (None, None, None, 0 ['batch_normalization_88[0][0]'] \n", + " 192) \n", + " \n", + " activation_91 (Activation) (None, None, None, 0 ['batch_normalization_91[0][0]'] \n", + " 192) \n", + " \n", + " block17_4_mixed (Concatenate) (None, None, None, 0 ['activation_88[0][0]', \n", + " 384) 'activation_91[0][0]'] \n", + " \n", + " block17_4_conv (Conv2D) (None, None, None, 418880 ['block17_4_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_4 (Lambda) (None, None, None, 0 ['block17_3_ac[0][0]', \n", + " 1088) 'block17_4_conv[0][0]'] \n", + " \n", + " block17_4_ac (Activation) (None, None, None, 0 ['block17_4[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_93 (Conv2D) (None, None, None, 139264 ['block17_4_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_93 (BatchN (None, None, None, 384 ['conv2d_93[0][0]'] \n", + " ormalization) 128) \n", + " \n", + " activation_93 (Activation) (None, None, None, 0 ['batch_normalization_93[0][0]'] \n", + " 128) \n", + " \n", + " conv2d_94 (Conv2D) (None, None, None, 143360 ['activation_93[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_94 (BatchN (None, None, None, 480 ['conv2d_94[0][0]'] \n", + " ormalization) 160) \n", + " \n", + " activation_94 (Activation) (None, None, None, 0 ['batch_normalization_94[0][0]'] \n", + " 160) \n", + " \n", + " conv2d_92 (Conv2D) (None, None, None, 208896 ['block17_4_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_95 (Conv2D) (None, None, None, 215040 ['activation_94[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_92 (BatchN (None, None, None, 576 ['conv2d_92[0][0]'] \n", + " ormalization) 192) \n", + " \n", + " batch_normalization_95 (BatchN (None, None, None, 576 ['conv2d_95[0][0]'] \n", + " ormalization) 192) \n", + " \n", + " activation_92 (Activation) (None, None, None, 0 ['batch_normalization_92[0][0]'] \n", + " 192) \n", + " \n", + " activation_95 (Activation) (None, None, None, 0 ['batch_normalization_95[0][0]'] \n", + " 192) \n", + " \n", + " block17_5_mixed (Concatenate) (None, None, None, 0 ['activation_92[0][0]', \n", + " 384) 'activation_95[0][0]'] \n", + " \n", + " block17_5_conv (Conv2D) (None, None, None, 418880 ['block17_5_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_5 (Lambda) (None, None, None, 0 ['block17_4_ac[0][0]', \n", + " 1088) 'block17_5_conv[0][0]'] \n", + " \n", + " block17_5_ac (Activation) (None, None, None, 0 ['block17_5[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_97 (Conv2D) (None, None, None, 139264 ['block17_5_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_97 (BatchN (None, None, None, 384 ['conv2d_97[0][0]'] \n", + " ormalization) 128) \n", + " \n", + " activation_97 (Activation) (None, None, None, 0 ['batch_normalization_97[0][0]'] \n", + " 128) \n", + " \n", + " conv2d_98 (Conv2D) (None, None, None, 143360 ['activation_97[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_98 (BatchN (None, None, None, 480 ['conv2d_98[0][0]'] \n", + " ormalization) 160) \n", + " \n", + " activation_98 (Activation) (None, None, None, 0 ['batch_normalization_98[0][0]'] \n", + " 160) \n", + " \n", + " conv2d_96 (Conv2D) (None, None, None, 208896 ['block17_5_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_99 (Conv2D) (None, None, None, 215040 ['activation_98[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_96 (BatchN (None, None, None, 576 ['conv2d_96[0][0]'] \n", + " ormalization) 192) \n", + " \n", + " batch_normalization_99 (BatchN (None, None, None, 576 ['conv2d_99[0][0]'] \n", + " ormalization) 192) \n", + " \n", + " activation_96 (Activation) (None, None, None, 0 ['batch_normalization_96[0][0]'] \n", + " 192) \n", + " \n", + " activation_99 (Activation) (None, None, None, 0 ['batch_normalization_99[0][0]'] \n", + " 192) \n", + " \n", + " block17_6_mixed (Concatenate) (None, None, None, 0 ['activation_96[0][0]', \n", + " 384) 'activation_99[0][0]'] \n", + " \n", + " block17_6_conv (Conv2D) (None, None, None, 418880 ['block17_6_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_6 (Lambda) (None, None, None, 0 ['block17_5_ac[0][0]', \n", + " 1088) 'block17_6_conv[0][0]'] \n", + " \n", + " block17_6_ac (Activation) (None, None, None, 0 ['block17_6[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_101 (Conv2D) (None, None, None, 139264 ['block17_6_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_101 (Batch (None, None, None, 384 ['conv2d_101[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_101 (Activation) (None, None, None, 0 ['batch_normalization_101[0][0]']\n", + " 128) \n", + " \n", + " conv2d_102 (Conv2D) (None, None, None, 143360 ['activation_101[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_102 (Batch (None, None, None, 480 ['conv2d_102[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_102 (Activation) (None, None, None, 0 ['batch_normalization_102[0][0]']\n", + " 160) \n", + " \n", + " conv2d_100 (Conv2D) (None, None, None, 208896 ['block17_6_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_103 (Conv2D) (None, None, None, 215040 ['activation_102[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_100 (Batch (None, None, None, 576 ['conv2d_100[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_103 (Batch (None, None, None, 576 ['conv2d_103[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_100 (Activation) (None, None, None, 0 ['batch_normalization_100[0][0]']\n", + " 192) \n", + " \n", + " activation_103 (Activation) (None, None, None, 0 ['batch_normalization_103[0][0]']\n", + " 192) \n", + " \n", + " block17_7_mixed (Concatenate) (None, None, None, 0 ['activation_100[0][0]', \n", + " 384) 'activation_103[0][0]'] \n", + " \n", + " block17_7_conv (Conv2D) (None, None, None, 418880 ['block17_7_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_7 (Lambda) (None, None, None, 0 ['block17_6_ac[0][0]', \n", + " 1088) 'block17_7_conv[0][0]'] \n", + " \n", + " block17_7_ac (Activation) (None, None, None, 0 ['block17_7[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_105 (Conv2D) (None, None, None, 139264 ['block17_7_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_105 (Batch (None, None, None, 384 ['conv2d_105[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_105 (Activation) (None, None, None, 0 ['batch_normalization_105[0][0]']\n", + " 128) \n", + " \n", + " conv2d_106 (Conv2D) (None, None, None, 143360 ['activation_105[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_106 (Batch (None, None, None, 480 ['conv2d_106[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_106 (Activation) (None, None, None, 0 ['batch_normalization_106[0][0]']\n", + " 160) \n", + " \n", + " conv2d_104 (Conv2D) (None, None, None, 208896 ['block17_7_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_107 (Conv2D) (None, None, None, 215040 ['activation_106[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_104 (Batch (None, None, None, 576 ['conv2d_104[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_107 (Batch (None, None, None, 576 ['conv2d_107[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_104 (Activation) (None, None, None, 0 ['batch_normalization_104[0][0]']\n", + " 192) \n", + " \n", + " activation_107 (Activation) (None, None, None, 0 ['batch_normalization_107[0][0]']\n", + " 192) \n", + " \n", + " block17_8_mixed (Concatenate) (None, None, None, 0 ['activation_104[0][0]', \n", + " 384) 'activation_107[0][0]'] \n", + " \n", + " block17_8_conv (Conv2D) (None, None, None, 418880 ['block17_8_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_8 (Lambda) (None, None, None, 0 ['block17_7_ac[0][0]', \n", + " 1088) 'block17_8_conv[0][0]'] \n", + " \n", + " block17_8_ac (Activation) (None, None, None, 0 ['block17_8[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_109 (Conv2D) (None, None, None, 139264 ['block17_8_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_109 (Batch (None, None, None, 384 ['conv2d_109[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_109 (Activation) (None, None, None, 0 ['batch_normalization_109[0][0]']\n", + " 128) \n", + " \n", + " conv2d_110 (Conv2D) (None, None, None, 143360 ['activation_109[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_110 (Batch (None, None, None, 480 ['conv2d_110[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_110 (Activation) (None, None, None, 0 ['batch_normalization_110[0][0]']\n", + " 160) \n", + " \n", + " conv2d_108 (Conv2D) (None, None, None, 208896 ['block17_8_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_111 (Conv2D) (None, None, None, 215040 ['activation_110[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_108 (Batch (None, None, None, 576 ['conv2d_108[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_111 (Batch (None, None, None, 576 ['conv2d_111[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_108 (Activation) (None, None, None, 0 ['batch_normalization_108[0][0]']\n", + " 192) \n", + " \n", + " activation_111 (Activation) (None, None, None, 0 ['batch_normalization_111[0][0]']\n", + " 192) \n", + " \n", + " block17_9_mixed (Concatenate) (None, None, None, 0 ['activation_108[0][0]', \n", + " 384) 'activation_111[0][0]'] \n", + " \n", + " block17_9_conv (Conv2D) (None, None, None, 418880 ['block17_9_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_9 (Lambda) (None, None, None, 0 ['block17_8_ac[0][0]', \n", + " 1088) 'block17_9_conv[0][0]'] \n", + " \n", + " block17_9_ac (Activation) (None, None, None, 0 ['block17_9[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_113 (Conv2D) (None, None, None, 139264 ['block17_9_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_113 (Batch (None, None, None, 384 ['conv2d_113[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_113 (Activation) (None, None, None, 0 ['batch_normalization_113[0][0]']\n", + " 128) \n", + " \n", + " conv2d_114 (Conv2D) (None, None, None, 143360 ['activation_113[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_114 (Batch (None, None, None, 480 ['conv2d_114[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_114 (Activation) (None, None, None, 0 ['batch_normalization_114[0][0]']\n", + " 160) \n", + " \n", + " conv2d_112 (Conv2D) (None, None, None, 208896 ['block17_9_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_115 (Conv2D) (None, None, None, 215040 ['activation_114[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_112 (Batch (None, None, None, 576 ['conv2d_112[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_115 (Batch (None, None, None, 576 ['conv2d_115[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_112 (Activation) (None, None, None, 0 ['batch_normalization_112[0][0]']\n", + " 192) \n", + " \n", + " activation_115 (Activation) (None, None, None, 0 ['batch_normalization_115[0][0]']\n", + " 192) \n", + " \n", + " block17_10_mixed (Concatenate) (None, None, None, 0 ['activation_112[0][0]', \n", + " 384) 'activation_115[0][0]'] \n", + " \n", + " block17_10_conv (Conv2D) (None, None, None, 418880 ['block17_10_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_10 (Lambda) (None, None, None, 0 ['block17_9_ac[0][0]', \n", + " 1088) 'block17_10_conv[0][0]'] \n", + " \n", + " block17_10_ac (Activation) (None, None, None, 0 ['block17_10[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_117 (Conv2D) (None, None, None, 139264 ['block17_10_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_117 (Batch (None, None, None, 384 ['conv2d_117[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_117 (Activation) (None, None, None, 0 ['batch_normalization_117[0][0]']\n", + " 128) \n", + " \n", + " conv2d_118 (Conv2D) (None, None, None, 143360 ['activation_117[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_118 (Batch (None, None, None, 480 ['conv2d_118[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_118 (Activation) (None, None, None, 0 ['batch_normalization_118[0][0]']\n", + " 160) \n", + " \n", + " conv2d_116 (Conv2D) (None, None, None, 208896 ['block17_10_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_119 (Conv2D) (None, None, None, 215040 ['activation_118[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_116 (Batch (None, None, None, 576 ['conv2d_116[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_119 (Batch (None, None, None, 576 ['conv2d_119[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_116 (Activation) (None, None, None, 0 ['batch_normalization_116[0][0]']\n", + " 192) \n", + " \n", + " activation_119 (Activation) (None, None, None, 0 ['batch_normalization_119[0][0]']\n", + " 192) \n", + " \n", + " block17_11_mixed (Concatenate) (None, None, None, 0 ['activation_116[0][0]', \n", + " 384) 'activation_119[0][0]'] \n", + " \n", + " block17_11_conv (Conv2D) (None, None, None, 418880 ['block17_11_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_11 (Lambda) (None, None, None, 0 ['block17_10_ac[0][0]', \n", + " 1088) 'block17_11_conv[0][0]'] \n", + " \n", + " block17_11_ac (Activation) (None, None, None, 0 ['block17_11[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_121 (Conv2D) (None, None, None, 139264 ['block17_11_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_121 (Batch (None, None, None, 384 ['conv2d_121[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_121 (Activation) (None, None, None, 0 ['batch_normalization_121[0][0]']\n", + " 128) \n", + " \n", + " conv2d_122 (Conv2D) (None, None, None, 143360 ['activation_121[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_122 (Batch (None, None, None, 480 ['conv2d_122[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_122 (Activation) (None, None, None, 0 ['batch_normalization_122[0][0]']\n", + " 160) \n", + " \n", + " conv2d_120 (Conv2D) (None, None, None, 208896 ['block17_11_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_123 (Conv2D) (None, None, None, 215040 ['activation_122[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_120 (Batch (None, None, None, 576 ['conv2d_120[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_123 (Batch (None, None, None, 576 ['conv2d_123[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_120 (Activation) (None, None, None, 0 ['batch_normalization_120[0][0]']\n", + " 192) \n", + " \n", + " activation_123 (Activation) (None, None, None, 0 ['batch_normalization_123[0][0]']\n", + " 192) \n", + " \n", + " block17_12_mixed (Concatenate) (None, None, None, 0 ['activation_120[0][0]', \n", + " 384) 'activation_123[0][0]'] \n", + " \n", + " block17_12_conv (Conv2D) (None, None, None, 418880 ['block17_12_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_12 (Lambda) (None, None, None, 0 ['block17_11_ac[0][0]', \n", + " 1088) 'block17_12_conv[0][0]'] \n", + " \n", + " block17_12_ac (Activation) (None, None, None, 0 ['block17_12[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_125 (Conv2D) (None, None, None, 139264 ['block17_12_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_125 (Batch (None, None, None, 384 ['conv2d_125[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_125 (Activation) (None, None, None, 0 ['batch_normalization_125[0][0]']\n", + " 128) \n", + " \n", + " conv2d_126 (Conv2D) (None, None, None, 143360 ['activation_125[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_126 (Batch (None, None, None, 480 ['conv2d_126[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_126 (Activation) (None, None, None, 0 ['batch_normalization_126[0][0]']\n", + " 160) \n", + " \n", + " conv2d_124 (Conv2D) (None, None, None, 208896 ['block17_12_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_127 (Conv2D) (None, None, None, 215040 ['activation_126[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_124 (Batch (None, None, None, 576 ['conv2d_124[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_127 (Batch (None, None, None, 576 ['conv2d_127[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_124 (Activation) (None, None, None, 0 ['batch_normalization_124[0][0]']\n", + " 192) \n", + " \n", + " activation_127 (Activation) (None, None, None, 0 ['batch_normalization_127[0][0]']\n", + " 192) \n", + " \n", + " block17_13_mixed (Concatenate) (None, None, None, 0 ['activation_124[0][0]', \n", + " 384) 'activation_127[0][0]'] \n", + " \n", + " block17_13_conv (Conv2D) (None, None, None, 418880 ['block17_13_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_13 (Lambda) (None, None, None, 0 ['block17_12_ac[0][0]', \n", + " 1088) 'block17_13_conv[0][0]'] \n", + " \n", + " block17_13_ac (Activation) (None, None, None, 0 ['block17_13[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_129 (Conv2D) (None, None, None, 139264 ['block17_13_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_129 (Batch (None, None, None, 384 ['conv2d_129[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_129 (Activation) (None, None, None, 0 ['batch_normalization_129[0][0]']\n", + " 128) \n", + " \n", + " conv2d_130 (Conv2D) (None, None, None, 143360 ['activation_129[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_130 (Batch (None, None, None, 480 ['conv2d_130[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_130 (Activation) (None, None, None, 0 ['batch_normalization_130[0][0]']\n", + " 160) \n", + " \n", + " conv2d_128 (Conv2D) (None, None, None, 208896 ['block17_13_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_131 (Conv2D) (None, None, None, 215040 ['activation_130[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_128 (Batch (None, None, None, 576 ['conv2d_128[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_131 (Batch (None, None, None, 576 ['conv2d_131[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_128 (Activation) (None, None, None, 0 ['batch_normalization_128[0][0]']\n", + " 192) \n", + " \n", + " activation_131 (Activation) (None, None, None, 0 ['batch_normalization_131[0][0]']\n", + " 192) \n", + " \n", + " block17_14_mixed (Concatenate) (None, None, None, 0 ['activation_128[0][0]', \n", + " 384) 'activation_131[0][0]'] \n", + " \n", + " block17_14_conv (Conv2D) (None, None, None, 418880 ['block17_14_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_14 (Lambda) (None, None, None, 0 ['block17_13_ac[0][0]', \n", + " 1088) 'block17_14_conv[0][0]'] \n", + " \n", + " block17_14_ac (Activation) (None, None, None, 0 ['block17_14[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_133 (Conv2D) (None, None, None, 139264 ['block17_14_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_133 (Batch (None, None, None, 384 ['conv2d_133[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_133 (Activation) (None, None, None, 0 ['batch_normalization_133[0][0]']\n", + " 128) \n", + " \n", + " conv2d_134 (Conv2D) (None, None, None, 143360 ['activation_133[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_134 (Batch (None, None, None, 480 ['conv2d_134[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_134 (Activation) (None, None, None, 0 ['batch_normalization_134[0][0]']\n", + " 160) \n", + " \n", + " conv2d_132 (Conv2D) (None, None, None, 208896 ['block17_14_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_135 (Conv2D) (None, None, None, 215040 ['activation_134[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_132 (Batch (None, None, None, 576 ['conv2d_132[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_135 (Batch (None, None, None, 576 ['conv2d_135[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_132 (Activation) (None, None, None, 0 ['batch_normalization_132[0][0]']\n", + " 192) \n", + " \n", + " activation_135 (Activation) (None, None, None, 0 ['batch_normalization_135[0][0]']\n", + " 192) \n", + " \n", + " block17_15_mixed (Concatenate) (None, None, None, 0 ['activation_132[0][0]', \n", + " 384) 'activation_135[0][0]'] \n", + " \n", + " block17_15_conv (Conv2D) (None, None, None, 418880 ['block17_15_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_15 (Lambda) (None, None, None, 0 ['block17_14_ac[0][0]', \n", + " 1088) 'block17_15_conv[0][0]'] \n", + " \n", + " block17_15_ac (Activation) (None, None, None, 0 ['block17_15[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_137 (Conv2D) (None, None, None, 139264 ['block17_15_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_137 (Batch (None, None, None, 384 ['conv2d_137[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_137 (Activation) (None, None, None, 0 ['batch_normalization_137[0][0]']\n", + " 128) \n", + " \n", + " conv2d_138 (Conv2D) (None, None, None, 143360 ['activation_137[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_138 (Batch (None, None, None, 480 ['conv2d_138[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_138 (Activation) (None, None, None, 0 ['batch_normalization_138[0][0]']\n", + " 160) \n", + " \n", + " conv2d_136 (Conv2D) (None, None, None, 208896 ['block17_15_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_139 (Conv2D) (None, None, None, 215040 ['activation_138[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_136 (Batch (None, None, None, 576 ['conv2d_136[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_139 (Batch (None, None, None, 576 ['conv2d_139[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_136 (Activation) (None, None, None, 0 ['batch_normalization_136[0][0]']\n", + " 192) \n", + " \n", + " activation_139 (Activation) (None, None, None, 0 ['batch_normalization_139[0][0]']\n", + " 192) \n", + " \n", + " block17_16_mixed (Concatenate) (None, None, None, 0 ['activation_136[0][0]', \n", + " 384) 'activation_139[0][0]'] \n", + " \n", + " block17_16_conv (Conv2D) (None, None, None, 418880 ['block17_16_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_16 (Lambda) (None, None, None, 0 ['block17_15_ac[0][0]', \n", + " 1088) 'block17_16_conv[0][0]'] \n", + " \n", + " block17_16_ac (Activation) (None, None, None, 0 ['block17_16[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_141 (Conv2D) (None, None, None, 139264 ['block17_16_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_141 (Batch (None, None, None, 384 ['conv2d_141[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_141 (Activation) (None, None, None, 0 ['batch_normalization_141[0][0]']\n", + " 128) \n", + " \n", + " conv2d_142 (Conv2D) (None, None, None, 143360 ['activation_141[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_142 (Batch (None, None, None, 480 ['conv2d_142[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_142 (Activation) (None, None, None, 0 ['batch_normalization_142[0][0]']\n", + " 160) \n", + " \n", + " conv2d_140 (Conv2D) (None, None, None, 208896 ['block17_16_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_143 (Conv2D) (None, None, None, 215040 ['activation_142[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_140 (Batch (None, None, None, 576 ['conv2d_140[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_143 (Batch (None, None, None, 576 ['conv2d_143[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_140 (Activation) (None, None, None, 0 ['batch_normalization_140[0][0]']\n", + " 192) \n", + " \n", + " activation_143 (Activation) (None, None, None, 0 ['batch_normalization_143[0][0]']\n", + " 192) \n", + " \n", + " block17_17_mixed (Concatenate) (None, None, None, 0 ['activation_140[0][0]', \n", + " 384) 'activation_143[0][0]'] \n", + " \n", + " block17_17_conv (Conv2D) (None, None, None, 418880 ['block17_17_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_17 (Lambda) (None, None, None, 0 ['block17_16_ac[0][0]', \n", + " 1088) 'block17_17_conv[0][0]'] \n", + " \n", + " block17_17_ac (Activation) (None, None, None, 0 ['block17_17[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_145 (Conv2D) (None, None, None, 139264 ['block17_17_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_145 (Batch (None, None, None, 384 ['conv2d_145[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_145 (Activation) (None, None, None, 0 ['batch_normalization_145[0][0]']\n", + " 128) \n", + " \n", + " conv2d_146 (Conv2D) (None, None, None, 143360 ['activation_145[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_146 (Batch (None, None, None, 480 ['conv2d_146[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_146 (Activation) (None, None, None, 0 ['batch_normalization_146[0][0]']\n", + " 160) \n", + " \n", + " conv2d_144 (Conv2D) (None, None, None, 208896 ['block17_17_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_147 (Conv2D) (None, None, None, 215040 ['activation_146[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_144 (Batch (None, None, None, 576 ['conv2d_144[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_147 (Batch (None, None, None, 576 ['conv2d_147[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_144 (Activation) (None, None, None, 0 ['batch_normalization_144[0][0]']\n", + " 192) \n", + " \n", + " activation_147 (Activation) (None, None, None, 0 ['batch_normalization_147[0][0]']\n", + " 192) \n", + " \n", + " block17_18_mixed (Concatenate) (None, None, None, 0 ['activation_144[0][0]', \n", + " 384) 'activation_147[0][0]'] \n", + " \n", + " block17_18_conv (Conv2D) (None, None, None, 418880 ['block17_18_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_18 (Lambda) (None, None, None, 0 ['block17_17_ac[0][0]', \n", + " 1088) 'block17_18_conv[0][0]'] \n", + " \n", + " block17_18_ac (Activation) (None, None, None, 0 ['block17_18[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_149 (Conv2D) (None, None, None, 139264 ['block17_18_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_149 (Batch (None, None, None, 384 ['conv2d_149[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_149 (Activation) (None, None, None, 0 ['batch_normalization_149[0][0]']\n", + " 128) \n", + " \n", + " conv2d_150 (Conv2D) (None, None, None, 143360 ['activation_149[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_150 (Batch (None, None, None, 480 ['conv2d_150[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_150 (Activation) (None, None, None, 0 ['batch_normalization_150[0][0]']\n", + " 160) \n", + " \n", + " conv2d_148 (Conv2D) (None, None, None, 208896 ['block17_18_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_151 (Conv2D) (None, None, None, 215040 ['activation_150[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_148 (Batch (None, None, None, 576 ['conv2d_148[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_151 (Batch (None, None, None, 576 ['conv2d_151[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_148 (Activation) (None, None, None, 0 ['batch_normalization_148[0][0]']\n", + " 192) \n", + " \n", + " activation_151 (Activation) (None, None, None, 0 ['batch_normalization_151[0][0]']\n", + " 192) \n", + " \n", + " block17_19_mixed (Concatenate) (None, None, None, 0 ['activation_148[0][0]', \n", + " 384) 'activation_151[0][0]'] \n", + " \n", + " block17_19_conv (Conv2D) (None, None, None, 418880 ['block17_19_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_19 (Lambda) (None, None, None, 0 ['block17_18_ac[0][0]', \n", + " 1088) 'block17_19_conv[0][0]'] \n", + " \n", + " block17_19_ac (Activation) (None, None, None, 0 ['block17_19[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_153 (Conv2D) (None, None, None, 139264 ['block17_19_ac[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization_153 (Batch (None, None, None, 384 ['conv2d_153[0][0]'] \n", + " Normalization) 128) \n", + " \n", + " activation_153 (Activation) (None, None, None, 0 ['batch_normalization_153[0][0]']\n", + " 128) \n", + " \n", + " conv2d_154 (Conv2D) (None, None, None, 143360 ['activation_153[0][0]'] \n", + " 160) \n", + " \n", + " batch_normalization_154 (Batch (None, None, None, 480 ['conv2d_154[0][0]'] \n", + " Normalization) 160) \n", + " \n", + " activation_154 (Activation) (None, None, None, 0 ['batch_normalization_154[0][0]']\n", + " 160) \n", + " \n", + " conv2d_152 (Conv2D) (None, None, None, 208896 ['block17_19_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_155 (Conv2D) (None, None, None, 215040 ['activation_154[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_152 (Batch (None, None, None, 576 ['conv2d_152[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_155 (Batch (None, None, None, 576 ['conv2d_155[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_152 (Activation) (None, None, None, 0 ['batch_normalization_152[0][0]']\n", + " 192) \n", + " \n", + " activation_155 (Activation) (None, None, None, 0 ['batch_normalization_155[0][0]']\n", + " 192) \n", + " \n", + " block17_20_mixed (Concatenate) (None, None, None, 0 ['activation_152[0][0]', \n", + " 384) 'activation_155[0][0]'] \n", + " \n", + " block17_20_conv (Conv2D) (None, None, None, 418880 ['block17_20_mixed[0][0]'] \n", + " 1088) \n", + " \n", + " block17_20 (Lambda) (None, None, None, 0 ['block17_19_ac[0][0]', \n", + " 1088) 'block17_20_conv[0][0]'] \n", + " \n", + " block17_20_ac (Activation) (None, None, None, 0 ['block17_20[0][0]'] \n", + " 1088) \n", + " \n", + " conv2d_160 (Conv2D) (None, None, None, 278528 ['block17_20_ac[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_160 (Batch (None, None, None, 768 ['conv2d_160[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " activation_160 (Activation) (None, None, None, 0 ['batch_normalization_160[0][0]']\n", + " 256) \n", + " \n", + " conv2d_156 (Conv2D) (None, None, None, 278528 ['block17_20_ac[0][0]'] \n", + " 256) \n", + " \n", + " conv2d_158 (Conv2D) (None, None, None, 278528 ['block17_20_ac[0][0]'] \n", + " 256) \n", + " \n", + " conv2d_161 (Conv2D) (None, None, None, 663552 ['activation_160[0][0]'] \n", + " 288) \n", + " \n", + " batch_normalization_156 (Batch (None, None, None, 768 ['conv2d_156[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " batch_normalization_158 (Batch (None, None, None, 768 ['conv2d_158[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " batch_normalization_161 (Batch (None, None, None, 864 ['conv2d_161[0][0]'] \n", + " Normalization) 288) \n", + " \n", + " activation_156 (Activation) (None, None, None, 0 ['batch_normalization_156[0][0]']\n", + " 256) \n", + " \n", + " activation_158 (Activation) (None, None, None, 0 ['batch_normalization_158[0][0]']\n", + " 256) \n", + " \n", + " activation_161 (Activation) (None, None, None, 0 ['batch_normalization_161[0][0]']\n", + " 288) \n", + " \n", + " conv2d_157 (Conv2D) (None, None, None, 884736 ['activation_156[0][0]'] \n", + " 384) \n", + " \n", + " conv2d_159 (Conv2D) (None, None, None, 663552 ['activation_158[0][0]'] \n", + " 288) \n", + " \n", + " conv2d_162 (Conv2D) (None, None, None, 829440 ['activation_161[0][0]'] \n", + " 320) \n", + " \n", + " batch_normalization_157 (Batch (None, None, None, 1152 ['conv2d_157[0][0]'] \n", + " Normalization) 384) \n", + " \n", + " batch_normalization_159 (Batch (None, None, None, 864 ['conv2d_159[0][0]'] \n", + " Normalization) 288) \n", + " \n", + " batch_normalization_162 (Batch (None, None, None, 960 ['conv2d_162[0][0]'] \n", + " Normalization) 320) \n", + " \n", + " activation_157 (Activation) (None, None, None, 0 ['batch_normalization_157[0][0]']\n", + " 384) \n", + " \n", + " activation_159 (Activation) (None, None, None, 0 ['batch_normalization_159[0][0]']\n", + " 288) \n", + " \n", + " activation_162 (Activation) (None, None, None, 0 ['batch_normalization_162[0][0]']\n", + " 320) \n", + " \n", + " max_pooling2d_3 (MaxPooling2D) (None, None, None, 0 ['block17_20_ac[0][0]'] \n", + " 1088) \n", + " \n", + " mixed_7a (Concatenate) (None, None, None, 0 ['activation_157[0][0]', \n", + " 2080) 'activation_159[0][0]', \n", + " 'activation_162[0][0]', \n", + " 'max_pooling2d_3[0][0]'] \n", + " \n", + " conv2d_164 (Conv2D) (None, None, None, 399360 ['mixed_7a[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_164 (Batch (None, None, None, 576 ['conv2d_164[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_164 (Activation) (None, None, None, 0 ['batch_normalization_164[0][0]']\n", + " 192) \n", + " \n", + " conv2d_165 (Conv2D) (None, None, None, 129024 ['activation_164[0][0]'] \n", + " 224) \n", + " \n", + " batch_normalization_165 (Batch (None, None, None, 672 ['conv2d_165[0][0]'] \n", + " Normalization) 224) \n", + " \n", + " activation_165 (Activation) (None, None, None, 0 ['batch_normalization_165[0][0]']\n", + " 224) \n", + " \n", + " conv2d_163 (Conv2D) (None, None, None, 399360 ['mixed_7a[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_166 (Conv2D) (None, None, None, 172032 ['activation_165[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_163 (Batch (None, None, None, 576 ['conv2d_163[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_166 (Batch (None, None, None, 768 ['conv2d_166[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " activation_163 (Activation) (None, None, None, 0 ['batch_normalization_163[0][0]']\n", + " 192) \n", + " \n", + " activation_166 (Activation) (None, None, None, 0 ['batch_normalization_166[0][0]']\n", + " 256) \n", + " \n", + " block8_1_mixed (Concatenate) (None, None, None, 0 ['activation_163[0][0]', \n", + " 448) 'activation_166[0][0]'] \n", + " \n", + " block8_1_conv (Conv2D) (None, None, None, 933920 ['block8_1_mixed[0][0]'] \n", + " 2080) \n", + " \n", + " block8_1 (Lambda) (None, None, None, 0 ['mixed_7a[0][0]', \n", + " 2080) 'block8_1_conv[0][0]'] \n", + " \n", + " block8_1_ac (Activation) (None, None, None, 0 ['block8_1[0][0]'] \n", + " 2080) \n", + " \n", + " conv2d_168 (Conv2D) (None, None, None, 399360 ['block8_1_ac[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_168 (Batch (None, None, None, 576 ['conv2d_168[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_168 (Activation) (None, None, None, 0 ['batch_normalization_168[0][0]']\n", + " 192) \n", + " \n", + " conv2d_169 (Conv2D) (None, None, None, 129024 ['activation_168[0][0]'] \n", + " 224) \n", + " \n", + " batch_normalization_169 (Batch (None, None, None, 672 ['conv2d_169[0][0]'] \n", + " Normalization) 224) \n", + " \n", + " activation_169 (Activation) (None, None, None, 0 ['batch_normalization_169[0][0]']\n", + " 224) \n", + " \n", + " conv2d_167 (Conv2D) (None, None, None, 399360 ['block8_1_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_170 (Conv2D) (None, None, None, 172032 ['activation_169[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_167 (Batch (None, None, None, 576 ['conv2d_167[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_170 (Batch (None, None, None, 768 ['conv2d_170[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " activation_167 (Activation) (None, None, None, 0 ['batch_normalization_167[0][0]']\n", + " 192) \n", + " \n", + " activation_170 (Activation) (None, None, None, 0 ['batch_normalization_170[0][0]']\n", + " 256) \n", + " \n", + " block8_2_mixed (Concatenate) (None, None, None, 0 ['activation_167[0][0]', \n", + " 448) 'activation_170[0][0]'] \n", + " \n", + " block8_2_conv (Conv2D) (None, None, None, 933920 ['block8_2_mixed[0][0]'] \n", + " 2080) \n", + " \n", + " block8_2 (Lambda) (None, None, None, 0 ['block8_1_ac[0][0]', \n", + " 2080) 'block8_2_conv[0][0]'] \n", + " \n", + " block8_2_ac (Activation) (None, None, None, 0 ['block8_2[0][0]'] \n", + " 2080) \n", + " \n", + " conv2d_172 (Conv2D) (None, None, None, 399360 ['block8_2_ac[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_172 (Batch (None, None, None, 576 ['conv2d_172[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_172 (Activation) (None, None, None, 0 ['batch_normalization_172[0][0]']\n", + " 192) \n", + " \n", + " conv2d_173 (Conv2D) (None, None, None, 129024 ['activation_172[0][0]'] \n", + " 224) \n", + " \n", + " batch_normalization_173 (Batch (None, None, None, 672 ['conv2d_173[0][0]'] \n", + " Normalization) 224) \n", + " \n", + " activation_173 (Activation) (None, None, None, 0 ['batch_normalization_173[0][0]']\n", + " 224) \n", + " \n", + " conv2d_171 (Conv2D) (None, None, None, 399360 ['block8_2_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_174 (Conv2D) (None, None, None, 172032 ['activation_173[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_171 (Batch (None, None, None, 576 ['conv2d_171[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_174 (Batch (None, None, None, 768 ['conv2d_174[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " activation_171 (Activation) (None, None, None, 0 ['batch_normalization_171[0][0]']\n", + " 192) \n", + " \n", + " activation_174 (Activation) (None, None, None, 0 ['batch_normalization_174[0][0]']\n", + " 256) \n", + " \n", + " block8_3_mixed (Concatenate) (None, None, None, 0 ['activation_171[0][0]', \n", + " 448) 'activation_174[0][0]'] \n", + " \n", + " block8_3_conv (Conv2D) (None, None, None, 933920 ['block8_3_mixed[0][0]'] \n", + " 2080) \n", + " \n", + " block8_3 (Lambda) (None, None, None, 0 ['block8_2_ac[0][0]', \n", + " 2080) 'block8_3_conv[0][0]'] \n", + " \n", + " block8_3_ac (Activation) (None, None, None, 0 ['block8_3[0][0]'] \n", + " 2080) \n", + " \n", + " conv2d_176 (Conv2D) (None, None, None, 399360 ['block8_3_ac[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_176 (Batch (None, None, None, 576 ['conv2d_176[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_176 (Activation) (None, None, None, 0 ['batch_normalization_176[0][0]']\n", + " 192) \n", + " \n", + " conv2d_177 (Conv2D) (None, None, None, 129024 ['activation_176[0][0]'] \n", + " 224) \n", + " \n", + " batch_normalization_177 (Batch (None, None, None, 672 ['conv2d_177[0][0]'] \n", + " Normalization) 224) \n", + " \n", + " activation_177 (Activation) (None, None, None, 0 ['batch_normalization_177[0][0]']\n", + " 224) \n", + " \n", + " conv2d_175 (Conv2D) (None, None, None, 399360 ['block8_3_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_178 (Conv2D) (None, None, None, 172032 ['activation_177[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_175 (Batch (None, None, None, 576 ['conv2d_175[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_178 (Batch (None, None, None, 768 ['conv2d_178[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " activation_175 (Activation) (None, None, None, 0 ['batch_normalization_175[0][0]']\n", + " 192) \n", + " \n", + " activation_178 (Activation) (None, None, None, 0 ['batch_normalization_178[0][0]']\n", + " 256) \n", + " \n", + " block8_4_mixed (Concatenate) (None, None, None, 0 ['activation_175[0][0]', \n", + " 448) 'activation_178[0][0]'] \n", + " \n", + " block8_4_conv (Conv2D) (None, None, None, 933920 ['block8_4_mixed[0][0]'] \n", + " 2080) \n", + " \n", + " block8_4 (Lambda) (None, None, None, 0 ['block8_3_ac[0][0]', \n", + " 2080) 'block8_4_conv[0][0]'] \n", + " \n", + " block8_4_ac (Activation) (None, None, None, 0 ['block8_4[0][0]'] \n", + " 2080) \n", + " \n", + " conv2d_180 (Conv2D) (None, None, None, 399360 ['block8_4_ac[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_180 (Batch (None, None, None, 576 ['conv2d_180[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_180 (Activation) (None, None, None, 0 ['batch_normalization_180[0][0]']\n", + " 192) \n", + " \n", + " conv2d_181 (Conv2D) (None, None, None, 129024 ['activation_180[0][0]'] \n", + " 224) \n", + " \n", + " batch_normalization_181 (Batch (None, None, None, 672 ['conv2d_181[0][0]'] \n", + " Normalization) 224) \n", + " \n", + " activation_181 (Activation) (None, None, None, 0 ['batch_normalization_181[0][0]']\n", + " 224) \n", + " \n", + " conv2d_179 (Conv2D) (None, None, None, 399360 ['block8_4_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_182 (Conv2D) (None, None, None, 172032 ['activation_181[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_179 (Batch (None, None, None, 576 ['conv2d_179[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_182 (Batch (None, None, None, 768 ['conv2d_182[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " activation_179 (Activation) (None, None, None, 0 ['batch_normalization_179[0][0]']\n", + " 192) \n", + " \n", + " activation_182 (Activation) (None, None, None, 0 ['batch_normalization_182[0][0]']\n", + " 256) \n", + " \n", + " block8_5_mixed (Concatenate) (None, None, None, 0 ['activation_179[0][0]', \n", + " 448) 'activation_182[0][0]'] \n", + " \n", + " block8_5_conv (Conv2D) (None, None, None, 933920 ['block8_5_mixed[0][0]'] \n", + " 2080) \n", + " \n", + " block8_5 (Lambda) (None, None, None, 0 ['block8_4_ac[0][0]', \n", + " 2080) 'block8_5_conv[0][0]'] \n", + " \n", + " block8_5_ac (Activation) (None, None, None, 0 ['block8_5[0][0]'] \n", + " 2080) \n", + " \n", + " conv2d_184 (Conv2D) (None, None, None, 399360 ['block8_5_ac[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_184 (Batch (None, None, None, 576 ['conv2d_184[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_184 (Activation) (None, None, None, 0 ['batch_normalization_184[0][0]']\n", + " 192) \n", + " \n", + " conv2d_185 (Conv2D) (None, None, None, 129024 ['activation_184[0][0]'] \n", + " 224) \n", + " \n", + " batch_normalization_185 (Batch (None, None, None, 672 ['conv2d_185[0][0]'] \n", + " Normalization) 224) \n", + " \n", + " activation_185 (Activation) (None, None, None, 0 ['batch_normalization_185[0][0]']\n", + " 224) \n", + " \n", + " conv2d_183 (Conv2D) (None, None, None, 399360 ['block8_5_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_186 (Conv2D) (None, None, None, 172032 ['activation_185[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_183 (Batch (None, None, None, 576 ['conv2d_183[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_186 (Batch (None, None, None, 768 ['conv2d_186[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " activation_183 (Activation) (None, None, None, 0 ['batch_normalization_183[0][0]']\n", + " 192) \n", + " \n", + " activation_186 (Activation) (None, None, None, 0 ['batch_normalization_186[0][0]']\n", + " 256) \n", + " \n", + " block8_6_mixed (Concatenate) (None, None, None, 0 ['activation_183[0][0]', \n", + " 448) 'activation_186[0][0]'] \n", + " \n", + " block8_6_conv (Conv2D) (None, None, None, 933920 ['block8_6_mixed[0][0]'] \n", + " 2080) \n", + " \n", + " block8_6 (Lambda) (None, None, None, 0 ['block8_5_ac[0][0]', \n", + " 2080) 'block8_6_conv[0][0]'] \n", + " \n", + " block8_6_ac (Activation) (None, None, None, 0 ['block8_6[0][0]'] \n", + " 2080) \n", + " \n", + " conv2d_188 (Conv2D) (None, None, None, 399360 ['block8_6_ac[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_188 (Batch (None, None, None, 576 ['conv2d_188[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_188 (Activation) (None, None, None, 0 ['batch_normalization_188[0][0]']\n", + " 192) \n", + " \n", + " conv2d_189 (Conv2D) (None, None, None, 129024 ['activation_188[0][0]'] \n", + " 224) \n", + " \n", + " batch_normalization_189 (Batch (None, None, None, 672 ['conv2d_189[0][0]'] \n", + " Normalization) 224) \n", + " \n", + " activation_189 (Activation) (None, None, None, 0 ['batch_normalization_189[0][0]']\n", + " 224) \n", + " \n", + " conv2d_187 (Conv2D) (None, None, None, 399360 ['block8_6_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_190 (Conv2D) (None, None, None, 172032 ['activation_189[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_187 (Batch (None, None, None, 576 ['conv2d_187[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_190 (Batch (None, None, None, 768 ['conv2d_190[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " activation_187 (Activation) (None, None, None, 0 ['batch_normalization_187[0][0]']\n", + " 192) \n", + " \n", + " activation_190 (Activation) (None, None, None, 0 ['batch_normalization_190[0][0]']\n", + " 256) \n", + " \n", + " block8_7_mixed (Concatenate) (None, None, None, 0 ['activation_187[0][0]', \n", + " 448) 'activation_190[0][0]'] \n", + " \n", + " block8_7_conv (Conv2D) (None, None, None, 933920 ['block8_7_mixed[0][0]'] \n", + " 2080) \n", + " \n", + " block8_7 (Lambda) (None, None, None, 0 ['block8_6_ac[0][0]', \n", + " 2080) 'block8_7_conv[0][0]'] \n", + " \n", + " block8_7_ac (Activation) (None, None, None, 0 ['block8_7[0][0]'] \n", + " 2080) \n", + " \n", + " conv2d_192 (Conv2D) (None, None, None, 399360 ['block8_7_ac[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_192 (Batch (None, None, None, 576 ['conv2d_192[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_192 (Activation) (None, None, None, 0 ['batch_normalization_192[0][0]']\n", + " 192) \n", + " \n", + " conv2d_193 (Conv2D) (None, None, None, 129024 ['activation_192[0][0]'] \n", + " 224) \n", + " \n", + " batch_normalization_193 (Batch (None, None, None, 672 ['conv2d_193[0][0]'] \n", + " Normalization) 224) \n", + " \n", + " activation_193 (Activation) (None, None, None, 0 ['batch_normalization_193[0][0]']\n", + " 224) \n", + " \n", + " conv2d_191 (Conv2D) (None, None, None, 399360 ['block8_7_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_194 (Conv2D) (None, None, None, 172032 ['activation_193[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_191 (Batch (None, None, None, 576 ['conv2d_191[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_194 (Batch (None, None, None, 768 ['conv2d_194[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " activation_191 (Activation) (None, None, None, 0 ['batch_normalization_191[0][0]']\n", + " 192) \n", + " \n", + " activation_194 (Activation) (None, None, None, 0 ['batch_normalization_194[0][0]']\n", + " 256) \n", + " \n", + " block8_8_mixed (Concatenate) (None, None, None, 0 ['activation_191[0][0]', \n", + " 448) 'activation_194[0][0]'] \n", + " \n", + " block8_8_conv (Conv2D) (None, None, None, 933920 ['block8_8_mixed[0][0]'] \n", + " 2080) \n", + " \n", + " block8_8 (Lambda) (None, None, None, 0 ['block8_7_ac[0][0]', \n", + " 2080) 'block8_8_conv[0][0]'] \n", + " \n", + " block8_8_ac (Activation) (None, None, None, 0 ['block8_8[0][0]'] \n", + " 2080) \n", + " \n", + " conv2d_196 (Conv2D) (None, None, None, 399360 ['block8_8_ac[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_196 (Batch (None, None, None, 576 ['conv2d_196[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_196 (Activation) (None, None, None, 0 ['batch_normalization_196[0][0]']\n", + " 192) \n", + " \n", + " conv2d_197 (Conv2D) (None, None, None, 129024 ['activation_196[0][0]'] \n", + " 224) \n", + " \n", + " batch_normalization_197 (Batch (None, None, None, 672 ['conv2d_197[0][0]'] \n", + " Normalization) 224) \n", + " \n", + " activation_197 (Activation) (None, None, None, 0 ['batch_normalization_197[0][0]']\n", + " 224) \n", + " \n", + " conv2d_195 (Conv2D) (None, None, None, 399360 ['block8_8_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_198 (Conv2D) (None, None, None, 172032 ['activation_197[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_195 (Batch (None, None, None, 576 ['conv2d_195[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_198 (Batch (None, None, None, 768 ['conv2d_198[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " activation_195 (Activation) (None, None, None, 0 ['batch_normalization_195[0][0]']\n", + " 192) \n", + " \n", + " activation_198 (Activation) (None, None, None, 0 ['batch_normalization_198[0][0]']\n", + " 256) \n", + " \n", + " block8_9_mixed (Concatenate) (None, None, None, 0 ['activation_195[0][0]', \n", + " 448) 'activation_198[0][0]'] \n", + " \n", + " block8_9_conv (Conv2D) (None, None, None, 933920 ['block8_9_mixed[0][0]'] \n", + " 2080) \n", + " \n", + " block8_9 (Lambda) (None, None, None, 0 ['block8_8_ac[0][0]', \n", + " 2080) 'block8_9_conv[0][0]'] \n", + " \n", + " block8_9_ac (Activation) (None, None, None, 0 ['block8_9[0][0]'] \n", + " 2080) \n", + " \n", + " conv2d_200 (Conv2D) (None, None, None, 399360 ['block8_9_ac[0][0]'] \n", + " 192) \n", + " \n", + " batch_normalization_200 (Batch (None, None, None, 576 ['conv2d_200[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " activation_200 (Activation) (None, None, None, 0 ['batch_normalization_200[0][0]']\n", + " 192) \n", + " \n", + " conv2d_201 (Conv2D) (None, None, None, 129024 ['activation_200[0][0]'] \n", + " 224) \n", + " \n", + " batch_normalization_201 (Batch (None, None, None, 672 ['conv2d_201[0][0]'] \n", + " Normalization) 224) \n", + " \n", + " activation_201 (Activation) (None, None, None, 0 ['batch_normalization_201[0][0]']\n", + " 224) \n", + " \n", + " conv2d_199 (Conv2D) (None, None, None, 399360 ['block8_9_ac[0][0]'] \n", + " 192) \n", + " \n", + " conv2d_202 (Conv2D) (None, None, None, 172032 ['activation_201[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_199 (Batch (None, None, None, 576 ['conv2d_199[0][0]'] \n", + " Normalization) 192) \n", + " \n", + " batch_normalization_202 (Batch (None, None, None, 768 ['conv2d_202[0][0]'] \n", + " Normalization) 256) \n", + " \n", + " activation_199 (Activation) (None, None, None, 0 ['batch_normalization_199[0][0]']\n", + " 192) \n", + " \n", + " activation_202 (Activation) (None, None, None, 0 ['batch_normalization_202[0][0]']\n", + " 256) \n", + " \n", + " block8_10_mixed (Concatenate) (None, None, None, 0 ['activation_199[0][0]', \n", + " 448) 'activation_202[0][0]'] \n", + " \n", + " block8_10_conv (Conv2D) (None, None, None, 933920 ['block8_10_mixed[0][0]'] \n", + " 2080) \n", + " \n", + " block8_10 (Lambda) (None, None, None, 0 ['block8_9_ac[0][0]', \n", + " 2080) 'block8_10_conv[0][0]'] \n", + " \n", + " conv_7b (Conv2D) (None, None, None, 3194880 ['block8_10[0][0]'] \n", + " 1536) \n", + " \n", + " conv_7b_bn (BatchNormalization (None, None, None, 4608 ['conv_7b[0][0]'] \n", + " ) 1536) \n", + " \n", + " conv_7b_ac (Activation) (None, None, None, 0 ['conv_7b_bn[0][0]'] \n", + " 1536) \n", + " \n", + " global_average_pooling2d (Glob (None, 1536) 0 ['conv_7b_ac[0][0]'] \n", + " alAveragePooling2D) \n", + " \n", + " dense (Dense) (None, 13) 19981 ['global_average_pooling2d[0][0]'\n", + " ] \n", + " \n", + "==================================================================================================\n", + "Total params: 54,356,717\n", + "Trainable params: 54,296,173\n", + "Non-trainable params: 60,544\n", + "__________________________________________________________________________________________________\n" + ] + } + ], + "source": [ + "for layer in base_model.layers:\n", + " layer.trainable = True\n", + " \n", + "output = Dense(13, activation='softmax')(base_model.output)\n", + "model = tf.keras.Model(base_model.input, output)\n", + "#model = add_regularization(model)\n", + "model.summary()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "ea620129", + "metadata": {}, + "outputs": [], + "source": [ + "#model.add(Dropout(.5))\n", + "#model.add(Dense(64, activation='softmax'))\n", + "# model.add(Dropout(.25))\n", + "#model = add_regularization(model)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "fd5d1246", + "metadata": {}, + "outputs": [], + "source": [ + "model.compile(optimizer=Adam(learning_rate=.0001), loss='categorical_crossentropy',\n", + " metrics=['accuracy'])\n", + "# sparse_categorical_crossentropy" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9cd2ba27", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epoch 1/30\n", + "142/142 [==============================] - 71s 426ms/step - loss: 1.5727 - accuracy: 0.4613 - val_loss: 2.5192 - val_accuracy: 0.1233\n", + "Epoch 2/30\n", + "142/142 [==============================] - 56s 395ms/step - loss: 0.6991 - accuracy: 0.7644 - val_loss: 1.9969 - val_accuracy: 0.3568\n", + "Epoch 3/30\n", + "142/142 [==============================] - 56s 395ms/step - loss: 0.2355 - accuracy: 0.9302 - val_loss: 1.9622 - val_accuracy: 0.4626\n", + "Epoch 4/30\n", + "142/142 [==============================] - 56s 393ms/step - loss: 0.1015 - accuracy: 0.9707 - val_loss: 1.8987 - val_accuracy: 0.5207\n", + "Epoch 5/30\n", + "142/142 [==============================] - 57s 398ms/step - loss: 0.0899 - accuracy: 0.9736 - val_loss: 1.8865 - val_accuracy: 0.5727\n", + "Epoch 6/30\n", + "142/142 [==============================] - 57s 402ms/step - loss: 0.0895 - accuracy: 0.9742 - val_loss: 1.9440 - val_accuracy: 0.5419\n", + "Epoch 7/30\n", + "142/142 [==============================] - 58s 406ms/step - loss: 0.0784 - accuracy: 0.9762 - val_loss: 2.2314 - val_accuracy: 0.5145\n", + "Epoch 8/30\n", + "142/142 [==============================] - 58s 406ms/step - loss: 0.0536 - accuracy: 0.9852 - val_loss: 2.0704 - val_accuracy: 0.5480\n", + "Epoch 9/30\n", + "142/142 [==============================] - 57s 399ms/step - loss: 0.0672 - accuracy: 0.9802 - val_loss: 2.3144 - val_accuracy: 0.5189\n", + "Epoch 10/30\n", + "142/142 [==============================] - 56s 395ms/step - loss: 0.0423 - accuracy: 0.9875 - val_loss: 2.2718 - val_accuracy: 0.5330\n", + "Epoch 11/30\n", + "142/142 [==============================] - 57s 400ms/step - loss: 0.0325 - accuracy: 0.9903 - val_loss: 2.2889 - val_accuracy: 0.5498\n", + "Epoch 12/30\n", + "142/142 [==============================] - 56s 396ms/step - loss: 0.0591 - accuracy: 0.9822 - val_loss: 2.1700 - val_accuracy: 0.5577\n", + "Epoch 13/30\n", + "142/142 [==============================] - 56s 395ms/step - loss: 0.0387 - accuracy: 0.9899 - val_loss: 2.3132 - val_accuracy: 0.5410\n", + "Epoch 14/30\n", + " 95/142 [===================>..........] - ETA: 14s - loss: 0.0344 - accuracy: 0.9888" + ] + } + ], + "source": [ + "model.fit(x=train_generator,\n", + " steps_per_epoch=len(train_generator),\n", + " validation_data=validation_generator,\n", + " validation_steps=len(validation_generator),\n", + " epochs=30,\n", + " verbose=1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63f791af", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Shoe Classifier_VGG16.ipynb b/Shoe Classifier_VGG16.ipynb new file mode 100644 index 0000000..19bfd86 --- /dev/null +++ b/Shoe Classifier_VGG16.ipynb @@ -0,0 +1,529 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "572dc7fb", + "metadata": {}, + "outputs": [], + "source": [ + "from matplotlib import pyplot as plt\n", + "from matplotlib.image import imread\n", + "import pandas as pd\n", + "from collections import Counter\n", + "import json\n", + "import os\n", + "import re\n", + "import tempfile\n", + "import numpy as np\n", + "from os.path import exists\n", + "from imblearn.under_sampling import RandomUnderSampler\n", + "from PIL import ImageFile\n", + "import sklearn as sk\n", + "from sklearn.model_selection import train_test_split, StratifiedShuffleSplit\n", + "import tensorflow as tf\n", + "import tensorflow.keras\n", + "from tensorflow.keras.preprocessing.image import ImageDataGenerator\n", + "from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dense, Dropout, Flatten, Activation\n", + "from tensorflow.keras.models import Sequential\n", + "from tensorflow.keras.optimizers import Adam\n", + "# custom modules\n", + "import image_faults\n", + "\n", + "ImageFile.LOAD_TRUNCATED_IMAGES = True" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def add_regularization(model, regularizer=tf.keras.regularizers.l2(0.0001)):\n", + "\n", + " if not isinstance(regularizer, tf.keras.regularizers.Regularizer):\n", + " print(\"Regularizer must be a subclass of tf.keras.regularizers.Regularizer\")\n", + " return model\n", + "\n", + " for layer in model.layers:\n", + " for attr in ['kernel_regularizer']:\n", + " if hasattr(layer, attr):\n", + " setattr(layer, attr, regularizer)\n", + "\n", + " # When we change the layers attributes, the change only happens in the model config file\n", + " model_json = model.to_json()\n", + "\n", + " # Save the weights before reloading the model.\n", + " tmp_weights_path = os.path.join(tempfile.gettempdir(), 'tmp_weights.h5')\n", + " model.save_weights(tmp_weights_path)\n", + "\n", + " # load the model from the config\n", + " model = tf.keras.models.model_from_json(model_json)\n", + " \n", + " # Reload the model weights\n", + " model.load_weights(tmp_weights_path, by_name=True)\n", + " return model" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "a5c72863", + "metadata": {}, + "outputs": [], + "source": [ + "# image_faults.faulty_images() # removes faulty images\n", + "df = pd.read_csv('expanded_class.csv', index_col=[0], low_memory=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "1057a442", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{source:target} dictionary created @ /tf/training_images\n" + ] + } + ], + "source": [ + "def dict_pics():\n", + " target_dir = os.getcwd() + os.sep + \"training_images\"\n", + " with open('temp_pics_source_list.txt') as f:\n", + " temp_pics_source_list = json.load(f)\n", + " dict_pics = {k:target_dir + os.sep + re.search(r'[^/]+(?=/\\$_|.jpg)', k, re.IGNORECASE).group() + '.jpg' for k in temp_pics_source_list}\n", + " print(\"{source:target} dictionary created @ \" + target_dir)\n", + " return dict_pics\n", + "\n", + "dict_pics = dict_pics()\n", + "blah = pd.Series(df.PictureURL)\n", + "df = df.drop(labels=['PictureURL'], axis=1)\n", + "blah = blah.apply(lambda x: dict_pics[x])\n", + "df = pd.concat([blah, df],axis=1)\n", + "df = df.groupby('PrimaryCategoryID').filter(lambda x: len(x)>25) # removes cat outliers\n", + "# removes non-existent image paths" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "7a6146e6", + "metadata": {}, + "outputs": [], + "source": [ + "df['PrimaryCategoryID'] = df['PrimaryCategoryID'].astype(str) # pandas thinks ids are ints\n", + "\n", + "df=df.sample(frac=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Counter({'11498': 546, '11504': 546, '11505': 546, '11632': 546, '15709': 546, '24087': 546, '45333': 546, '53120': 546, '53548': 546, '53557': 546, '55793': 546, '62107': 546, '95672': 546})\n" + ] + } + ], + "source": [ + "undersample = RandomUnderSampler(sampling_strategy='auto')\n", + "train, y_under = undersample.fit_resample(df, df['PrimaryCategoryID'])\n", + "print(Counter(train['PrimaryCategoryID']))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "506aa5cf", + "metadata": {}, + "outputs": [], + "source": [ + "train, test = train_test_split(train, test_size=0.2, random_state=42)\n", + "# stratify=train['PrimaryCategoryID']\n", + "# train['PrimaryCategoryID'].value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "4d72eb90", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found 4542 validated image filenames belonging to 13 classes.\n", + "Found 1135 validated image filenames belonging to 13 classes.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.8/dist-packages/keras_preprocessing/image/dataframe_iterator.py:279: UserWarning: Found 1 invalid image filename(s) in x_col=\"PictureURL\". These filename(s) will be ignored.\n", + " warnings.warn(\n" + ] + } + ], + "source": [ + "datagen = ImageDataGenerator(rescale=1./255., \n", + " validation_split=.2,\n", + " #samplewise_std_normalization=True,\n", + " #horizontal_flip= True,\n", + " #vertical_flip= True,\n", + " #width_shift_range= 0.2,\n", + " #height_shift_range= 0.2,\n", + " #rotation_range= 90,\n", + " preprocessing_function=tf.keras.applications.vgg16.preprocess_input)\n", + "train_generator=datagen.flow_from_dataframe(\n", + " dataframe=train[:len(train)],\n", + " directory='./training_images',\n", + " x_col='PictureURL',\n", + " y_col='PrimaryCategoryID',\n", + " batch_size=32,\n", + " seed=42,\n", + " shuffle=True,\n", + " target_size=(244,244),\n", + " subset='training'\n", + " )\n", + "validation_generator=datagen.flow_from_dataframe(\n", + " dataframe=train[:len(train)], # is using train right?\n", + " directory='./training_images',\n", + " x_col='PictureURL',\n", + " y_col='PrimaryCategoryID',\n", + " batch_size=32,\n", + " seed=42,\n", + " shuffle=True,\n", + " target_size=(244,244),\n", + " subset='validation'\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "7b70f37f", + "metadata": {}, + "outputs": [], + "source": [ + "imgs, labels = next(train_generator)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "1ed54bf5", + "metadata": {}, + "outputs": [], + "source": [ + "def plotImages(images_arr):\n", + " fig, axes = plt.subplots(1, 10, figsize=(20,20))\n", + " axes = axes.flatten()\n", + " for img, ax in zip( images_arr, axes):\n", + " ax.imshow(img)\n", + " ax.axis('off')\n", + " plt.tight_layout()\n", + " plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "85934565", + "metadata": {}, + "outputs": [], + "source": [ + "#plotImages(imgs)\n", + "#print(labels)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "6322bcad", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ], + "source": [ + "physical_devices = tf.config.list_physical_devices('GPU')\n", + "print(len(physical_devices))\n", + "tf.config.experimental.set_memory_growth(physical_devices[0], True)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "b31af79e", + "metadata": {}, + "outputs": [], + "source": [ + "base_model = tf.keras.applications.vgg16.VGG16(weights='imagenet')" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "fe06f2bf", + "metadata": {}, + "outputs": [], + "source": [ + "#model = Sequential()\n", + "#for layer in base_model.layers[:-1]:\n", + "# model.add(layer)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "7d3cc82c", + "metadata": {}, + "outputs": [], + "source": [ + "# loop through layers, add Dropout after layers 'fc1' and 'fc2'\n", + "updated_model = Sequential()\n", + "for layer in base_model.layers[:-1]:\n", + " updated_model.add(layer)\n", + " if layer.name in ['fc1', 'fc2']:\n", + " updated_model.add(Dropout(.75))\n", + "\n", + "model = updated_model\n", + "\n", + "for layer in model.layers:\n", + " layer.trainable = True\n", + "\n", + "model.add(Dense(units=13, activation='softmax'))" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "c774d787", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Model: \"sequential\"\n", + "_________________________________________________________________\n", + " Layer (type) Output Shape Param # \n", + "=================================================================\n", + " block1_conv1 (Conv2D) (None, 224, 224, 64) 1792 \n", + " \n", + " block1_conv2 (Conv2D) (None, 224, 224, 64) 36928 \n", + " \n", + " block1_pool (MaxPooling2D) (None, 112, 112, 64) 0 \n", + " \n", + " block2_conv1 (Conv2D) (None, 112, 112, 128) 73856 \n", + " \n", + " block2_conv2 (Conv2D) (None, 112, 112, 128) 147584 \n", + " \n", + " block2_pool (MaxPooling2D) (None, 56, 56, 128) 0 \n", + " \n", + " block3_conv1 (Conv2D) (None, 56, 56, 256) 295168 \n", + " \n", + " block3_conv2 (Conv2D) (None, 56, 56, 256) 590080 \n", + " \n", + " block3_conv3 (Conv2D) (None, 56, 56, 256) 590080 \n", + " \n", + " block3_pool (MaxPooling2D) (None, 28, 28, 256) 0 \n", + " \n", + " block4_conv1 (Conv2D) (None, 28, 28, 512) 1180160 \n", + " \n", + " block4_conv2 (Conv2D) (None, 28, 28, 512) 2359808 \n", + " \n", + " block4_conv3 (Conv2D) (None, 28, 28, 512) 2359808 \n", + " \n", + " block4_pool (MaxPooling2D) (None, 14, 14, 512) 0 \n", + " \n", + " block5_conv1 (Conv2D) (None, 14, 14, 512) 2359808 \n", + " \n", + " block5_conv2 (Conv2D) (None, 14, 14, 512) 2359808 \n", + " \n", + " block5_conv3 (Conv2D) (None, 14, 14, 512) 2359808 \n", + " \n", + " block5_pool (MaxPooling2D) (None, 7, 7, 512) 0 \n", + " \n", + " flatten (Flatten) (None, 25088) 0 \n", + " \n", + " fc1 (Dense) (None, 4096) 102764544 \n", + " \n", + " dropout (Dropout) (None, 4096) 0 \n", + " \n", + " fc2 (Dense) (None, 4096) 16781312 \n", + " \n", + " dropout_1 (Dropout) (None, 4096) 0 \n", + " \n", + " dense (Dense) (None, 13) 53261 \n", + " \n", + "=================================================================\n", + "Total params: 134,313,805\n", + "Trainable params: 134,313,805\n", + "Non-trainable params: 0\n", + "_________________________________________________________________\n" + ] + } + ], + "source": [ + "#model = add_regularization(model)\n", + "model.summary()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "fd5d1246", + "metadata": {}, + "outputs": [], + "source": [ + "model.compile(optimizer=Adam(learning_rate=.0001), loss='categorical_crossentropy',\n", + " metrics=['accuracy'])" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "9cd2ba27", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epoch 1/30\n", + "142/142 [==============================] - 62s 404ms/step - loss: 2.7986 - accuracy: 0.0771 - val_loss: 2.5716 - val_accuracy: 0.0670\n", + "Epoch 2/30\n", + "142/142 [==============================] - 53s 370ms/step - loss: 2.6351 - accuracy: 0.0790 - val_loss: 2.5728 - val_accuracy: 0.0802\n", + "Epoch 3/30\n", + "142/142 [==============================] - 53s 370ms/step - loss: 2.6157 - accuracy: 0.0852 - val_loss: 2.5786 - val_accuracy: 0.0705\n", + "Epoch 4/30\n", + "142/142 [==============================] - 53s 371ms/step - loss: 2.6087 - accuracy: 0.0821 - val_loss: 2.5501 - val_accuracy: 0.1013\n", + "Epoch 5/30\n", + "142/142 [==============================] - 53s 371ms/step - loss: 2.5420 - accuracy: 0.1182 - val_loss: 2.4237 - val_accuracy: 0.1401\n", + "Epoch 6/30\n", + "142/142 [==============================] - 52s 368ms/step - loss: 2.4275 - accuracy: 0.1640 - val_loss: 2.3050 - val_accuracy: 0.1982\n", + "Epoch 7/30\n", + "142/142 [==============================] - 52s 368ms/step - loss: 2.3270 - accuracy: 0.2008 - val_loss: 2.2103 - val_accuracy: 0.2273\n", + "Epoch 8/30\n", + "142/142 [==============================] - 54s 378ms/step - loss: 2.2011 - accuracy: 0.2294 - val_loss: 2.0607 - val_accuracy: 0.2872\n", + "Epoch 9/30\n", + "142/142 [==============================] - 54s 378ms/step - loss: 2.0790 - accuracy: 0.2781 - val_loss: 1.9376 - val_accuracy: 0.3419\n", + "Epoch 10/30\n", + "142/142 [==============================] - 52s 368ms/step - loss: 1.8708 - accuracy: 0.3417 - val_loss: 2.0407 - val_accuracy: 0.3198\n", + "Epoch 11/30\n", + "142/142 [==============================] - 52s 368ms/step - loss: 1.7588 - accuracy: 0.3743 - val_loss: 1.8968 - val_accuracy: 0.3401\n", + "Epoch 12/30\n", + "142/142 [==============================] - 52s 369ms/step - loss: 1.5927 - accuracy: 0.4251 - val_loss: 1.8735 - val_accuracy: 0.3542\n", + "Epoch 13/30\n", + "142/142 [==============================] - 53s 369ms/step - loss: 1.4704 - accuracy: 0.4626 - val_loss: 1.8489 - val_accuracy: 0.3753\n", + "Epoch 14/30\n", + "142/142 [==============================] - 52s 367ms/step - loss: 1.2452 - accuracy: 0.5484 - val_loss: 1.9595 - val_accuracy: 0.3656\n", + "Epoch 15/30\n", + "142/142 [==============================] - 52s 370ms/step - loss: 1.1410 - accuracy: 0.5885 - val_loss: 1.9159 - val_accuracy: 0.3930\n", + "Epoch 16/30\n", + "142/142 [==============================] - 52s 367ms/step - loss: 0.9705 - accuracy: 0.6510 - val_loss: 2.1161 - val_accuracy: 0.3921\n", + "Epoch 17/30\n", + "142/142 [==============================] - 52s 368ms/step - loss: 0.7992 - accuracy: 0.7041 - val_loss: 2.1271 - val_accuracy: 0.4097\n", + "Epoch 18/30\n", + "142/142 [==============================] - 52s 369ms/step - loss: 0.7544 - accuracy: 0.7305 - val_loss: 2.0093 - val_accuracy: 0.4361\n", + "Epoch 19/30\n", + "142/142 [==============================] - 52s 367ms/step - loss: 0.5651 - accuracy: 0.7961 - val_loss: 2.4199 - val_accuracy: 0.3850\n", + "Epoch 20/30\n", + "142/142 [==============================] - 52s 366ms/step - loss: 0.4566 - accuracy: 0.8342 - val_loss: 2.4058 - val_accuracy: 0.4352\n", + "Epoch 21/30\n", + "142/142 [==============================] - 52s 364ms/step - loss: 0.3841 - accuracy: 0.8622 - val_loss: 2.5407 - val_accuracy: 0.4141\n", + "Epoch 22/30\n", + "142/142 [==============================] - 52s 366ms/step - loss: 0.2496 - accuracy: 0.9086 - val_loss: 3.0696 - val_accuracy: 0.4088\n", + "Epoch 23/30\n", + "142/142 [==============================] - 52s 368ms/step - loss: 0.2847 - accuracy: 0.8985 - val_loss: 2.7929 - val_accuracy: 0.4273\n", + "Epoch 24/30\n", + "142/142 [==============================] - 52s 369ms/step - loss: 0.2035 - accuracy: 0.9293 - val_loss: 3.0300 - val_accuracy: 0.4132\n", + "Epoch 25/30\n", + "142/142 [==============================] - ETA: 0s - loss: 0.1872 - accuracy: 0.9377" + ] + }, + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m model.fit(x=train_generator,\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_generator\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[1;32m 3\u001b[0m \u001b[0mvalidation_data\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mvalidation_generator\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mvalidation_steps\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalidation_generator\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[1;32m 5\u001b[0m \u001b[0mepochs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m30\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 64\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 65\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# pylint: disable=broad-except\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 66\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_process_traceback_frames\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__traceback__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/engine/training.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)\u001b[0m\n\u001b[1;32m 1250\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1251\u001b[0m steps_per_execution=self._steps_per_execution)\n\u001b[0;32m-> 1252\u001b[0;31m val_logs = self.evaluate(\n\u001b[0m\u001b[1;32m 1253\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mval_x\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1254\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mval_y\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 64\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 65\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# pylint: disable=broad-except\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 66\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_process_traceback_frames\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__traceback__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/engine/training.py\u001b[0m in \u001b[0;36mevaluate\u001b[0;34m(self, x, y, batch_size, verbose, sample_weight, steps, callbacks, max_queue_size, workers, use_multiprocessing, return_dict, **kwargs)\u001b[0m\n\u001b[1;32m 1535\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprofiler\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexperimental\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTrace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'test'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstep_num\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstep\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_r\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\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[1;32m 1536\u001b[0m \u001b[0mcallbacks\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_test_batch_begin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstep\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1537\u001b[0;31m \u001b[0mtmp_logs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtest_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterator\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 1538\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mdata_handler\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshould_sync\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1539\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masync_wait\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[0;32m/usr/local/lib/python3.8/dist-packages/tensorflow/python/util/traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 148\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 149\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 150\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 151\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 152\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_process_traceback_frames\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__traceback__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/def_function.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *args, **kwds)\u001b[0m\n\u001b[1;32m 908\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 909\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mOptionalXlaContext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_jit_compile\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[0;32m--> 910\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\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 911\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 912\u001b[0m \u001b[0mnew_tracing_count\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexperimental_get_tracing_count\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[0;32m/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/def_function.py\u001b[0m in \u001b[0;36m_call\u001b[0;34m(self, *args, **kwds)\u001b[0m\n\u001b[1;32m 947\u001b[0m \u001b[0;31m# In this case we have not created variables on the first call. So we can\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 948\u001b[0m \u001b[0;31m# run the first trace but we should fail if variables are created.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 949\u001b[0;31m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_stateful_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\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 950\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_created_variables\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mALLOW_DYNAMIC_VARIABLE_CREATION\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 951\u001b[0m raise ValueError(\"Creating variables on a non-first call to a function\"\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/function.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 3128\u001b[0m (graph_function,\n\u001b[1;32m 3129\u001b[0m filtered_flat_args) = self._maybe_define_function(args, kwargs)\n\u001b[0;32m-> 3130\u001b[0;31m return graph_function._call_flat(\n\u001b[0m\u001b[1;32m 3131\u001b[0m filtered_flat_args, captured_inputs=graph_function.captured_inputs) # pylint: disable=protected-access\n\u001b[1;32m 3132\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/function.py\u001b[0m in \u001b[0;36m_call_flat\u001b[0;34m(self, args, captured_inputs, cancellation_manager)\u001b[0m\n\u001b[1;32m 1957\u001b[0m and executing_eagerly):\n\u001b[1;32m 1958\u001b[0m \u001b[0;31m# No tape is watching; skip to running the function.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1959\u001b[0;31m return self._build_call_outputs(self._inference_function.call(\n\u001b[0m\u001b[1;32m 1960\u001b[0m ctx, args, cancellation_manager=cancellation_manager))\n\u001b[1;32m 1961\u001b[0m forward_backward = self._select_forward_and_backward_functions(\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/function.py\u001b[0m in \u001b[0;36mcall\u001b[0;34m(self, ctx, args, cancellation_manager)\u001b[0m\n\u001b[1;32m 596\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0m_InterpolateFunctionError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\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[1;32m 597\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcancellation_manager\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 598\u001b[0;31m outputs = execute.execute(\n\u001b[0m\u001b[1;32m 599\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msignature\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\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[1;32m 600\u001b[0m \u001b[0mnum_outputs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_num_outputs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/execute.py\u001b[0m in \u001b[0;36mquick_execute\u001b[0;34m(op_name, num_outputs, inputs, attrs, ctx, name)\u001b[0m\n\u001b[1;32m 56\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 57\u001b[0m \u001b[0mctx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mensure_initialized\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[0;32m---> 58\u001b[0;31m tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,\n\u001b[0m\u001b[1;32m 59\u001b[0m inputs, attrs, num_outputs)\n\u001b[1;32m 60\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mcore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_NotOkStatusException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], + "source": [ + "model.fit(x=train_generator,\n", + " steps_per_epoch=len(train_generator),\n", + " validation_data=validation_generator,\n", + " validation_steps=len(validation_generator),\n", + " epochs=30,\n", + " verbose=1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63f791af", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Shoe Classifier.ipynb b/Shoe Classifier_VGG19.ipynb similarity index 66% rename from Shoe Classifier.ipynb rename to Shoe Classifier_VGG19.ipynb index e3b82fe..baac84d 100644 --- a/Shoe Classifier.ipynb +++ b/Shoe Classifier_VGG19.ipynb @@ -10,13 +10,17 @@ "from matplotlib import pyplot as plt\n", "from matplotlib.image import imread\n", "import pandas as pd\n", + "from collections import Counter\n", "import json\n", "import os\n", "import re\n", + "import tempfile\n", "import numpy as np\n", "from os.path import exists\n", + "from imblearn.under_sampling import RandomUnderSampler\n", "from PIL import ImageFile\n", - "#import sklearn as sk\n", + "import sklearn as sk\n", + "from sklearn.model_selection import train_test_split, StratifiedShuffleSplit\n", "import tensorflow as tf\n", "import tensorflow.keras\n", "from tensorflow.keras.preprocessing.image import ImageDataGenerator\n", @@ -32,6 +36,38 @@ { "cell_type": "code", "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def add_regularization(model, regularizer=tf.keras.regularizers.l2(0.0001)):\n", + "\n", + " if not isinstance(regularizer, tf.keras.regularizers.Regularizer):\n", + " print(\"Regularizer must be a subclass of tf.keras.regularizers.Regularizer\")\n", + " return model\n", + "\n", + " for layer in model.layers:\n", + " for attr in ['kernel_regularizer']:\n", + " if hasattr(layer, attr):\n", + " setattr(layer, attr, regularizer)\n", + "\n", + " # When we change the layers attributes, the change only happens in the model config file\n", + " model_json = model.to_json()\n", + "\n", + " # Save the weights before reloading the model.\n", + " tmp_weights_path = os.path.join(tempfile.gettempdir(), 'tmp_weights.h5')\n", + " model.save_weights(tmp_weights_path)\n", + "\n", + " # load the model from the config\n", + " model = tf.keras.models.model_from_json(model_json)\n", + " \n", + " # Reload the model weights\n", + " model.load_weights(tmp_weights_path, by_name=True)\n", + " return model" + ] + }, + { + "cell_type": "code", + "execution_count": 3, "id": "a5c72863", "metadata": {}, "outputs": [], @@ -42,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "id": "1057a442", "metadata": { "scrolled": true @@ -76,7 +112,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "id": "7a6146e6", "metadata": {}, "outputs": [], @@ -88,7 +124,38 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Counter({'11498': 3913, '11504': 3913, '11505': 3913, '11632': 3913, '15709': 3913, '24087': 3913, '45333': 3913, '53120': 3913, '53548': 3913, '53557': 3913, '55793': 3913, '62107': 3913, '95672': 3913})\n" + ] + } + ], + "source": [ + "undersample = RandomUnderSampler(sampling_strategy='auto')\n", + "train, y_under = undersample.fit_resample(df, df['PrimaryCategoryID'])\n", + "#print(Counter(train['PrimaryCategoryID']))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "506aa5cf", + "metadata": {}, + "outputs": [], + "source": [ + "train, test = train_test_split(train, test_size=0.2, random_state=42)\n", + "# stratify=train['PrimaryCategoryID']\n", + "# train['PrimaryCategoryID'].value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, "id": "4d72eb90", "metadata": {}, "outputs": [ @@ -96,56 +163,56 @@ "name": "stdout", "output_type": "stream", "text": [ - "Found 6217 validated image filenames belonging to 13 classes.\n", - "Found 2664 validated image filenames belonging to 13 classes.\n" + "Found 32547 validated image filenames belonging to 13 classes.\n", + "Found 8136 validated image filenames belonging to 13 classes.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "/usr/local/lib/python3.8/dist-packages/keras_preprocessing/image/dataframe_iterator.py:279: UserWarning: Found 1 invalid image filename(s) in x_col=\"PictureURL\". These filename(s) will be ignored.\n", + "/usr/local/lib/python3.8/dist-packages/keras_preprocessing/image/dataframe_iterator.py:279: UserWarning: Found 12 invalid image filename(s) in x_col=\"PictureURL\". These filename(s) will be ignored.\n", " warnings.warn(\n" ] } ], "source": [ "datagen = ImageDataGenerator(rescale=1./255., \n", - " validation_split=.3,\n", - " #featurewise_std_normalization=True,\n", + " validation_split=.2,\n", + " #samplewise_std_normalization=True,\n", " #horizontal_flip= True,\n", " #vertical_flip= True,\n", " #width_shift_range= 0.2,\n", " #height_shift_range= 0.2,\n", - " #rotation_range= 180,\n", + " #rotation_range= 90,\n", " preprocessing_function=tf.keras.applications.vgg16.preprocess_input)\n", "train_generator=datagen.flow_from_dataframe(\n", - " dataframe=df[:len(df)],\n", + " dataframe=train[:len(train)],\n", " directory='./training_images',\n", " x_col='PictureURL',\n", " y_col='PrimaryCategoryID',\n", " batch_size=32,\n", " seed=42,\n", " shuffle=True,\n", - " target_size=(224,224),\n", + " target_size=(244,244),\n", " subset='training'\n", " )\n", "validation_generator=datagen.flow_from_dataframe(\n", - " dataframe=df[:len(df)],\n", + " dataframe=train[:len(train)], # is using train right?\n", " directory='./training_images',\n", " x_col='PictureURL',\n", " y_col='PrimaryCategoryID',\n", " batch_size=32,\n", " seed=42,\n", " shuffle=True,\n", - " target_size=(224,224),\n", + " target_size=(244,244),\n", " subset='validation'\n", " )" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 9, "id": "7b70f37f", "metadata": {}, "outputs": [], @@ -155,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 10, "id": "1ed54bf5", "metadata": {}, "outputs": [], @@ -172,7 +239,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 11, "id": "85934565", "metadata": {}, "outputs": [], @@ -183,7 +250,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 12, "id": "6322bcad", "metadata": {}, "outputs": [ @@ -203,88 +270,47 @@ }, { "cell_type": "code", - "execution_count": 10, - "id": "07fd25c6", - "metadata": {}, - "outputs": [], - "source": [ - "# see https://www.kaggle.com/dmitrypukhov/cnn-with-imagedatagenerator-flow-from-dataframe for train/test/val split \n", - "# example\n", - "\n", - "# may need to either create a test dataset from the original dataset or just download a new one" - ] - }, - { - "cell_type": "code", - "execution_count": 11, + "execution_count": 14, "id": "b31af79e", "metadata": {}, "outputs": [], "source": [ - "vgg16_model = tf.keras.applications.vgg16.VGG16(weights='imagenet')\n", - "#weights='imagenet'" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "fe06f2bf", - "metadata": {}, - "outputs": [], - "source": [ - "model = Sequential()\n", - "for layer in vgg16_model.layers[:-1]:\n", - " model.add(layer)" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "7d3cc82c", - "metadata": {}, - "outputs": [], - "source": [ - "for layer in model.layers:\n", - " layer.trainable = True" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "ea620129", - "metadata": {}, - "outputs": [], - "source": [ - "model.add(Dense(units=13, activation='softmax'))" + "base_model = tf.keras.applications.vgg19.VGG19(weights='imagenet')" ] }, { "cell_type": "code", "execution_count": 15, - "id": "c774d787", - "metadata": { - "scrolled": true - }, + "id": "fe06f2bf", + "metadata": {}, "outputs": [], "source": [ - "#model.summary()" + "model = Sequential()\n", + "for layer in base_model.layers[:-1]:\n", + " model.add(layer)" ] }, { "cell_type": "code", "execution_count": 16, - "id": "fd5d1246", + "id": "7d3cc82c", "metadata": {}, "outputs": [], "source": [ - "model.compile(optimizer=Adam(learning_rate=0.0001), loss='categorical_crossentropy',\n", - " metrics=['accuracy'])" + "for layer in model.layers:\n", + " layer.trainable = True\n", + " \n", + "#model.add(Dropout(.5))\n", + "#model.add(Dense(64, activation='softmax'))\n", + "# model.add(Dropout(.25))\n", + "\n", + "model.add(Dense(units=13, activation='softmax'))" ] }, { "cell_type": "code", - "execution_count": 17, - "id": "9cd2ba27", + "execution_count": 18, + "id": "c774d787", "metadata": { "scrolled": true }, @@ -293,97 +319,115 @@ "name": "stdout", "output_type": "stream", "text": [ - "Epoch 1/100\n", - "195/195 - 83s - loss: 2.5928 - accuracy: 0.1139 - val_loss: 2.3657 - val_accuracy: 0.1674 - 83s/epoch - 426ms/step\n", - "Epoch 2/100\n", - "195/195 - 77s - loss: 2.1473 - accuracy: 0.2582 - val_loss: 1.9276 - val_accuracy: 0.3281 - 77s/epoch - 394ms/step\n", - "Epoch 3/100\n", - "195/195 - 78s - loss: 1.7234 - accuracy: 0.3973 - val_loss: 1.6724 - val_accuracy: 0.4050 - 78s/epoch - 400ms/step\n", - "Epoch 4/100\n", - "195/195 - 78s - loss: 1.4692 - accuracy: 0.4843 - val_loss: 1.5583 - val_accuracy: 0.4662 - 78s/epoch - 402ms/step\n", - "Epoch 5/100\n", - "195/195 - 79s - loss: 1.2598 - accuracy: 0.5477 - val_loss: 1.5135 - val_accuracy: 0.4944 - 79s/epoch - 403ms/step\n", - "Epoch 6/100\n", - "195/195 - 79s - loss: 1.0220 - accuracy: 0.6376 - val_loss: 1.5566 - val_accuracy: 0.4962 - 79s/epoch - 404ms/step\n", - "Epoch 7/100\n", - "195/195 - 78s - loss: 0.8021 - accuracy: 0.7084 - val_loss: 1.7647 - val_accuracy: 0.4711 - 78s/epoch - 398ms/step\n", - "Epoch 8/100\n", - "195/195 - 78s - loss: 0.5998 - accuracy: 0.7804 - val_loss: 1.8439 - val_accuracy: 0.4869 - 78s/epoch - 400ms/step\n", - "Epoch 9/100\n", - "195/195 - 77s - loss: 0.3910 - accuracy: 0.8631 - val_loss: 2.1197 - val_accuracy: 0.4872 - 77s/epoch - 397ms/step\n", - "Epoch 10/100\n", - "195/195 - 78s - loss: 0.2600 - accuracy: 0.9094 - val_loss: 2.3586 - val_accuracy: 0.4703 - 78s/epoch - 402ms/step\n", - "Epoch 11/100\n", - "195/195 - 77s - loss: 0.2066 - accuracy: 0.9279 - val_loss: 2.5012 - val_accuracy: 0.4632 - 77s/epoch - 397ms/step\n", - "Epoch 12/100\n", - "195/195 - 77s - loss: 0.1266 - accuracy: 0.9571 - val_loss: 2.5961 - val_accuracy: 0.4854 - 77s/epoch - 395ms/step\n", - "Epoch 13/100\n", - "195/195 - 77s - loss: 0.1098 - accuracy: 0.9648 - val_loss: 2.9123 - val_accuracy: 0.4602 - 77s/epoch - 395ms/step\n", - "Epoch 14/100\n", - "195/195 - 77s - loss: 0.0794 - accuracy: 0.9744 - val_loss: 2.9060 - val_accuracy: 0.4752 - 77s/epoch - 395ms/step\n", - "Epoch 15/100\n", - "195/195 - 77s - loss: 0.1061 - accuracy: 0.9656 - val_loss: 2.7269 - val_accuracy: 0.4658 - 77s/epoch - 396ms/step\n", - "Epoch 16/100\n", - "195/195 - 77s - loss: 0.0908 - accuracy: 0.9712 - val_loss: 2.9450 - val_accuracy: 0.4621 - 77s/epoch - 396ms/step\n", - "Epoch 17/100\n", - "195/195 - 77s - loss: 0.0820 - accuracy: 0.9736 - val_loss: 2.8900 - val_accuracy: 0.4703 - 77s/epoch - 396ms/step\n", - "Epoch 18/100\n", - "195/195 - 77s - loss: 0.0827 - accuracy: 0.9722 - val_loss: 2.9304 - val_accuracy: 0.4745 - 77s/epoch - 395ms/step\n", - "Epoch 19/100\n", - "195/195 - 77s - loss: 0.0726 - accuracy: 0.9757 - val_loss: 3.2673 - val_accuracy: 0.4580 - 77s/epoch - 393ms/step\n", - "Epoch 20/100\n", - "195/195 - 77s - loss: 0.0560 - accuracy: 0.9821 - val_loss: 3.0101 - val_accuracy: 0.4670 - 77s/epoch - 394ms/step\n", - "Epoch 21/100\n", - "195/195 - 77s - loss: 0.0355 - accuracy: 0.9907 - val_loss: 3.2575 - val_accuracy: 0.4568 - 77s/epoch - 395ms/step\n", - "Epoch 22/100\n", - "195/195 - 78s - loss: 0.0950 - accuracy: 0.9693 - val_loss: 3.0716 - val_accuracy: 0.4568 - 78s/epoch - 399ms/step\n", - "Epoch 23/100\n", - "195/195 - 78s - loss: 0.0307 - accuracy: 0.9910 - val_loss: 3.6348 - val_accuracy: 0.4741 - 78s/epoch - 401ms/step\n", - "Epoch 24/100\n", - "195/195 - 77s - loss: 0.0315 - accuracy: 0.9903 - val_loss: 3.2422 - val_accuracy: 0.4711 - 77s/epoch - 396ms/step\n", - "Epoch 25/100\n", - "195/195 - 78s - loss: 0.0640 - accuracy: 0.9789 - val_loss: 3.5402 - val_accuracy: 0.4298 - 78s/epoch - 402ms/step\n", - "Epoch 26/100\n", - "195/195 - 78s - loss: 0.0916 - accuracy: 0.9715 - val_loss: 3.1916 - val_accuracy: 0.4520 - 78s/epoch - 399ms/step\n", - "Epoch 27/100\n", - "195/195 - 77s - loss: 0.0634 - accuracy: 0.9799 - val_loss: 3.2234 - val_accuracy: 0.4602 - 77s/epoch - 394ms/step\n", - "Epoch 28/100\n", - "195/195 - 78s - loss: 0.0673 - accuracy: 0.9788 - val_loss: 3.4435 - val_accuracy: 0.4647 - 78s/epoch - 400ms/step\n", - "Epoch 29/100\n", - "195/195 - 78s - loss: 0.0440 - accuracy: 0.9870 - val_loss: 3.3068 - val_accuracy: 0.4598 - 78s/epoch - 400ms/step\n", - "Epoch 30/100\n", - "195/195 - 78s - loss: 0.0165 - accuracy: 0.9950 - val_loss: 3.6233 - val_accuracy: 0.4681 - 78s/epoch - 401ms/step\n", - "Epoch 31/100\n", - "195/195 - 79s - loss: 0.0303 - accuracy: 0.9910 - val_loss: 3.7398 - val_accuracy: 0.4572 - 79s/epoch - 403ms/step\n", - "Epoch 32/100\n", - "195/195 - 78s - loss: 0.0554 - accuracy: 0.9815 - val_loss: 3.5560 - val_accuracy: 0.4369 - 78s/epoch - 399ms/step\n", - "Epoch 33/100\n", - "195/195 - 78s - loss: 0.0556 - accuracy: 0.9829 - val_loss: 3.6555 - val_accuracy: 0.4610 - 78s/epoch - 401ms/step\n", - "Epoch 34/100\n", - "195/195 - 78s - loss: 0.0624 - accuracy: 0.9809 - val_loss: 3.3500 - val_accuracy: 0.4617 - 78s/epoch - 401ms/step\n", - "Epoch 35/100\n", - "195/195 - 77s - loss: 0.0367 - accuracy: 0.9886 - val_loss: 3.5968 - val_accuracy: 0.4625 - 77s/epoch - 394ms/step\n", - "Epoch 36/100\n", - "195/195 - 78s - loss: 0.0301 - accuracy: 0.9912 - val_loss: 3.5188 - val_accuracy: 0.4643 - 78s/epoch - 399ms/step\n", - "Epoch 37/100\n", - "195/195 - 79s - loss: 0.0491 - accuracy: 0.9850 - val_loss: 3.3079 - val_accuracy: 0.4471 - 79s/epoch - 403ms/step\n", - "Epoch 38/100\n", - "195/195 - 78s - loss: 0.0577 - accuracy: 0.9821 - val_loss: 3.4042 - val_accuracy: 0.4381 - 78s/epoch - 400ms/step\n", - "Epoch 39/100\n", - "195/195 - 78s - loss: 0.0431 - accuracy: 0.9878 - val_loss: 3.4389 - val_accuracy: 0.4550 - 78s/epoch - 399ms/step\n", - "Epoch 40/100\n", - "195/195 - 77s - loss: 0.0218 - accuracy: 0.9940 - val_loss: 3.1989 - val_accuracy: 0.4854 - 77s/epoch - 397ms/step\n", - "Epoch 41/100\n", - "195/195 - 77s - loss: 0.0296 - accuracy: 0.9921 - val_loss: 3.2759 - val_accuracy: 0.4651 - 77s/epoch - 394ms/step\n", - "Epoch 42/100\n", - "195/195 - 78s - loss: 0.0176 - accuracy: 0.9947 - val_loss: 3.2391 - val_accuracy: 0.4745 - 78s/epoch - 398ms/step\n", - "Epoch 43/100\n", - "195/195 - 79s - loss: 0.0099 - accuracy: 0.9965 - val_loss: 3.5696 - val_accuracy: 0.4553 - 79s/epoch - 405ms/step\n", - "Epoch 44/100\n", - "195/195 - 78s - loss: 0.0516 - accuracy: 0.9852 - val_loss: 3.3857 - val_accuracy: 0.4482 - 78s/epoch - 402ms/step\n", - "Epoch 45/100\n", - "195/195 - 79s - loss: 0.0412 - accuracy: 0.9860 - val_loss: 3.3717 - val_accuracy: 0.4580 - 79s/epoch - 404ms/step\n", - "Epoch 46/100\n" + "Model: \"sequential\"\n", + "_________________________________________________________________\n", + " Layer (type) Output Shape Param # \n", + "=================================================================\n", + " block1_conv1 (Conv2D) (None, 224, 224, 64) 1792 \n", + " \n", + " block1_conv2 (Conv2D) (None, 224, 224, 64) 36928 \n", + " \n", + " block1_pool (MaxPooling2D) (None, 112, 112, 64) 0 \n", + " \n", + " block2_conv1 (Conv2D) (None, 112, 112, 128) 73856 \n", + " \n", + " block2_conv2 (Conv2D) (None, 112, 112, 128) 147584 \n", + " \n", + " block2_pool (MaxPooling2D) (None, 56, 56, 128) 0 \n", + " \n", + " block3_conv1 (Conv2D) (None, 56, 56, 256) 295168 \n", + " \n", + " block3_conv2 (Conv2D) (None, 56, 56, 256) 590080 \n", + " \n", + " block3_conv3 (Conv2D) (None, 56, 56, 256) 590080 \n", + " \n", + " block3_pool (MaxPooling2D) (None, 28, 28, 256) 0 \n", + " \n", + " block4_conv1 (Conv2D) (None, 28, 28, 512) 1180160 \n", + " \n", + " block4_conv2 (Conv2D) (None, 28, 28, 512) 2359808 \n", + " \n", + " block4_conv3 (Conv2D) (None, 28, 28, 512) 2359808 \n", + " \n", + " block4_pool (MaxPooling2D) (None, 14, 14, 512) 0 \n", + " \n", + " block5_conv1 (Conv2D) (None, 14, 14, 512) 2359808 \n", + " \n", + " block5_conv2 (Conv2D) (None, 14, 14, 512) 2359808 \n", + " \n", + " block5_conv3 (Conv2D) (None, 14, 14, 512) 2359808 \n", + " \n", + " block5_pool (MaxPooling2D) (None, 7, 7, 512) 0 \n", + " \n", + " flatten (Flatten) (None, 25088) 0 \n", + " \n", + " fc1 (Dense) (None, 4096) 102764544 \n", + " \n", + " fc2 (Dense) (None, 4096) 16781312 \n", + " \n", + " dense (Dense) (None, 13) 53261 \n", + " \n", + "=================================================================\n", + "Total params: 134,313,805\n", + "Trainable params: 134,313,805\n", + "Non-trainable params: 0\n", + "_________________________________________________________________\n" + ] + } + ], + "source": [ + "#model = add_regularization(model)\n", + "model.summary()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "fd5d1246", + "metadata": {}, + "outputs": [], + "source": [ + "model.compile(optimizer=Adam(learning_rate=.0001), loss='categorical_crossentropy',\n", + " metrics=['accuracy'])\n", + "# sparse_categorical_crossentropy" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "9cd2ba27", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epoch 1/30\n", + "1018/1018 [==============================] - 391s 379ms/step - loss: 2.4329 - accuracy: 0.1571 - val_loss: 2.1902 - val_accuracy: 0.2525\n", + "Epoch 2/30\n", + "1018/1018 [==============================] - 379s 373ms/step - loss: 2.0578 - accuracy: 0.2960 - val_loss: 1.9160 - val_accuracy: 0.3330\n", + "Epoch 3/30\n", + "1018/1018 [==============================] - 381s 374ms/step - loss: 1.8221 - accuracy: 0.3681 - val_loss: 1.8588 - val_accuracy: 0.3535\n", + "Epoch 4/30\n", + "1018/1018 [==============================] - 383s 376ms/step - loss: 1.6406 - accuracy: 0.4272 - val_loss: 1.7819 - val_accuracy: 0.4028\n", + "Epoch 5/30\n", + "1018/1018 [==============================] - 383s 376ms/step - loss: 1.4577 - accuracy: 0.4920 - val_loss: 1.7216 - val_accuracy: 0.4158\n", + "Epoch 6/30\n", + "1018/1018 [==============================] - 379s 372ms/step - loss: 1.2528 - accuracy: 0.5607 - val_loss: 1.7924 - val_accuracy: 0.4140\n", + "Epoch 7/30\n", + "1018/1018 [==============================] - 378s 371ms/step - loss: 1.0030 - accuracy: 0.6469 - val_loss: 1.8017 - val_accuracy: 0.4303\n", + "Epoch 8/30\n", + "1018/1018 [==============================] - 379s 372ms/step - loss: 0.7405 - accuracy: 0.7420 - val_loss: 1.9863 - val_accuracy: 0.4453\n", + "Epoch 9/30\n", + "1018/1018 [==============================] - 379s 372ms/step - loss: 0.4704 - accuracy: 0.8354 - val_loss: 2.3988 - val_accuracy: 0.4263\n", + "Epoch 10/30\n", + "1018/1018 [==============================] - 379s 372ms/step - loss: 0.3059 - accuracy: 0.8944 - val_loss: 2.7526 - val_accuracy: 0.4303\n", + "Epoch 11/30\n", + "1018/1018 [==============================] - 377s 371ms/step - loss: 0.2160 - accuracy: 0.9278 - val_loss: 3.0618 - val_accuracy: 0.4250\n", + "Epoch 12/30\n", + " 437/1018 [===========>..................] - ETA: 2:53 - loss: 0.1370 - accuracy: 0.9536" ] }, { @@ -393,7 +437,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m model.fit(x=train_generator,\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_generator\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[1;32m 3\u001b[0m \u001b[0mvalidation_data\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mvalidation_generator\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mvalidation_steps\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalidation_generator\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[1;32m 5\u001b[0m \u001b[0mepochs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m model.fit(x=train_generator,\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_generator\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[1;32m 3\u001b[0m \u001b[0mvalidation_data\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mvalidation_generator\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mvalidation_steps\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalidation_generator\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[1;32m 5\u001b[0m \u001b[0mepochs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m30\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 64\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 65\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# pylint: disable=broad-except\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 66\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_process_traceback_frames\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__traceback__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/engine/training.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)\u001b[0m\n\u001b[1;32m 1214\u001b[0m _r=1):\n\u001b[1;32m 1215\u001b[0m \u001b[0mcallbacks\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_train_batch_begin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstep\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1216\u001b[0;31m \u001b[0mtmp_logs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrain_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterator\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 1217\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mdata_handler\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshould_sync\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1218\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masync_wait\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[0;32m/usr/local/lib/python3.8/dist-packages/tensorflow/python/util/traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 148\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 149\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 150\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 151\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 152\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_process_traceback_frames\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__traceback__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", @@ -412,8 +456,8 @@ " steps_per_epoch=len(train_generator),\n", " validation_data=validation_generator,\n", " validation_steps=len(validation_generator),\n", - " epochs=100,\n", - " verbose=2)" + " epochs=30,\n", + " verbose=1)" ] }, { diff --git a/Shoe Classifier_Xception.ipynb b/Shoe Classifier_Xception.ipynb new file mode 100644 index 0000000..e14bfbe --- /dev/null +++ b/Shoe Classifier_Xception.ipynb @@ -0,0 +1,857 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "572dc7fb", + "metadata": {}, + "outputs": [], + "source": [ + "from matplotlib import pyplot as plt\n", + "from matplotlib.image import imread\n", + "import pandas as pd\n", + "from collections import Counter\n", + "import json\n", + "import os\n", + "import re\n", + "import tempfile\n", + "import numpy as np\n", + "from os.path import exists\n", + "from imblearn.under_sampling import RandomUnderSampler\n", + "from PIL import ImageFile\n", + "import sklearn as sk\n", + "from sklearn.model_selection import train_test_split, StratifiedShuffleSplit\n", + "import tensorflow as tf\n", + "import tensorflow.keras\n", + "from tensorflow.keras.preprocessing.image import ImageDataGenerator\n", + "from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dense, Dropout, Flatten, Activation\n", + "from tensorflow.keras.models import Sequential\n", + "from tensorflow.keras.optimizers import Adam\n", + "# custom modules\n", + "import image_faults\n", + "\n", + "ImageFile.LOAD_TRUNCATED_IMAGES = True" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "8d94196d", + "metadata": {}, + "outputs": [], + "source": [ + "def add_regularization(model, regularizer=tf.keras.regularizers.l2(0.0001)):\n", + "\n", + " if not isinstance(regularizer, tf.keras.regularizers.Regularizer):\n", + " print(\"Regularizer must be a subclass of tf.keras.regularizers.Regularizer\")\n", + " return model\n", + "\n", + " for layer in model.layers:\n", + " for attr in ['kernel_regularizer']:\n", + " if hasattr(layer, attr):\n", + " setattr(layer, attr, regularizer)\n", + "\n", + " # When we change the layers attributes, the change only happens in the model config file\n", + " model_json = model.to_json()\n", + "\n", + " # Save the weights before reloading the model.\n", + " tmp_weights_path = os.path.join(tempfile.gettempdir(), 'tmp_weights.h5')\n", + " model.save_weights(tmp_weights_path)\n", + "\n", + " # load the model from the config\n", + " model = tf.keras.models.model_from_json(model_json)\n", + " \n", + " # Reload the model weights\n", + " model.load_weights(tmp_weights_path, by_name=True)\n", + " return model" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "a5c72863", + "metadata": {}, + "outputs": [], + "source": [ + "# image_faults.faulty_images() # removes faulty images\n", + "df = pd.read_csv('expanded_class.csv', index_col=[0], low_memory=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "1057a442", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{source:target} dictionary created @ /tf/training_images\n" + ] + } + ], + "source": [ + "def dict_pics():\n", + " target_dir = os.getcwd() + os.sep + \"training_images\"\n", + " with open('temp_pics_source_list.txt') as f:\n", + " temp_pics_source_list = json.load(f)\n", + " dict_pics = {k:target_dir + os.sep + re.search(r'[^/]+(?=/\\$_|.jpg)', k, re.IGNORECASE).group() + '.jpg' for k in temp_pics_source_list}\n", + " print(\"{source:target} dictionary created @ \" + target_dir)\n", + " return dict_pics\n", + "\n", + "dict_pics = dict_pics()\n", + "blah = pd.Series(df.PictureURL)\n", + "df = df.drop(labels=['PictureURL'], axis=1)\n", + "blah = blah.apply(lambda x: dict_pics[x])\n", + "df = pd.concat([blah, df],axis=1)\n", + "df = df.groupby('PrimaryCategoryID').filter(lambda x: len(x)>25) # removes cat outliers\n", + "# removes non-existent image paths" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "7a6146e6", + "metadata": {}, + "outputs": [], + "source": [ + "df['PrimaryCategoryID'] = df['PrimaryCategoryID'].astype(str) # pandas thinks ids are ints\n", + "\n", + "df=df.sample(frac=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "114cc3c0", + "metadata": {}, + "outputs": [], + "source": [ + "undersample = RandomUnderSampler(sampling_strategy='auto')\n", + "train, y_under = undersample.fit_resample(df, df['PrimaryCategoryID'])\n", + "#print(Counter(train['PrimaryCategoryID']))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "506aa5cf", + "metadata": {}, + "outputs": [], + "source": [ + "train, test = train_test_split(train, test_size=0.1, random_state=42)\n", + "# stratify=train['PrimaryCategoryID']\n", + "# train['PrimaryCategoryID'].value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "4d72eb90", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found 5110 validated image filenames belonging to 13 classes.\n", + "Found 1277 validated image filenames belonging to 13 classes.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.8/dist-packages/keras_preprocessing/image/dataframe_iterator.py:279: UserWarning: Found 1 invalid image filename(s) in x_col=\"PictureURL\". These filename(s) will be ignored.\n", + " warnings.warn(\n" + ] + } + ], + "source": [ + "datagen = ImageDataGenerator(rescale=1./255., \n", + " validation_split=.2,\n", + " #samplewise_std_normalization=True,\n", + " #horizontal_flip= True,\n", + " #vertical_flip= True,\n", + " #width_shift_range= 0.2,\n", + " #height_shift_range= 0.2,\n", + " #rotation_range= 90,\n", + " preprocessing_function=tf.keras.applications.xception.preprocess_input)\n", + "train_generator=datagen.flow_from_dataframe(\n", + " dataframe=train[:len(train)],\n", + " directory='./training_images',\n", + " x_col='PictureURL',\n", + " y_col='PrimaryCategoryID',\n", + " batch_size=64,\n", + " seed=42,\n", + " shuffle=True,\n", + " target_size=(299,299),\n", + " subset='training'\n", + " )\n", + "validation_generator=datagen.flow_from_dataframe(\n", + " dataframe=train[:len(train)], # is using train right?\n", + " directory='./training_images',\n", + " x_col='PictureURL',\n", + " y_col='PrimaryCategoryID',\n", + " batch_size=64,\n", + " seed=42,\n", + " shuffle=True,\n", + " target_size=(299,299),\n", + " subset='validation'\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "7b70f37f", + "metadata": {}, + "outputs": [], + "source": [ + "imgs, labels = next(train_generator)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "1ed54bf5", + "metadata": {}, + "outputs": [], + "source": [ + "def plotImages(images_arr):\n", + " fig, axes = plt.subplots(1, 10, figsize=(20,20))\n", + " axes = axes.flatten()\n", + " for img, ax in zip( images_arr, axes):\n", + " ax.imshow(img)\n", + " ax.axis('off')\n", + " plt.tight_layout()\n", + " plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "85934565", + "metadata": {}, + "outputs": [], + "source": [ + "#plotImages(imgs)\n", + "#print(labels)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "6322bcad", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ], + "source": [ + "physical_devices = tf.config.list_physical_devices('GPU')\n", + "print(len(physical_devices))\n", + "tf.config.experimental.set_memory_growth(physical_devices[0], True)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "07fd25c6", + "metadata": {}, + "outputs": [], + "source": [ + "# see https://www.kaggle.com/dmitrypukhov/cnn-with-imagedatagenerator-flow-from-dataframe for train/test/val split \n", + "# example\n", + "\n", + "# may need to either create a test dataset from the original dataset or just download a new one" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "b31af79e", + "metadata": {}, + "outputs": [], + "source": [ + "base_model = tf.keras.applications.xception.Xception(include_top=False, weights='imagenet', pooling='avg')\n", + "#base_model.summary()" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "fe06f2bf", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Model: \"model\"\n", + "__________________________________________________________________________________________________\n", + " Layer (type) Output Shape Param # Connected to \n", + "==================================================================================================\n", + " input_1 (InputLayer) [(None, None, None, 0 [] \n", + " 3)] \n", + " \n", + " block1_conv1 (Conv2D) (None, None, None, 864 ['input_1[0][0]'] \n", + " 32) \n", + " \n", + " block1_conv1_bn (BatchNormaliz (None, None, None, 128 ['block1_conv1[0][0]'] \n", + " ation) 32) \n", + " \n", + " block1_conv1_act (Activation) (None, None, None, 0 ['block1_conv1_bn[0][0]'] \n", + " 32) \n", + " \n", + " block1_conv2 (Conv2D) (None, None, None, 18432 ['block1_conv1_act[0][0]'] \n", + " 64) \n", + " \n", + " block1_conv2_bn (BatchNormaliz (None, None, None, 256 ['block1_conv2[0][0]'] \n", + " ation) 64) \n", + " \n", + " block1_conv2_act (Activation) (None, None, None, 0 ['block1_conv2_bn[0][0]'] \n", + " 64) \n", + " \n", + " block2_sepconv1 (SeparableConv (None, None, None, 8768 ['block1_conv2_act[0][0]'] \n", + " 2D) 128) \n", + " \n", + " block2_sepconv1_bn (BatchNorma (None, None, None, 512 ['block2_sepconv1[0][0]'] \n", + " lization) 128) \n", + " \n", + " block2_sepconv2_act (Activatio (None, None, None, 0 ['block2_sepconv1_bn[0][0]'] \n", + " n) 128) \n", + " \n", + " block2_sepconv2 (SeparableConv (None, None, None, 17536 ['block2_sepconv2_act[0][0]'] \n", + " 2D) 128) \n", + " \n", + " block2_sepconv2_bn (BatchNorma (None, None, None, 512 ['block2_sepconv2[0][0]'] \n", + " lization) 128) \n", + " \n", + " conv2d (Conv2D) (None, None, None, 8192 ['block1_conv2_act[0][0]'] \n", + " 128) \n", + " \n", + " block2_pool (MaxPooling2D) (None, None, None, 0 ['block2_sepconv2_bn[0][0]'] \n", + " 128) \n", + " \n", + " batch_normalization (BatchNorm (None, None, None, 512 ['conv2d[0][0]'] \n", + " alization) 128) \n", + " \n", + " add (Add) (None, None, None, 0 ['block2_pool[0][0]', \n", + " 128) 'batch_normalization[0][0]'] \n", + " \n", + " block3_sepconv1_act (Activatio (None, None, None, 0 ['add[0][0]'] \n", + " n) 128) \n", + " \n", + " block3_sepconv1 (SeparableConv (None, None, None, 33920 ['block3_sepconv1_act[0][0]'] \n", + " 2D) 256) \n", + " \n", + " block3_sepconv1_bn (BatchNorma (None, None, None, 1024 ['block3_sepconv1[0][0]'] \n", + " lization) 256) \n", + " \n", + " block3_sepconv2_act (Activatio (None, None, None, 0 ['block3_sepconv1_bn[0][0]'] \n", + " n) 256) \n", + " \n", + " block3_sepconv2 (SeparableConv (None, None, None, 67840 ['block3_sepconv2_act[0][0]'] \n", + " 2D) 256) \n", + " \n", + " block3_sepconv2_bn (BatchNorma (None, None, None, 1024 ['block3_sepconv2[0][0]'] \n", + " lization) 256) \n", + " \n", + " conv2d_1 (Conv2D) (None, None, None, 32768 ['add[0][0]'] \n", + " 256) \n", + " \n", + " block3_pool (MaxPooling2D) (None, None, None, 0 ['block3_sepconv2_bn[0][0]'] \n", + " 256) \n", + " \n", + " batch_normalization_1 (BatchNo (None, None, None, 1024 ['conv2d_1[0][0]'] \n", + " rmalization) 256) \n", + " \n", + " add_1 (Add) (None, None, None, 0 ['block3_pool[0][0]', \n", + " 256) 'batch_normalization_1[0][0]'] \n", + " \n", + " block4_sepconv1_act (Activatio (None, None, None, 0 ['add_1[0][0]'] \n", + " n) 256) \n", + " \n", + " block4_sepconv1 (SeparableConv (None, None, None, 188672 ['block4_sepconv1_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block4_sepconv1_bn (BatchNorma (None, None, None, 2912 ['block4_sepconv1[0][0]'] \n", + " lization) 728) \n", + " \n", + " block4_sepconv2_act (Activatio (None, None, None, 0 ['block4_sepconv1_bn[0][0]'] \n", + " n) 728) \n", + " \n", + " block4_sepconv2 (SeparableConv (None, None, None, 536536 ['block4_sepconv2_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block4_sepconv2_bn (BatchNorma (None, None, None, 2912 ['block4_sepconv2[0][0]'] \n", + " lization) 728) \n", + " \n", + " conv2d_2 (Conv2D) (None, None, None, 186368 ['add_1[0][0]'] \n", + " 728) \n", + " \n", + " block4_pool (MaxPooling2D) (None, None, None, 0 ['block4_sepconv2_bn[0][0]'] \n", + " 728) \n", + " \n", + " batch_normalization_2 (BatchNo (None, None, None, 2912 ['conv2d_2[0][0]'] \n", + " rmalization) 728) \n", + " \n", + " add_2 (Add) (None, None, None, 0 ['block4_pool[0][0]', \n", + " 728) 'batch_normalization_2[0][0]'] \n", + " \n", + " block5_sepconv1_act (Activatio (None, None, None, 0 ['add_2[0][0]'] \n", + " n) 728) \n", + " \n", + " block5_sepconv1 (SeparableConv (None, None, None, 536536 ['block5_sepconv1_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block5_sepconv1_bn (BatchNorma (None, None, None, 2912 ['block5_sepconv1[0][0]'] \n", + " lization) 728) \n", + " \n", + " block5_sepconv2_act (Activatio (None, None, None, 0 ['block5_sepconv1_bn[0][0]'] \n", + " n) 728) \n", + " \n", + " block5_sepconv2 (SeparableConv (None, None, None, 536536 ['block5_sepconv2_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block5_sepconv2_bn (BatchNorma (None, None, None, 2912 ['block5_sepconv2[0][0]'] \n", + " lization) 728) \n", + " \n", + " block5_sepconv3_act (Activatio (None, None, None, 0 ['block5_sepconv2_bn[0][0]'] \n", + " n) 728) \n", + " \n", + " block5_sepconv3 (SeparableConv (None, None, None, 536536 ['block5_sepconv3_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block5_sepconv3_bn (BatchNorma (None, None, None, 2912 ['block5_sepconv3[0][0]'] \n", + " lization) 728) \n", + " \n", + " add_3 (Add) (None, None, None, 0 ['block5_sepconv3_bn[0][0]', \n", + " 728) 'add_2[0][0]'] \n", + " \n", + " block6_sepconv1_act (Activatio (None, None, None, 0 ['add_3[0][0]'] \n", + " n) 728) \n", + " \n", + " block6_sepconv1 (SeparableConv (None, None, None, 536536 ['block6_sepconv1_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block6_sepconv1_bn (BatchNorma (None, None, None, 2912 ['block6_sepconv1[0][0]'] \n", + " lization) 728) \n", + " \n", + " block6_sepconv2_act (Activatio (None, None, None, 0 ['block6_sepconv1_bn[0][0]'] \n", + " n) 728) \n", + " \n", + " block6_sepconv2 (SeparableConv (None, None, None, 536536 ['block6_sepconv2_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block6_sepconv2_bn (BatchNorma (None, None, None, 2912 ['block6_sepconv2[0][0]'] \n", + " lization) 728) \n", + " \n", + " block6_sepconv3_act (Activatio (None, None, None, 0 ['block6_sepconv2_bn[0][0]'] \n", + " n) 728) \n", + " \n", + " block6_sepconv3 (SeparableConv (None, None, None, 536536 ['block6_sepconv3_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block6_sepconv3_bn (BatchNorma (None, None, None, 2912 ['block6_sepconv3[0][0]'] \n", + " lization) 728) \n", + " \n", + " add_4 (Add) (None, None, None, 0 ['block6_sepconv3_bn[0][0]', \n", + " 728) 'add_3[0][0]'] \n", + " \n", + " block7_sepconv1_act (Activatio (None, None, None, 0 ['add_4[0][0]'] \n", + " n) 728) \n", + " \n", + " block7_sepconv1 (SeparableConv (None, None, None, 536536 ['block7_sepconv1_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block7_sepconv1_bn (BatchNorma (None, None, None, 2912 ['block7_sepconv1[0][0]'] \n", + " lization) 728) \n", + " \n", + " block7_sepconv2_act (Activatio (None, None, None, 0 ['block7_sepconv1_bn[0][0]'] \n", + " n) 728) \n", + " \n", + " block7_sepconv2 (SeparableConv (None, None, None, 536536 ['block7_sepconv2_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block7_sepconv2_bn (BatchNorma (None, None, None, 2912 ['block7_sepconv2[0][0]'] \n", + " lization) 728) \n", + " \n", + " block7_sepconv3_act (Activatio (None, None, None, 0 ['block7_sepconv2_bn[0][0]'] \n", + " n) 728) \n", + " \n", + " block7_sepconv3 (SeparableConv (None, None, None, 536536 ['block7_sepconv3_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block7_sepconv3_bn (BatchNorma (None, None, None, 2912 ['block7_sepconv3[0][0]'] \n", + " lization) 728) \n", + " \n", + " add_5 (Add) (None, None, None, 0 ['block7_sepconv3_bn[0][0]', \n", + " 728) 'add_4[0][0]'] \n", + " \n", + " block8_sepconv1_act (Activatio (None, None, None, 0 ['add_5[0][0]'] \n", + " n) 728) \n", + " \n", + " block8_sepconv1 (SeparableConv (None, None, None, 536536 ['block8_sepconv1_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block8_sepconv1_bn (BatchNorma (None, None, None, 2912 ['block8_sepconv1[0][0]'] \n", + " lization) 728) \n", + " \n", + " block8_sepconv2_act (Activatio (None, None, None, 0 ['block8_sepconv1_bn[0][0]'] \n", + " n) 728) \n", + " \n", + " block8_sepconv2 (SeparableConv (None, None, None, 536536 ['block8_sepconv2_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block8_sepconv2_bn (BatchNorma (None, None, None, 2912 ['block8_sepconv2[0][0]'] \n", + " lization) 728) \n", + " \n", + " block8_sepconv3_act (Activatio (None, None, None, 0 ['block8_sepconv2_bn[0][0]'] \n", + " n) 728) \n", + " \n", + " block8_sepconv3 (SeparableConv (None, None, None, 536536 ['block8_sepconv3_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block8_sepconv3_bn (BatchNorma (None, None, None, 2912 ['block8_sepconv3[0][0]'] \n", + " lization) 728) \n", + " \n", + " add_6 (Add) (None, None, None, 0 ['block8_sepconv3_bn[0][0]', \n", + " 728) 'add_5[0][0]'] \n", + " \n", + " block9_sepconv1_act (Activatio (None, None, None, 0 ['add_6[0][0]'] \n", + " n) 728) \n", + " \n", + " block9_sepconv1 (SeparableConv (None, None, None, 536536 ['block9_sepconv1_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block9_sepconv1_bn (BatchNorma (None, None, None, 2912 ['block9_sepconv1[0][0]'] \n", + " lization) 728) \n", + " \n", + " block9_sepconv2_act (Activatio (None, None, None, 0 ['block9_sepconv1_bn[0][0]'] \n", + " n) 728) \n", + " \n", + " block9_sepconv2 (SeparableConv (None, None, None, 536536 ['block9_sepconv2_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block9_sepconv2_bn (BatchNorma (None, None, None, 2912 ['block9_sepconv2[0][0]'] \n", + " lization) 728) \n", + " \n", + " block9_sepconv3_act (Activatio (None, None, None, 0 ['block9_sepconv2_bn[0][0]'] \n", + " n) 728) \n", + " \n", + " block9_sepconv3 (SeparableConv (None, None, None, 536536 ['block9_sepconv3_act[0][0]'] \n", + " 2D) 728) \n", + " \n", + " block9_sepconv3_bn (BatchNorma (None, None, None, 2912 ['block9_sepconv3[0][0]'] \n", + " lization) 728) \n", + " \n", + " add_7 (Add) (None, None, None, 0 ['block9_sepconv3_bn[0][0]', \n", + " 728) 'add_6[0][0]'] \n", + " \n", + " block10_sepconv1_act (Activati (None, None, None, 0 ['add_7[0][0]'] \n", + " on) 728) \n", + " \n", + " block10_sepconv1 (SeparableCon (None, None, None, 536536 ['block10_sepconv1_act[0][0]'] \n", + " v2D) 728) \n", + " \n", + " block10_sepconv1_bn (BatchNorm (None, None, None, 2912 ['block10_sepconv1[0][0]'] \n", + " alization) 728) \n", + " \n", + " block10_sepconv2_act (Activati (None, None, None, 0 ['block10_sepconv1_bn[0][0]'] \n", + " on) 728) \n", + " \n", + " block10_sepconv2 (SeparableCon (None, None, None, 536536 ['block10_sepconv2_act[0][0]'] \n", + " v2D) 728) \n", + " \n", + " block10_sepconv2_bn (BatchNorm (None, None, None, 2912 ['block10_sepconv2[0][0]'] \n", + " alization) 728) \n", + " \n", + " block10_sepconv3_act (Activati (None, None, None, 0 ['block10_sepconv2_bn[0][0]'] \n", + " on) 728) \n", + " \n", + " block10_sepconv3 (SeparableCon (None, None, None, 536536 ['block10_sepconv3_act[0][0]'] \n", + " v2D) 728) \n", + " \n", + " block10_sepconv3_bn (BatchNorm (None, None, None, 2912 ['block10_sepconv3[0][0]'] \n", + " alization) 728) \n", + " \n", + " add_8 (Add) (None, None, None, 0 ['block10_sepconv3_bn[0][0]', \n", + " 728) 'add_7[0][0]'] \n", + " \n", + " block11_sepconv1_act (Activati (None, None, None, 0 ['add_8[0][0]'] \n", + " on) 728) \n", + " \n", + " block11_sepconv1 (SeparableCon (None, None, None, 536536 ['block11_sepconv1_act[0][0]'] \n", + " v2D) 728) \n", + " \n", + " block11_sepconv1_bn (BatchNorm (None, None, None, 2912 ['block11_sepconv1[0][0]'] \n", + " alization) 728) \n", + " \n", + " block11_sepconv2_act (Activati (None, None, None, 0 ['block11_sepconv1_bn[0][0]'] \n", + " on) 728) \n", + " \n", + " block11_sepconv2 (SeparableCon (None, None, None, 536536 ['block11_sepconv2_act[0][0]'] \n", + " v2D) 728) \n", + " \n", + " block11_sepconv2_bn (BatchNorm (None, None, None, 2912 ['block11_sepconv2[0][0]'] \n", + " alization) 728) \n", + " \n", + " block11_sepconv3_act (Activati (None, None, None, 0 ['block11_sepconv2_bn[0][0]'] \n", + " on) 728) \n", + " \n", + " block11_sepconv3 (SeparableCon (None, None, None, 536536 ['block11_sepconv3_act[0][0]'] \n", + " v2D) 728) \n", + " \n", + " block11_sepconv3_bn (BatchNorm (None, None, None, 2912 ['block11_sepconv3[0][0]'] \n", + " alization) 728) \n", + " \n", + " add_9 (Add) (None, None, None, 0 ['block11_sepconv3_bn[0][0]', \n", + " 728) 'add_8[0][0]'] \n", + " \n", + " block12_sepconv1_act (Activati (None, None, None, 0 ['add_9[0][0]'] \n", + " on) 728) \n", + " \n", + " block12_sepconv1 (SeparableCon (None, None, None, 536536 ['block12_sepconv1_act[0][0]'] \n", + " v2D) 728) \n", + " \n", + " block12_sepconv1_bn (BatchNorm (None, None, None, 2912 ['block12_sepconv1[0][0]'] \n", + " alization) 728) \n", + " \n", + " block12_sepconv2_act (Activati (None, None, None, 0 ['block12_sepconv1_bn[0][0]'] \n", + " on) 728) \n", + " \n", + " block12_sepconv2 (SeparableCon (None, None, None, 536536 ['block12_sepconv2_act[0][0]'] \n", + " v2D) 728) \n", + " \n", + " block12_sepconv2_bn (BatchNorm (None, None, None, 2912 ['block12_sepconv2[0][0]'] \n", + " alization) 728) \n", + " \n", + " block12_sepconv3_act (Activati (None, None, None, 0 ['block12_sepconv2_bn[0][0]'] \n", + " on) 728) \n", + " \n", + " block12_sepconv3 (SeparableCon (None, None, None, 536536 ['block12_sepconv3_act[0][0]'] \n", + " v2D) 728) \n", + " \n", + " block12_sepconv3_bn (BatchNorm (None, None, None, 2912 ['block12_sepconv3[0][0]'] \n", + " alization) 728) \n", + " \n", + " add_10 (Add) (None, None, None, 0 ['block12_sepconv3_bn[0][0]', \n", + " 728) 'add_9[0][0]'] \n", + " \n", + " block13_sepconv1_act (Activati (None, None, None, 0 ['add_10[0][0]'] \n", + " on) 728) \n", + " \n", + " block13_sepconv1 (SeparableCon (None, None, None, 536536 ['block13_sepconv1_act[0][0]'] \n", + " v2D) 728) \n", + " \n", + " block13_sepconv1_bn (BatchNorm (None, None, None, 2912 ['block13_sepconv1[0][0]'] \n", + " alization) 728) \n", + " \n", + " block13_sepconv2_act (Activati (None, None, None, 0 ['block13_sepconv1_bn[0][0]'] \n", + " on) 728) \n", + " \n", + " block13_sepconv2 (SeparableCon (None, None, None, 752024 ['block13_sepconv2_act[0][0]'] \n", + " v2D) 1024) \n", + " \n", + " block13_sepconv2_bn (BatchNorm (None, None, None, 4096 ['block13_sepconv2[0][0]'] \n", + " alization) 1024) \n", + " \n", + " conv2d_3 (Conv2D) (None, None, None, 745472 ['add_10[0][0]'] \n", + " 1024) \n", + " \n", + " block13_pool (MaxPooling2D) (None, None, None, 0 ['block13_sepconv2_bn[0][0]'] \n", + " 1024) \n", + " \n", + " batch_normalization_3 (BatchNo (None, None, None, 4096 ['conv2d_3[0][0]'] \n", + " rmalization) 1024) \n", + " \n", + " add_11 (Add) (None, None, None, 0 ['block13_pool[0][0]', \n", + " 1024) 'batch_normalization_3[0][0]'] \n", + " \n", + " block14_sepconv1 (SeparableCon (None, None, None, 1582080 ['add_11[0][0]'] \n", + " v2D) 1536) \n", + " \n", + " block14_sepconv1_bn (BatchNorm (None, None, None, 6144 ['block14_sepconv1[0][0]'] \n", + " alization) 1536) \n", + " \n", + " block14_sepconv1_act (Activati (None, None, None, 0 ['block14_sepconv1_bn[0][0]'] \n", + " on) 1536) \n", + " \n", + " block14_sepconv2 (SeparableCon (None, None, None, 3159552 ['block14_sepconv1_act[0][0]'] \n", + " v2D) 2048) \n", + " \n", + " block14_sepconv2_bn (BatchNorm (None, None, None, 8192 ['block14_sepconv2[0][0]'] \n", + " alization) 2048) \n", + " \n", + " block14_sepconv2_act (Activati (None, None, None, 0 ['block14_sepconv2_bn[0][0]'] \n", + " on) 2048) \n", + " \n", + " global_average_pooling2d (Glob (None, 2048) 0 ['block14_sepconv2_act[0][0]'] \n", + " alAveragePooling2D) \n", + " \n", + " dense (Dense) (None, 13) 26637 ['global_average_pooling2d[0][0]'\n", + " ] \n", + " \n", + "==================================================================================================\n", + "Total params: 20,888,117\n", + "Trainable params: 20,833,589\n", + "Non-trainable params: 54,528\n", + "__________________________________________________________________________________________________\n" + ] + } + ], + "source": [ + "for layer in base_model.layers:\n", + " layer.trainable = True\n", + " \n", + "output = Dense(13, activation='softmax')(base_model.output)\n", + "model = tf.keras.Model(base_model.input, output)\n", + "#model = add_regularization(model)\n", + "model.summary()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "ea620129", + "metadata": {}, + "outputs": [], + "source": [ + "#model.add(Dropout(.5))\n", + "#model.add(Dense(64, activation='softmax'))\n", + "# model.add(Dropout(.25))\n", + "#model = add_regularization(model)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "fd5d1246", + "metadata": {}, + "outputs": [], + "source": [ + "model.compile(optimizer=Adam(learning_rate=.0001), loss='categorical_crossentropy',\n", + " metrics=['accuracy'])\n", + "# sparse_categorical_crossentropy" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "9cd2ba27", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epoch 1/30\n", + "80/80 [==============================] - 78s 913ms/step - loss: 1.8419 - accuracy: 0.4153 - val_loss: 2.6144 - val_accuracy: 0.0720\n", + "Epoch 2/30\n", + "80/80 [==============================] - 69s 862ms/step - loss: 0.9255 - accuracy: 0.7121 - val_loss: 2.5804 - val_accuracy: 0.1026\n", + "Epoch 3/30\n", + "80/80 [==============================] - 72s 900ms/step - loss: 0.4003 - accuracy: 0.9092 - val_loss: 2.4443 - val_accuracy: 0.2310\n", + "Epoch 4/30\n", + "80/80 [==============================] - 71s 888ms/step - loss: 0.1224 - accuracy: 0.9847 - val_loss: 2.1299 - val_accuracy: 0.3782\n", + "Epoch 5/30\n", + "80/80 [==============================] - 75s 935ms/step - loss: 0.0371 - accuracy: 0.9975 - val_loss: 1.7368 - val_accuracy: 0.4973\n", + "Epoch 6/30\n", + "80/80 [==============================] - 73s 900ms/step - loss: 0.0167 - accuracy: 0.9992 - val_loss: 1.6747 - val_accuracy: 0.5341\n", + "Epoch 7/30\n", + "80/80 [==============================] - 72s 897ms/step - loss: 0.0097 - accuracy: 0.9998 - val_loss: 1.6494 - val_accuracy: 0.5442\n", + "Epoch 8/30\n", + "80/80 [==============================] - 74s 915ms/step - loss: 0.0062 - accuracy: 0.9998 - val_loss: 1.6659 - val_accuracy: 0.5568\n", + "Epoch 9/30\n", + "80/80 [==============================] - 74s 917ms/step - loss: 0.0044 - accuracy: 1.0000 - val_loss: 1.7088 - val_accuracy: 0.5615\n", + "Epoch 10/30\n", + "80/80 [==============================] - 70s 868ms/step - loss: 0.0035 - accuracy: 1.0000 - val_loss: 1.7540 - val_accuracy: 0.5583\n", + "Epoch 11/30\n", + "80/80 [==============================] - 70s 864ms/step - loss: 0.0027 - accuracy: 0.9998 - val_loss: 1.7894 - val_accuracy: 0.5552\n", + "Epoch 12/30\n", + "80/80 [==============================] - 69s 858ms/step - loss: 0.0020 - accuracy: 1.0000 - val_loss: 1.8126 - val_accuracy: 0.5536\n", + "Epoch 13/30\n", + "80/80 [==============================] - 69s 857ms/step - loss: 0.0019 - accuracy: 1.0000 - val_loss: 1.8496 - val_accuracy: 0.5544\n", + "Epoch 14/30\n", + "80/80 [==============================] - 69s 859ms/step - loss: 0.0015 - accuracy: 1.0000 - val_loss: 1.8646 - val_accuracy: 0.5544\n", + "Epoch 15/30\n", + "30/80 [==========>...................] - ETA: 36s - loss: 0.0011 - accuracy: 1.0000" + ] + }, + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m model.fit(x=train_generator,\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_generator\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[1;32m 3\u001b[0m \u001b[0mvalidation_data\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mvalidation_generator\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mvalidation_steps\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalidation_generator\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[1;32m 5\u001b[0m \u001b[0mepochs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m30\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 64\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 65\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# pylint: disable=broad-except\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 66\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_process_traceback_frames\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__traceback__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/engine/training.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)\u001b[0m\n\u001b[1;32m 1219\u001b[0m \u001b[0mlogs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtmp_logs\u001b[0m \u001b[0;31m# No error, now safe to assign to logs.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1220\u001b[0m \u001b[0mend_step\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstep\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mdata_handler\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstep_increment\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1221\u001b[0;31m \u001b[0mcallbacks\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_train_batch_end\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mend_step\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlogs\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 1222\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstop_training\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1223\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/callbacks.py\u001b[0m in \u001b[0;36mon_train_batch_end\u001b[0;34m(self, batch, logs)\u001b[0m\n\u001b[1;32m 434\u001b[0m \"\"\"\n\u001b[1;32m 435\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_should_call_train_batch_hooks\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 436\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_batch_hook\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mModeKeys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTRAIN\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'end'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlogs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlogs\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 437\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 438\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mon_test_batch_begin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlogs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\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[0;32m/usr/local/lib/python3.8/dist-packages/keras/callbacks.py\u001b[0m in \u001b[0;36m_call_batch_hook\u001b[0;34m(self, mode, hook, batch, logs)\u001b[0m\n\u001b[1;32m 293\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_batch_begin_hook\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlogs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 294\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mhook\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'end'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 295\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_batch_end_hook\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlogs\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 296\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 297\u001b[0m raise ValueError(\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/callbacks.py\u001b[0m in \u001b[0;36m_call_batch_end_hook\u001b[0;34m(self, mode, batch, logs)\u001b[0m\n\u001b[1;32m 314\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_batch_times\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbatch_time\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 315\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 316\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_batch_hook_helper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhook_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlogs\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 317\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 318\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_batch_times\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m>=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_num_batches_for_timing_check\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/callbacks.py\u001b[0m in \u001b[0;36m_call_batch_hook_helper\u001b[0;34m(self, hook_name, batch, logs)\u001b[0m\n\u001b[1;32m 352\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mcallback\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcallbacks\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 353\u001b[0m \u001b[0mhook\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcallback\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhook_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 354\u001b[0;31m \u001b[0mhook\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlogs\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 355\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 356\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_check_timing\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/callbacks.py\u001b[0m in \u001b[0;36mon_train_batch_end\u001b[0;34m(self, batch, logs)\u001b[0m\n\u001b[1;32m 1030\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1031\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mon_train_batch_end\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlogs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\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[0;32m-> 1032\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_batch_update_progbar\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlogs\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 1033\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1034\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mon_test_batch_end\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlogs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\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[0;32m/usr/local/lib/python3.8/dist-packages/keras/callbacks.py\u001b[0m in \u001b[0;36m_batch_update_progbar\u001b[0;34m(self, batch, logs)\u001b[0m\n\u001b[1;32m 1102\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1103\u001b[0m \u001b[0;31m# Only block async when verbose = 1.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1104\u001b[0;31m \u001b[0mlogs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf_utils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msync_to_numpy_or_python_type\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlogs\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 1105\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprogbar\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mseen\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlogs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfinalize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/utils/tf_utils.py\u001b[0m in \u001b[0;36msync_to_numpy_or_python_type\u001b[0;34m(tensors)\u001b[0m\n\u001b[1;32m 552\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mt\u001b[0m \u001b[0;31m# Don't turn ragged or sparse tensors to NumPy.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 553\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 554\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnest\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmap_structure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_to_single_numpy_or_python_type\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtensors\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 555\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 556\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/tensorflow/python/util/nest.py\u001b[0m in \u001b[0;36mmap_structure\u001b[0;34m(func, *structure, **kwargs)\u001b[0m\n\u001b[1;32m 867\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 868\u001b[0m return pack_sequence_as(\n\u001b[0;32m--> 869\u001b[0;31m \u001b[0mstructure\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mentries\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 870\u001b[0m expand_composites=expand_composites)\n\u001b[1;32m 871\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/tensorflow/python/util/nest.py\u001b[0m in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 867\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 868\u001b[0m return pack_sequence_as(\n\u001b[0;32m--> 869\u001b[0;31m \u001b[0mstructure\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mentries\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 870\u001b[0m expand_composites=expand_composites)\n\u001b[1;32m 871\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/keras/utils/tf_utils.py\u001b[0m in \u001b[0;36m_to_single_numpy_or_python_type\u001b[0;34m(t)\u001b[0m\n\u001b[1;32m 548\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_to_single_numpy_or_python_type\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\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[1;32m 549\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTensor\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[0;32m--> 550\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnumpy\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 551\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndim\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 552\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mt\u001b[0m \u001b[0;31m# Don't turn ragged or sparse tensors to NumPy.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/ops.py\u001b[0m in \u001b[0;36mnumpy\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1147\u001b[0m \"\"\"\n\u001b[1;32m 1148\u001b[0m \u001b[0;31m# TODO(slebedev): Consider avoiding a copy for non-CPU or remote tensors.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1149\u001b[0;31m \u001b[0mmaybe_arr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_numpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# pylint: disable=protected-access\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1150\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mmaybe_arr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcopy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmaybe_arr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndarray\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mmaybe_arr\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1151\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/ops.py\u001b[0m in \u001b[0;36m_numpy\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1113\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_numpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\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[1;32m 1114\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1115\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_numpy_internal\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 1116\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mcore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_NotOkStatusException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# pylint: disable=protected-access\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1117\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mcore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_status_to_exception\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;31m# pylint: disable=protected-access\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], + "source": [ + "model.fit(x=train_generator,\n", + " steps_per_epoch=len(train_generator),\n", + " validation_data=validation_generator,\n", + " validation_steps=len(validation_generator),\n", + " epochs=30,\n", + " verbose=1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63f791af", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/ebay_api.py b/ebay_api.py index 84f2300..8b57d3f 100644 --- a/ebay_api.py +++ b/ebay_api.py @@ -27,20 +27,20 @@ class FindingApi: Methods for accessing eBay's FindingApi services ''' - def __init__(self, service, idspc): + def __init__(self, service): self.service = [ 'findItemsAdvanced', 'findCompletedItems', 'findItemsByKeywords', 'findItemsIneBayStores', 'findItemsByCategory', 'findItemsByProduct' ][service] # Currently using only index 4, i.e., service = 4 - self.idspc = idspc # examples of additional params you may want to add: + # examples of additional params you may want to add: # 'itemFilter(0).value':'Used' consider using this with findCompletedItems call # 'itemFilter(1).name':'ListingType' # 'itemFilter(1).value':'AuctionWithBIN' # 'StartTimeNewest' # HideDuplicateItems - def get_data(self, category_id, idspc): + def get_data(self, category_id): ''' Gets raw JSON data fom FindingApi service call. Currently being used to @@ -51,8 +51,6 @@ class FindingApi: # days_on_site = (now - startTime).days # as int ids = [] - modTimeFrom = datetime.now() - timedelta(seconds=5) # initialize modTimeFrom value - i = 1 params = { "OPERATION-NAME":self.service, "SECURITY-APPNAME":cfg.sec['SECURITY-APPNAME'], @@ -60,62 +58,37 @@ class FindingApi: "RESPONSE-DATA-FORMAT":"JSON", "categoryId":category_id, "paginationInput.entriesPerPage":"100", - "paginationInput.PageNumber":i, + "paginationInput.PageNumber":"1", "itemFilter(0).name":"Condition", "itemFilter(0).value":"Used", "itemFilter.name":"HideDuplicateItems", "itemFilter.value":"true", "sortOrder":"StartTimeNewest", + "itemFilter(1).name":"TopRatedSellerOnly", + "itemFilter(1).value":"true", } -# "itemFilter.name(2)":"modTimeFrom", -# "itemFilter.value(2)":modTimeFrom, + try: + response = requests.get("https://svcs.ebay.com/services/search/FindingService/v1", + params=params, timeout=24) + response.raise_for_status() - while len(ids) < idspc: + except requests.exceptions.RequestException: # appears this works need to be able to continue where you left off or use better timeout? + print('connection error') + return ids + try: + data = response.json() + for item in data['findItemsByCategoryResponse'][0]['searchResult'][0]['item']: + ids.append(item['itemId'][0]) - try: - response = requests.get("https://svcs.ebay.com/services/search/FindingService/v1", - params=params, timeout=24) - response.raise_for_status() + ids = list(set(ids)) - except requests.exceptions.RequestException: # appears this works need to be able to continue where you left off or use better timeout? - print('connection error') - return ids - try: - data = response.json() - itemSearchURL = data['findItemsByCategoryResponse'][0]['itemSearchURL'][0] - modTimeFrom = data['findItemsByCategoryResponse'][0]['searchResult'][0]['item'][-1]['listingInfo'][0]['startTime'][0] - modTimeFrom = dateutil.parser.isoparse( modTimeFrom ) - modTimeFrom = modTimeFrom - timedelta(seconds=5) # TODO NEED BACK TO GMT FORMAT - for item in data['findItemsByCategoryResponse'][0]['searchResult'][0]['item']: -# if item not in ids: - ids.append(item['itemId'][0]) + except (AttributeError, KeyError): + print('AttributeError or KeyError. Exiting') + print(response.json()) + return ids - #ids = list(set(ids)) - - except (AttributeError, KeyError): - print('AttributeError or KeyError. Exiting') - print(response.json()) - return ids - - input('press enter to continue') - i+=1 - params = { - "OPERATION-NAME":self.service, - "SECURITY-APPNAME":cfg.sec['SECURITY-APPNAME'], - "SERVICE-VERSION":"1.13.0", - "RESPONSE-DATA-FORMAT":"JSON", - "categoryId":category_id, - "paginationInput.entriesPerPage":"20", - "paginationInput.PageNumber":i, - "itemFilter(0).name":"Condition", - "itemFilter(0).value":"Used", - "itemFilter.name":"HideDuplicateItems", - "itemFilter.value":"true", - "sortOrder":"StartTimeNewest", - } - - return ids, data, modTimeFrom, itemSearchURL + return ids # TODO add some other options to finding call api such as for possibly filtering for used items only. This might give you a better dataset for training. Or maybe a mixture of new and used. Maybe # try and come up with a way to mathematically determine your odds of maximizing the number of pictures in your training set while reducing the number of useless images. Say for example, if you took a @@ -125,36 +98,32 @@ class FindingApi: # You may even have more consistency with used shoes since they are "one-off" items without confusing multiple variations and colors. What else you can do is run small training sets on both new and used # to see which one is more accurate or if a combo of both is more accurate. - def get_ids_from_cats(self): #TODO need to resolve duplicates here to maximize unique ids/data and ShopppingApi call + def get_ids_from_cats(self): ''' Creates a 20-itemId list to use for the ShoppingApi call ''' -# target_idspc = self.target_idspc - idspc = self.idspc itemid_results_list = [] with open('cat_list.txt') as jf: cat_list = json.load(jf) - for cat in cat_list: - args = [(cat, idspc) for cat in cat_list] - - with concurrent.futures.ThreadPoolExecutor() as executor: - for future in executor.map(lambda p: self.get_data(*p), args): - itemid_results_list.extend(future) + with concurrent.futures.ThreadPoolExecutor() as executor: + for future in executor.map(self.get_data, cat_list): + itemid_results_list.extend(future) print(len(itemid_results_list)) a = list(set(itemid_results_list)) print(len(a)) - input('press enter to continue') with open('raw_ids.txt', 'w') as f: json.dump(itemid_results_list, f) + # 20-ItemID list created to maximize dataset/decrease calls given call constraints item_id_results = [','.join(itemid_results_list[n:n+20]) for n in list(range(0, - len(itemid_results_list), 20))] # 20-ItemID list created to maximize dataset/decrease calls given call constraints + len(itemid_results_list), 20))] + return item_id_results, itemid_results_list class ShoppingApi: