{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":3362,"databundleVersionId":31148,"sourceType":"competition"}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2025-03-17T14:19:27.179314Z","iopub.execute_input":"2025-03-17T14:19:27.179639Z","iopub.status.idle":"2025-03-17T14:19:27.49182Z","shell.execute_reply.started":"2025-03-17T14:19:27.179606Z","shell.execute_reply":"2025-03-17T14:19:27.49097Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!python --version","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:19:27.49349Z","iopub.execute_input":"2025-03-17T14:19:27.493857Z","iopub.status.idle":"2025-03-17T14:19:28.561818Z","shell.execute_reply.started":"2025-03-17T14:19:27.493834Z","shell.execute_reply":"2025-03-17T14:19:28.560797Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nprint(os.listdir(\"../input\"))\n\nimport zipfile\n\nwith zipfile.ZipFile(\"/kaggle/input/dogs-vs-cats/test1.zip\",\"r\") as z:\n    z.extractall(\".\")\n    \nwith zipfile.ZipFile(\"/kaggle/input/dogs-vs-cats/train.zip\",\"r\") as z:\n    z.extractall(\".\")","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:19:28.566051Z","iopub.execute_input":"2025-03-17T14:19:28.566281Z","iopub.status.idle":"2025-03-17T14:19:42.069367Z","shell.execute_reply.started":"2025-03-17T14:19:28.566258Z","shell.execute_reply":"2025-03-17T14:19:42.068206Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ls","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:19:42.070542Z","iopub.execute_input":"2025-03-17T14:19:42.07087Z","iopub.status.idle":"2025-03-17T14:19:43.087336Z","shell.execute_reply.started":"2025-03-17T14:19:42.07084Z","shell.execute_reply":"2025-03-17T14:19:43.086496Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ls -l","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:19:43.088912Z","iopub.execute_input":"2025-03-17T14:19:43.089592Z","iopub.status.idle":"2025-03-17T14:19:44.07704Z","shell.execute_reply.started":"2025-03-17T14:19:43.089555Z","shell.execute_reply":"2025-03-17T14:19:44.075993Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ls test1/ | wc -l","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:19:44.080101Z","iopub.execute_input":"2025-03-17T14:19:44.080364Z","iopub.status.idle":"2025-03-17T14:19:45.276209Z","shell.execute_reply.started":"2025-03-17T14:19:44.080341Z","shell.execute_reply":"2025-03-17T14:19:45.27532Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ls train/ | wc -l","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:19:45.277439Z","iopub.execute_input":"2025-03-17T14:19:45.277708Z","iopub.status.idle":"2025-03-17T14:19:46.379148Z","shell.execute_reply.started":"2025-03-17T14:19:45.277684Z","shell.execute_reply":"2025-03-17T14:19:46.378322Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ls train/","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:19:46.380395Z","iopub.execute_input":"2025-03-17T14:19:46.380659Z","iopub.status.idle":"2025-03-17T14:19:47.537152Z","shell.execute_reply.started":"2025-03-17T14:19:46.380634Z","shell.execute_reply":"2025-03-17T14:19:47.536127Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# plot dog photos from the dogs vs cats dataset\nfrom matplotlib import pyplot\nfrom matplotlib.image import imread\n# define location of dataset\nfolder = 'train/'\n# plot first few images\nfor i in range(9):\n\t# define subplot\n\tpyplot.subplot(330 + 1 + i)\n\t# define filename\n\tfilename = folder + 'dog.' + str(i) + '.jpg'\n\t# load image pixels\n\timage = imread(filename)\n\t# plot raw pixel data\n\tpyplot.imshow(image)\n# show the figure\npyplot.show()","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:19:47.538625Z","iopub.execute_input":"2025-03-17T14:19:47.538988Z","iopub.status.idle":"2025-03-17T14:19:48.594491Z","shell.execute_reply.started":"2025-03-17T14:19:47.538955Z","shell.execute_reply":"2025-03-17T14:19:48.593587Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# plot cat photos from the dogs vs cats dataset\nfrom matplotlib import pyplot\nfrom matplotlib.image import imread\n# define location of dataset\nfolder = 'train/'\n# plot first few images\nfor i in range(9):\n\t# define subplot\n\tpyplot.subplot(330 + 1 + i)\n\t# define filename\n\tfilename = folder + 'cat.' + str(i) + '.jpg'\n\t# load image pixels\n\timage = imread(filename)\n\t# plot raw pixel data\n\tpyplot.imshow(image)\n# show the figure\npyplot.show()","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:19:48.595593Z","iopub.execute_input":"2025-03-17T14:19:48.595866Z","iopub.status.idle":"2025-03-17T14:19:49.54659Z","shell.execute_reply.started":"2025-03-17T14:19:48.595843Z","shell.execute_reply":"2025-03-17T14:19:49.545795Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import tensorflow\nprint(tensorflow.__version__)\n\nimport keras\nprint(keras.__version__)\n\nimport tensorflow.keras\nprint(tensorflow.__version__)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:19:49.54783Z","iopub.execute_input":"2025-03-17T14:19:49.548058Z","iopub.status.idle":"2025-03-17T14:20:05.072965Z","shell.execute_reply.started":"2025-03-17T14:19:49.548037Z","shell.execute_reply":"2025-03-17T14:20:05.072076Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# load dogs vs cats dataset, reshape and save to a new file\nfrom os import listdir\nfrom numpy import asarray\nfrom numpy import save\nfrom keras.preprocessing.image import load_img\nfrom keras.preprocessing.image import img_to_array","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:20:05.074275Z","iopub.execute_input":"2025-03-17T14:20:05.075389Z","iopub.status.idle":"2025-03-17T14:20:05.079753Z","shell.execute_reply.started":"2025-03-17T14:20:05.075353Z","shell.execute_reply":"2025-03-17T14:20:05.078933Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# define location of dataset\nfolder = 'train/'\nphotos, labels = list(), list()\n# enumerate files in the directory\nfor file in listdir(folder):\n\t# determine class\n\toutput = 0.0\n\tif file.startswith('dog'):\n\t\toutput = 1.0\n\t# load image\n\tphoto = load_img(folder + file, target_size=(200, 200))\n\t# convert to numpy array\n\tphoto = img_to_array(photo)\n\t# store\n\tphotos.append(photo)\n\tlabels.append(output)\n# convert to a numpy arrays\nphotos = asarray(photos)\nlabels = asarray(labels)\nprint(photos.shape, labels.shape)\n# save the reshaped photos\nsave('dogs_vs_cats_photos.npy', photos)\nsave('dogs_vs_cats_labels.npy', labels)","metadata":{"execution":{"iopub.status.busy":"2024-01-27T03:36:15.416611Z","iopub.execute_input":"2024-01-27T03:36:15.417128Z","iopub.status.idle":"2024-01-27T03:36:38.886396Z","shell.execute_reply.started":"2024-01-27T03:36:15.417101Z","shell.execute_reply":"2024-01-27T03:36:38.883149Z"}}},{"cell_type":"markdown","source":"# load and confirm the shape\nfrom numpy import load\nphotos = load('dogs_vs_cats_photos.npy')\nlabels = load('dogs_vs_cats_labels.npy')","metadata":{"execution":{"iopub.status.busy":"2024-01-27T03:36:38.88711Z","iopub.status.idle":"2024-01-27T03:36:38.887458Z","shell.execute_reply.started":"2024-01-27T03:36:38.887281Z","shell.execute_reply":"2024-01-27T03:36:38.887296Z"}}},{"cell_type":"code","source":"# organize dataset into a useful structure\nfrom os import makedirs\nfrom os import listdir\nfrom shutil import copyfile\nfrom random import seed\nfrom random import random","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:20:05.080923Z","iopub.execute_input":"2025-03-17T14:20:05.081196Z","iopub.status.idle":"2025-03-17T14:20:05.100162Z","shell.execute_reply.started":"2025-03-17T14:20:05.081173Z","shell.execute_reply":"2025-03-17T14:20:05.099504Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# create directories\ndataset_home = 'dataset_dogs_vs_cats/'\nsubdirs = ['train/', 'test/'] #test==>validation\nfor subdir in subdirs:\n    # create label subdirectories\n    labeldirs = ['dogs/', 'cats/']\n    for labldir in labeldirs:\n        newdir = dataset_home + subdir + labldir       \n        makedirs(newdir, exist_ok=True)\n        print(newdir)","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:20:05.101047Z","iopub.execute_input":"2025-03-17T14:20:05.101281Z","iopub.status.idle":"2025-03-17T14:20:05.111972Z","shell.execute_reply.started":"2025-03-17T14:20:05.10126Z","shell.execute_reply":"2025-03-17T14:20:05.111192Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ls -l dataset_dogs_vs_cats/train/dogs/","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:20:05.113194Z","iopub.execute_input":"2025-03-17T14:20:05.113493Z","iopub.status.idle":"2025-03-17T14:20:06.13771Z","shell.execute_reply.started":"2025-03-17T14:20:05.113465Z","shell.execute_reply":"2025-03-17T14:20:06.136872Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ls -l","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:20:06.138995Z","iopub.execute_input":"2025-03-17T14:20:06.139236Z","iopub.status.idle":"2025-03-17T14:20:07.156529Z","shell.execute_reply.started":"2025-03-17T14:20:06.139215Z","shell.execute_reply":"2025-03-17T14:20:07.154972Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ls -l dataset_dogs_vs_cats/train","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:20:07.158358Z","iopub.execute_input":"2025-03-17T14:20:07.158804Z","iopub.status.idle":"2025-03-17T14:20:08.167556Z","shell.execute_reply.started":"2025-03-17T14:20:07.158766Z","shell.execute_reply":"2025-03-17T14:20:08.16644Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ls -l dataset_dogs_vs_cats/test","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:20:08.169273Z","iopub.execute_input":"2025-03-17T14:20:08.169651Z","iopub.status.idle":"2025-03-17T14:20:09.18611Z","shell.execute_reply.started":"2025-03-17T14:20:08.169618Z","shell.execute_reply":"2025-03-17T14:20:09.185154Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# seed random number generator\nseed(1337)\n# define ratio of pictures to use for validation\nval_ratio = 0.25 #changable\n# copy training dataset images into subdirectories\nsrc_directory = 'train/'\n\nfor file in listdir(src_directory):\n\tsrc = src_directory + '/' + file\n\tdst_dir = 'train/'\n\tif random() < val_ratio:\n\t\tdst_dir = 'test/'\n\tif file.startswith('cat'):\n\t\tdst = dataset_home + dst_dir + 'cats/'  + file\n\t\tcopyfile(src, dst)\n\telif file.startswith('dog'):\n\t\tdst = dataset_home + dst_dir + 'dogs/'  + file\n\t\tcopyfile(src, dst)","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:20:09.18746Z","iopub.execute_input":"2025-03-17T14:20:09.187774Z","iopub.status.idle":"2025-03-17T14:20:11.509437Z","shell.execute_reply.started":"2025-03-17T14:20:09.187747Z","shell.execute_reply":"2025-03-17T14:20:11.508717Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(src)\nprint(dst)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:20:11.510464Z","iopub.execute_input":"2025-03-17T14:20:11.510773Z","iopub.status.idle":"2025-03-17T14:20:11.515029Z","shell.execute_reply.started":"2025-03-17T14:20:11.510713Z","shell.execute_reply":"2025-03-17T14:20:11.514236Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls -l dataset_dogs_vs_cats/train/dogs | wc -l\n!ls -l dataset_dogs_vs_cats/train/cats | wc -l","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:20:11.520362Z","iopub.execute_input":"2025-03-17T14:20:11.520846Z","iopub.status.idle":"2025-03-17T14:20:13.706639Z","shell.execute_reply.started":"2025-03-17T14:20:11.52082Z","shell.execute_reply":"2025-03-17T14:20:13.705795Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#validation set\n!ls -l dataset_dogs_vs_cats/test/dogs | wc -l\n!ls -l dataset_dogs_vs_cats/test/cats | wc -l","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:20:13.707824Z","iopub.execute_input":"2025-03-17T14:20:13.708098Z","iopub.status.idle":"2025-03-17T14:20:15.824603Z","shell.execute_reply.started":"2025-03-17T14:20:13.708075Z","shell.execute_reply":"2025-03-17T14:20:15.823508Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip -q install livelossplot==0.5.5","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:20:15.82681Z","iopub.execute_input":"2025-03-17T14:20:15.827188Z","iopub.status.idle":"2025-03-17T14:20:26.60466Z","shell.execute_reply.started":"2025-03-17T14:20:15.827159Z","shell.execute_reply":"2025-03-17T14:20:26.60348Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from livelossplot import PlotLossesKeras","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:20:26.6063Z","iopub.execute_input":"2025-03-17T14:20:26.606708Z","iopub.status.idle":"2025-03-17T14:20:26.624336Z","shell.execute_reply.started":"2025-03-17T14:20:26.60667Z","shell.execute_reply":"2025-03-17T14:20:26.623564Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Prepare Final Dataset","metadata":{}},{"cell_type":"markdown","source":"# Start tutorial\n# Develop a Baseline CNN Model","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"# https://keras.io/api/applications/","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:22:27.826137Z","iopub.execute_input":"2025-03-17T14:22:27.827027Z","iopub.status.idle":"2025-03-17T14:22:27.8307Z","shell.execute_reply.started":"2025-03-17T14:22:27.826995Z","shell.execute_reply":"2025-03-17T14:22:27.829754Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# baseline model for the dogs vs cats dataset\nimport sys\nfrom matplotlib import pyplot\nfrom keras.utils import to_categorical\nfrom keras.models import Sequential\nfrom keras.layers import Conv2D\nfrom keras.layers import MaxPooling2D\nfrom keras.layers import Dense\nfrom keras.layers import Flatten\nfrom keras.optimizers import SGD\nfrom keras.preprocessing.image import ImageDataGenerator","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:49:47.319216Z","iopub.execute_input":"2025-03-17T14:49:47.320008Z","iopub.status.idle":"2025-03-17T14:49:47.324538Z","shell.execute_reply.started":"2025-03-17T14:49:47.319978Z","shell.execute_reply":"2025-03-17T14:49:47.323695Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# define cnn model\ndef define_model_1():\n\tmodel = Sequential()\n\tmodel.add(Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same', input_shape=(200, 200, 3)))\n\tmodel.add(MaxPooling2D((2, 2)))\n\tmodel.add(Flatten())\n\tmodel.add(Dense(128, activation='relu', kernel_initializer='he_uniform'))\n\tmodel.add(Dense(1, activation='sigmoid'))\n\t# compile model\n\topt = SGD(lr=0.001, momentum=0.9)\n\tmodel.compile(optimizer=opt, loss='binary_crossentropy', metrics=['accuracy'])\n\treturn model","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:49:49.842346Z","iopub.execute_input":"2025-03-17T14:49:49.843154Z","iopub.status.idle":"2025-03-17T14:49:49.848425Z","shell.execute_reply.started":"2025-03-17T14:49:49.843122Z","shell.execute_reply":"2025-03-17T14:49:49.847568Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# plot diagnostic learning curves\ndef summarize_diagnostics(history):\n    # plot loss\n    pyplot.subplot(211)\n    pyplot.title('Cross Entropy Loss')\n    pyplot.plot(history.history['loss'], color='blue', label='train')\n    pyplot.plot(history.history['val_loss'], color='orange', label='test')\n    # plot accuracy\n    pyplot.subplot(212)\n    pyplot.title('Classification Accuracy')\n    pyplot.plot(history.history['accuracy'], color='blue', label='train')\n    pyplot.plot(history.history['val_accuracy'], color='orange', label='test')\n    pyplot.show()\n    \n    # save plot to file\n    filename = sys.argv[0].split('/')[-1]\n    pyplot.savefig(filename + '_plot.png') \n    pyplot.close()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:49:52.684987Z","iopub.execute_input":"2025-03-17T14:49:52.685287Z","iopub.status.idle":"2025-03-17T14:49:52.690856Z","shell.execute_reply.started":"2025-03-17T14:49:52.685266Z","shell.execute_reply":"2025-03-17T14:49:52.690033Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# run the test harness for evaluating a model\ndef run_test_harness():\n\t# define model\n\tmodel = define_model()\n\t# create data generator\n\tdatagen = ImageDataGenerator(rescale=1.0/255.0)\n\t# prepare iterators\n\ttrain_it = datagen.flow_from_directory('dataset_dogs_vs_cats/train/',\n\t\tclass_mode='binary', batch_size=64, target_size=(200, 200))\n\ttest_it = datagen.flow_from_directory('dataset_dogs_vs_cats/test/',\n\t\tclass_mode='binary', batch_size=64, target_size=(200, 200))\n\t# fit model\n\thistory = model.fit_generator(train_it, steps_per_epoch=len(train_it),\n\t\tvalidation_data=test_it, validation_steps=len(test_it), epochs=20, verbose=0)\n\t# evaluate model\n\t_, acc = model.evaluate_generator(test_it, steps=len(test_it), verbose=0)\n\tprint('> %.3f' % (acc * 100.0))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:49:55.591321Z","iopub.execute_input":"2025-03-17T14:49:55.592057Z","iopub.status.idle":"2025-03-17T14:49:55.59739Z","shell.execute_reply.started":"2025-03-17T14:49:55.592024Z","shell.execute_reply":"2025-03-17T14:49:55.596588Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import sys\nfrom matplotlib import pyplot\nfrom keras.utils import to_categorical\nfrom keras.applications.vgg16 import VGG16\nfrom keras.models import Model\nfrom keras.layers import Dense\nfrom keras.layers import Flatten\nfrom keras.optimizers import SGD\nfrom keras.preprocessing.image import ImageDataGenerator\n \n# define cnn model\ndef define_model():\n\t# load model\n\tmodel = VGG16(include_top=False, input_shape=(224, 224, 3))\n\t# mark loaded layers as not trainable\n\tfor layer in model.layers:\n\t\tlayer.trainable = False\n\t# add new classifier layers\n\tflat1 = Flatten()(model.layers[-1].output)\n\tclass1 = Dense(128, activation='relu', kernel_initializer='he_uniform')(flat1)\n\toutput = Dense(1, activation='sigmoid')(class1)\n\t# define new model\n\tmodel = Model(inputs=model.inputs, outputs=output)\n\t# compile model\n\topt = SGD(lr=0.001, momentum=0.9)\n\tmodel.compile(optimizer=opt, loss='binary_crossentropy', metrics=['accuracy'])\n\treturn model\n \n# plot diagnostic learning curves\ndef summarize_diagnostics(history):\n\t# plot loss\n\tpyplot.subplot(211)\n\tpyplot.title('Cross Entropy Loss')\n\tpyplot.plot(history.history['loss'], color='blue', label='train')\n\tpyplot.plot(history.history['val_loss'], color='orange', label='test')\n\t# plot accuracy\n\tpyplot.subplot(212)\n\tpyplot.title('Classification Accuracy')\n\tpyplot.plot(history.history['accuracy'], color='blue', label='train')\n\tpyplot.plot(history.history['val_accuracy'], color='orange', label='test')\n\t# save plot to file\n\tfilename = sys.argv[0].split('/')[-1]\n\tpyplot.savefig(filename + '_plot.png')\n\tpyplot.close()\n \n# run the test harness for evaluating a model\ndef run_test_harness():\n\t# define model\n\tmodel = define_model()\n\t# create data generator\n\tdatagen = ImageDataGenerator(featurewise_center=True)\n\t# specify imagenet mean values for centering\n\tdatagen.mean = [123.68, 116.779, 103.939]\n\t# prepare iterator\n\ttrain_it = datagen.flow_from_directory('dataset_dogs_vs_cats/train/',\n\t\tclass_mode='binary', batch_size=64, target_size=(224, 224))\n\ttest_it = datagen.flow_from_directory('dataset_dogs_vs_cats/test/',\n\t\tclass_mode='binary', batch_size=64, target_size=(224, 224))\n\t# fit model\n\thistory = model.fit_generator(train_it, steps_per_epoch=len(train_it),\n\t\tvalidation_data=test_it, validation_steps=len(test_it), epochs=10, verbose=1)\n\t# evaluate model\n\t_, acc = model.evaluate_generator(test_it, steps=len(test_it), verbose=0)\n\tprint('> %.3f' % (acc * 100.0))\n\t# learning curves\n\tsummarize_diagnostics(history)\n \n# entry point, run the test harness\nrun_test_harness()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:50:39.143295Z","iopub.execute_input":"2025-03-17T14:50:39.144044Z","iopub.status.idle":"2025-03-17T15:12:01.161261Z","shell.execute_reply.started":"2025-03-17T14:50:39.144016Z","shell.execute_reply":"2025-03-17T15:12:01.160371Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"datagen = ImageDataGenerator(rescale=1.0/255.0)\n\n# prepare iterators\ntrain_it = datagen.flow_from_directory('dataset_dogs_vs_cats/train/',\n    class_mode='binary', batch_size=64, target_size=(200, 200))\n\nval_it = datagen.flow_from_directory('dataset_dogs_vs_cats/test/',\n    class_mode='binary', batch_size=64, target_size=(200, 200))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:15:51.132656Z","iopub.execute_input":"2025-03-17T15:15:51.133003Z","iopub.status.idle":"2025-03-17T15:15:51.853275Z","shell.execute_reply.started":"2025-03-17T15:15:51.13298Z","shell.execute_reply":"2025-03-17T15:15:51.852638Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(train_it), len(train_it.classes), train_it.classes[:10]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:15:55.297325Z","iopub.execute_input":"2025-03-17T15:15:55.297913Z","iopub.status.idle":"2025-03-17T15:15:55.303491Z","shell.execute_reply.started":"2025-03-17T15:15:55.297883Z","shell.execute_reply":"2025-03-17T15:15:55.302611Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(val_it), len(val_it.classes), val_it.classes[-10:]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:45:42.372598Z","iopub.execute_input":"2025-03-17T14:45:42.373198Z","iopub.status.idle":"2025-03-17T14:45:42.378727Z","shell.execute_reply.started":"2025-03-17T14:45:42.373168Z","shell.execute_reply":"2025-03-17T14:45:42.377875Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# fit model\nmodel_1.reset_states()\nhistory_1 = model_1.fit_generator(\n    train_it, steps_per_epoch=len(train_it),\n    validation_data=val_it,\n    validation_steps=len(val_it),\n    epochs=1, verbose=1,\n    callbacks = [PlotLossesKeras()]\n    )","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:45:53.2216Z","iopub.execute_input":"2025-03-17T14:45:53.22195Z","iopub.status.idle":"2025-03-17T14:46:38.043164Z","shell.execute_reply.started":"2025-03-17T14:45:53.221922Z","shell.execute_reply":"2025-03-17T14:46:38.042502Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# learning curves\nsummarize_diagnostics(history_1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:28:23.035646Z","iopub.execute_input":"2025-03-17T14:28:23.035995Z","iopub.status.idle":"2025-03-17T14:28:23.391241Z","shell.execute_reply.started":"2025-03-17T14:28:23.035969Z","shell.execute_reply":"2025-03-17T14:28:23.390573Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Evaluate model\n_, acc = model_1.evaluate(val_it, steps=len(val_it), verbose=1)\nprint('> %.3f' % (acc * 100.0))\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:43:04.661529Z","iopub.status.idle":"2025-03-17T14:43:04.661842Z","shell.execute_reply.started":"2025-03-17T14:43:04.661678Z","shell.execute_reply":"2025-03-17T14:43:04.661692Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ls ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:32:09.449427Z","iopub.execute_input":"2025-03-17T14:32:09.449812Z","iopub.status.idle":"2025-03-17T14:32:10.486474Z","shell.execute_reply.started":"2025-03-17T14:32:09.449777Z","shell.execute_reply":"2025-03-17T14:32:10.485345Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pwd","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:32:12.222402Z","iopub.execute_input":"2025-03-17T14:32:12.222784Z","iopub.status.idle":"2025-03-17T14:32:12.22947Z","shell.execute_reply.started":"2025-03-17T14:32:12.222753Z","shell.execute_reply":"2025-03-17T14:32:12.228673Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport pandas as pd\nfrom glob import glob\n\n# Define the image folder path\nimage_folder = '/kaggle/working/test1'\n\n# List all .jpg files in the directory (adjust the pattern if needed)\nimage_files = glob(os.path.join(image_folder, '*.jpg'))\n\n# Check if images were found\nif not image_files:\n    print(\"No images found. Please verify the directory and file extensions.\")\n    \n# Create a DataFrame with the file paths\ndf = pd.DataFrame({'filename': image_files})\n\n# If your use-case doesn't require labels (for example, during testing), you can leave out the label column.\n# Otherwise, if you need a dummy label, you can add one:\n# df['class'] = 'dummy_label'\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:32:14.118334Z","iopub.execute_input":"2025-03-17T14:32:14.119184Z","iopub.status.idle":"2025-03-17T14:32:14.172321Z","shell.execute_reply.started":"2025-03-17T14:32:14.119153Z","shell.execute_reply":"2025-03-17T14:32:14.171669Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_files[:5], type(image_files), len(image_files)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:32:18.265093Z","iopub.execute_input":"2025-03-17T14:32:18.265917Z","iopub.status.idle":"2025-03-17T14:32:18.271675Z","shell.execute_reply.started":"2025-03-17T14:32:18.265884Z","shell.execute_reply":"2025-03-17T14:32:18.270869Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:32:21.295442Z","iopub.execute_input":"2025-03-17T14:32:21.296369Z","iopub.status.idle":"2025-03-17T14:32:21.359078Z","shell.execute_reply.started":"2025-03-17T14:32:21.296338Z","shell.execute_reply":"2025-03-17T14:32:21.358298Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.loc[1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:32:25.067543Z","iopub.execute_input":"2025-03-17T14:32:25.068299Z","iopub.status.idle":"2025-03-17T14:32:25.075682Z","shell.execute_reply.started":"2025-03-17T14:32:25.068267Z","shell.execute_reply":"2025-03-17T14:32:25.074695Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.sample(5)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:32:27.020156Z","iopub.execute_input":"2025-03-17T14:32:27.020822Z","iopub.status.idle":"2025-03-17T14:32:27.037873Z","shell.execute_reply.started":"2025-03-17T14:32:27.020784Z","shell.execute_reply":"2025-03-17T14:32:27.036988Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['filename']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:32:29.408622Z","iopub.execute_input":"2025-03-17T14:32:29.409554Z","iopub.status.idle":"2025-03-17T14:32:29.417235Z","shell.execute_reply.started":"2025-03-17T14:32:29.409514Z","shell.execute_reply":"2025-03-17T14:32:29.416426Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"IMAGE_SIZE = (299, 299)\n\ndatagen = ImageDataGenerator(rescale=1.0/255.0,\n                            horizontal_flip=True,)\n\n# prepare iterators\ntrain_it = datagen.flow_from_directory('dataset_dogs_vs_cats/train/',\n    class_mode='binary', batch_size=64, target_size=IMAGE_SIZE )\n\nval_it = datagen.flow_from_directory('dataset_dogs_vs_cats/test/',\n    class_mode='binary', batch_size=64, target_size=IMAGE_SIZE )\n\n# Prediction\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\n\n# Initialize your ImageDataGenerator (modify parameters as needed)\ndatagen_test = ImageDataGenerator(rescale=1./255,\n                                 horizontal_flip=True)\n\n# Create the data generator using the DataFrame\ntest_it = datagen_test.flow_from_dataframe(\n    dataframe=df,\n    x_col='filename',\n    y_col=None,            # No labels for testing, so set to None\n    target_size=IMAGE_SIZE,\n    batch_size=64,\n    class_mode=None,       # Since there are no labels\n    # shuffle=True,         # Usually testing data should not be shuffled\n    shuffle=False,\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:32:31.221882Z","iopub.execute_input":"2025-03-17T14:32:31.222237Z","iopub.status.idle":"2025-03-17T14:32:31.968093Z","shell.execute_reply.started":"2025-03-17T14:32:31.222201Z","shell.execute_reply":"2025-03-17T14:32:31.967137Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\ndef plot_exmaple(images):\n    # Assuming test_images is a numpy array with shape (64, height, width, channels)\n    fig, axes = plt.subplots(8, 8, figsize=(16, 16))\n    axes = axes.flatten()  # Flatten the 8x8 grid into a list for easy iteration\n    \n    for i, ax in enumerate(axes):\n        # Ensure there are enough images in the batch before plotting\n        if i < test_images.shape[0]:\n            ax.imshow(test_images[i])\n        ax.axis('off')  # Turn off axis ticks/labels for clarity\n    \n    plt.tight_layout()\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:32:51.797948Z","iopub.execute_input":"2025-03-17T14:32:51.798257Z","iopub.status.idle":"2025-03-17T14:32:51.803613Z","shell.execute_reply.started":"2025-03-17T14:32:51.798234Z","shell.execute_reply":"2025-03-17T14:32:51.802788Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\n\n# Assuming train_it is already defined as a data iterator\ntrain_images, train_labels = train_it.__next__()\n\n# Check the shape of the images batch\nprint(\"Train images shape:\", train_images.shape)\n\n# Function to plot an example image\ndef plot_example(images, labels, index=0):\n    plt.imshow(images[index], cmap='gray')  # Assuming grayscale images; change if RGB\n    plt.title(f\"Label: {labels[index]}\")\n    plt.axis('off')  # Turn off axes for cleaner look\n    plt.show()\n\n# Plot the first example image\nplot_example(train_images, train_labels, index=0)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:36:28.423611Z","iopub.execute_input":"2025-03-17T14:36:28.424064Z","iopub.status.idle":"2025-03-17T14:36:28.844014Z","shell.execute_reply.started":"2025-03-17T14:36:28.424037Z","shell.execute_reply":"2025-03-17T14:36:28.843168Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_images = test_it.__next__()\ntest_images.shape\nplot_exmaple(test_images)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:33:06.239914Z","iopub.execute_input":"2025-03-17T14:33:06.240253Z","iopub.status.idle":"2025-03-17T14:33:10.750221Z","shell.execute_reply.started":"2025-03-17T14:33:06.240224Z","shell.execute_reply":"2025-03-17T14:33:10.749041Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Create transfer learning model for VGG16\nimport sys\nfrom matplotlib import pyplot\nfrom keras.utils import to_categorical\nfrom keras.applications.vgg16 import VGG16\nfrom keras.models import Model\nfrom keras.layers import Dense\nfrom keras.layers import Flatten\nfrom keras.optimizers import SGD\nfrom keras.preprocessing.image import ImageDataGenerator\n\n# define cnn model\ndef define_model_vgg16():\n\t# load model\n\tmodel = VGG16(include_top=False, input_shape=(224, 224, 3))\n\t# mark loaded layers as not trainable\n\tfor layer in model.layers:\n\t\tlayer.trainable = False\n\t# add new classifier layers\n\tflat1 = Flatten()(model.layers[-1].output)\n\tclass1 = Dense(128, activation='relu', kernel_initializer='he_uniform')(flat1)\n\toutput = Dense(1, activation='sigmoid')(class1)\n\t# define new model\n\tmodel = Model(inputs=model.inputs, outputs=output)\n\t# compile model\n\topt = SGD(lr=0.001, momentum=0.9)\n\tmodel.compile(optimizer=opt, loss='binary_crossentropy', metrics=['accuracy'])\n\treturn model","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:33:16.783298Z","iopub.execute_input":"2025-03-17T14:33:16.784114Z","iopub.status.idle":"2025-03-17T14:33:16.790636Z","shell.execute_reply.started":"2025-03-17T14:33:16.784084Z","shell.execute_reply":"2025-03-17T14:33:16.789633Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"vgg16_model = define_model_vgg16()\nvgg16_model.summary()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:33:21.169707Z","iopub.execute_input":"2025-03-17T14:33:21.170349Z","iopub.status.idle":"2025-03-17T14:33:22.323652Z","shell.execute_reply.started":"2025-03-17T14:33:21.17032Z","shell.execute_reply":"2025-03-17T14:33:22.322847Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from keras.applications.inception_v3 import InceptionV3\n\ndef define_model_inceptionv3():\n\t# load model\n\tmodel = InceptionV3(include_top=False, input_shape=(299, 299, 3))\n\t# mark loaded layers as not trainable\n\tfor layer in model.layers:\n\t\tlayer.trainable = False\n\n\t# add new classifier layers\n\tflat1 = Flatten()(model.layers[-1].output)\n\tclass1 = Dense(1024, activation='relu', kernel_initializer='he_uniform')(flat1)\n\tclass2 = Dense(512, activation='relu', kernel_initializer='he_uniform')(class1)\n\tclass3 = Dense(256, activation='relu', kernel_initializer='he_uniform')(class2)\n\tclass4 = Dense(128, activation='relu', kernel_initializer='he_uniform')(class3)\n\toutput = Dense(1, activation='sigmoid')(class4)\n\t# output = Dense(2, activation='softmax')(class4)\n\t# define new model\n\tmodel = Model(inputs=model.inputs, outputs=output)\n\t# compile model\n\topt = SGD(lr=0.001, momentum=0.9)\n\tmodel.compile(optimizer=opt, loss='binary_crossentropy', metrics=['accuracy'])\n\treturn model","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:33:28.018028Z","iopub.execute_input":"2025-03-17T14:33:28.01837Z","iopub.status.idle":"2025-03-17T14:33:28.025123Z","shell.execute_reply.started":"2025-03-17T14:33:28.018343Z","shell.execute_reply":"2025-03-17T14:33:28.024099Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model_inceptionv3 = define_model_inceptionv3()","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:33:30.664403Z","iopub.execute_input":"2025-03-17T14:33:30.665085Z","iopub.status.idle":"2025-03-17T14:33:34.623382Z","shell.execute_reply.started":"2025-03-17T14:33:30.665052Z","shell.execute_reply":"2025-03-17T14:33:34.62241Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model_inceptionv3.summary()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:35:30.173049Z","iopub.execute_input":"2025-03-17T14:35:30.17343Z","iopub.status.idle":"2025-03-17T14:35:30.842626Z","shell.execute_reply.started":"2025-03-17T14:35:30.173402Z","shell.execute_reply":"2025-03-17T14:35:30.841786Z"},"scrolled":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# fit model\nmodel_inceptionv3.reset_states()\nhistory_inceptionv3 = model_inceptionv3.fit(\n    train_it, \n    steps_per_epoch=len(train_it),\n    validation_data=val_it,\n    validation_steps=len(val_it),\n    epochs=3, verbose=1,\n    callbacks = [PlotLossesKeras()]\n    )","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:36:54.414223Z","iopub.execute_input":"2025-03-17T14:36:54.414937Z","iopub.status.idle":"2025-03-17T14:43:03.500592Z","shell.execute_reply.started":"2025-03-17T14:36:54.414905Z","shell.execute_reply":"2025-03-17T14:43:03.499722Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\ndef plot_images_with_labels(images, labels, train_log, set_label, save=False):\n    \"\"\"\n    Plots a grid of images with their corresponding labels and saves the figure.\n    \n    Args:\n    - images (list or np.array): List of images to be displayed.\n    - labels (np.array): Array of one-hot encoded labels.\n    - train_log (str): The directory or log name to save the plot.\n    - set_label (str): The specific set label (e.g., \"train\", \"validation\", etc.).\n    - config (dict): Configuration dictionary containing image dimensions.\n    \n    Returns:\n    - None: Displays and saves the plot.\n    \"\"\"\n    # Convert one-hot encoded labels to class indices\n    class_indices = labels\n\n    # Create subplots\n    fig, axes = plt.subplots(3, 4, figsize=(14, 10), dpi=120)\n    axes = axes.flatten()\n\n    for img, label_idx, ax in zip(images, class_indices, axes):\n        # Undo any preprocessing (like rescaling for pre-trained models)\n        if np.max(img) == 1:\n            img = img * 255\n\n        # Display the image\n        img_shape = (224, 224, 3)\n        ax.imshow(img.astype(\"uint8\"))\n        # ax.imshow(img)\n\n        # Set the title to the corresponding class label\n        ax.set_title(f\"Label: {label_idx}\", fontsize=18)\n        ax.axis('on')\n\n    # Set the overall title for the figure\n    plot_title = f\"{train_log}-{set_label}\"\n    plt.suptitle(plot_title, fontsize=18)\n\n    # Show the plot\n    plt.show()\n\n    # Save the figure\n    if save:\n        plot_file = os.path.join(train_log, f\"{plot_title}.png\")\n        fig.savefig(plot_file, dpi=120)\n        print(f'Saved {plot_file}')\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-20T13:29:26.538824Z","iopub.execute_input":"2025-03-20T13:29:26.53961Z","iopub.status.idle":"2025-03-20T13:29:26.546186Z","shell.execute_reply.started":"2025-03-20T13:29:26.539582Z","shell.execute_reply":"2025-03-20T13:29:26.545383Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# plot_images_with_labels(images, labels, \"Dog-Cat\", \"Training\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-20T13:27:34.326544Z","iopub.execute_input":"2025-03-20T13:27:34.327064Z","iopub.status.idle":"2025-03-20T13:27:34.338956Z","shell.execute_reply.started":"2025-03-20T13:27:34.327024Z","shell.execute_reply":"2025-03-20T13:27:34.338191Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# for index, layer in enumerate(model.layers):\n#     print(index, layer.output.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:20:29.680411Z","iopub.status.idle":"2025-03-17T14:20:29.680939Z","shell.execute_reply.started":"2025-03-17T14:20:29.680649Z","shell.execute_reply":"2025-03-17T14:20:29.680673Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# # mark loaded layers as not trainable\n# for index, layer in enumerate(model.layers[:15]):\n#     print(index, layer.name, layer.output_shape)\n#     layer.trainable = False\n    \n# for index, layer in enumerate(model.layers[15:]):\n#     print(index, layer.name, layer.output_shape)\n#     layer.trainable = True","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:20:29.682873Z","iopub.status.idle":"2025-03-17T14:20:29.683287Z","shell.execute_reply.started":"2025-03-17T14:20:29.68307Z","shell.execute_reply":"2025-03-17T14:20:29.683091Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# evaluate model\n_, acc = model_inceptionv3.evaluate(test_it, steps=len(test_it), verbose=1)\nprint('> %.3f' % (acc * 100.0))\n# learning curves\n# summarize_diagnostics(history)\n\n# best_model = 'vgg16_model.hdf5'\n# my_model.save(best_model)","metadata":{"execution":{"iopub.status.busy":"2025-03-17T14:20:29.684365Z","iopub.status.idle":"2025-03-17T14:20:29.684688Z","shell.execute_reply.started":"2025-03-17T14:20:29.684539Z","shell.execute_reply":"2025-03-17T14:20:29.684556Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"images = test_it.__next__()\nimages.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:20:29.686315Z","iopub.status.idle":"2025-03-17T14:20:29.686601Z","shell.execute_reply.started":"2025-03-17T14:20:29.686459Z","shell.execute_reply":"2025-03-17T14:20:29.686473Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 5 first img: 1, 0, 1, 1, 0\nimages_to_predict = images[:5]\nimages_to_predict.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:20:29.687983Z","iopub.status.idle":"2025-03-17T14:20:29.688282Z","shell.execute_reply.started":"2025-03-17T14:20:29.688142Z","shell.execute_reply":"2025-03-17T14:20:29.688157Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"probs = model_inceptionv3.predict(images_to_predict, verbose=1)\nprobs","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T14:20:29.689253Z","iopub.status.idle":"2025-03-17T14:20:29.689546Z","shell.execute_reply.started":"2025-03-17T14:20:29.689401Z","shell.execute_reply":"2025-03-17T14:20:29.689415Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Make Prediction","metadata":{}},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}