{"metadata":{"colab":{"provenance":[],"gpuType":"T4"},"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"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"},"accelerator":"GPU","kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":3362,"databundleVersionId":31148,"sourceType":"competition"}],"dockerImageVersionId":30615,"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":{"execution":{"iopub.status.busy":"2023-12-15T16:38:33.715160Z","iopub.execute_input":"2023-12-15T16:38:33.715536Z","iopub.status.idle":"2023-12-15T16:38:34.123836Z","shell.execute_reply.started":"2023-12-15T16:38:33.715506Z","shell.execute_reply":"2023-12-15T16:38:34.122856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nprint(os.listdir('../input'))","metadata":{"id":"cgJeoK_QlR-K","outputId":"62f011fb-184f-4d6c-c5cf-131d2e2116b5","execution":{"iopub.status.busy":"2023-12-15T16:38:34.125691Z","iopub.execute_input":"2023-12-15T16:38:34.126142Z","iopub.status.idle":"2023-12-15T16:38:34.132130Z","shell.execute_reply.started":"2023-12-15T16:38:34.126111Z","shell.execute_reply":"2023-12-15T16:38:34.131045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import zipfile\n\nwith zipfile.ZipFile('/kaggle/input/dogs-vs-cats/train.zip','r') as z:\n    z.extractall('.')","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:38:34.133404Z","iopub.execute_input":"2023-12-15T16:38:34.133753Z","iopub.status.idle":"2023-12-15T16:38:43.749447Z","shell.execute_reply.started":"2023-12-15T16:38:34.133719Z","shell.execute_reply":"2023-12-15T16:38:43.748252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.mkdir('/kaggle/working/test')","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:38:43.750970Z","iopub.execute_input":"2023-12-15T16:38:43.751739Z","iopub.status.idle":"2023-12-15T16:38:43.756676Z","shell.execute_reply.started":"2023-12-15T16:38:43.751698Z","shell.execute_reply":"2023-12-15T16:38:43.755647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with zipfile.ZipFile('/kaggle/input/dogs-vs-cats/test1.zip','r') as z:\n    z.extractall('.')","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:38:43.761013Z","iopub.execute_input":"2023-12-15T16:38:43.761399Z","iopub.status.idle":"2023-12-15T16:38:48.545857Z","shell.execute_reply.started":"2023-12-15T16:38:43.761368Z","shell.execute_reply":"2023-12-15T16:38:48.544987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# zip_file_path='/kaggle/input/dogs-vs-cats/train.zip'","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:38:48.546971Z","iopub.execute_input":"2023-12-15T16:38:48.547282Z","iopub.status.idle":"2023-12-15T16:38:48.551561Z","shell.execute_reply.started":"2023-12-15T16:38:48.547252Z","shell.execute_reply":"2023-12-15T16:38:48.550557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_data_dir = os.path.join(os.path.dirname(zip_file_path), \"train\")","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:38:48.553033Z","iopub.execute_input":"2023-12-15T16:38:48.553335Z","iopub.status.idle":"2023-12-15T16:38:48.562957Z","shell.execute_reply.started":"2023-12-15T16:38:48.553307Z","shell.execute_reply":"2023-12-15T16:38:48.561929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Specify the zip file path\n# zip_file_path = \"/kaggle/input/dogs-vs-cats/train.zip\"\n\n# # Extract the zip file\n# with zipfile.ZipFile(zip_file_path, \"r\") as zip_ref:\n#     zip_ref.extractall()\n\n# # You can now access the extracted files in the \"train\" directory\n# train_data_dir = os.path.join(os.path.dirname(zip_file_path), \"train\")","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:38:48.564311Z","iopub.execute_input":"2023-12-15T16:38:48.564664Z","iopub.status.idle":"2023-12-15T16:38:48.574151Z","shell.execute_reply.started":"2023-12-15T16:38:48.564635Z","shell.execute_reply":"2023-12-15T16:38:48.573201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(os.listdir('/kaggle/working/train'))","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:38:48.575501Z","iopub.execute_input":"2023-12-15T16:38:48.575862Z","iopub.status.idle":"2023-12-15T16:38:48.604586Z","shell.execute_reply.started":"2023-12-15T16:38:48.575826Z","shell.execute_reply":"2023-12-15T16:38:48.603542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# path,dirs,files=next(os.walk('/content/train/train'))\n# print(len(files))","metadata":{"id":"_UpOzsuWSVd0","outputId":"3db73b4f-3fb2-4952-849b-93ee6e4d845a","execution":{"iopub.status.busy":"2023-12-15T16:38:48.605787Z","iopub.execute_input":"2023-12-15T16:38:48.606104Z","iopub.status.idle":"2023-12-15T16:38:48.610480Z","shell.execute_reply.started":"2023-12-15T16:38:48.606077Z","shell.execute_reply":"2023-12-15T16:38:48.609534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"original_dataset_dir='/kaggle/working/train'","metadata":{"id":"bh1Pv-6wSt9i","execution":{"iopub.status.busy":"2023-12-15T16:38:48.611519Z","iopub.execute_input":"2023-12-15T16:38:48.611792Z","iopub.status.idle":"2023-12-15T16:38:48.621490Z","shell.execute_reply.started":"2023-12-15T16:38:48.611759Z","shell.execute_reply":"2023-12-15T16:38:48.620411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# basedir='content/cats_and_dogs_small'\n# os.mkdir(basedir)","metadata":{"id":"lcG8th6US0SP","execution":{"iopub.status.busy":"2023-12-15T16:38:48.622699Z","iopub.execute_input":"2023-12-15T16:38:48.623014Z","iopub.status.idle":"2023-12-15T16:38:48.631724Z","shell.execute_reply.started":"2023-12-15T16:38:48.622977Z","shell.execute_reply":"2023-12-15T16:38:48.630668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.mkdir('/kaggle/working/small')","metadata":{"id":"3nW61tp9TDn0","execution":{"iopub.status.busy":"2023-12-15T16:38:48.633243Z","iopub.execute_input":"2023-12-15T16:38:48.633584Z","iopub.status.idle":"2023-12-15T16:38:48.641790Z","shell.execute_reply.started":"2023-12-15T16:38:48.633552Z","shell.execute_reply":"2023-12-15T16:38:48.640846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_dir='/kaggle/working/small'","metadata":{"id":"y4skzeYOTZo5","execution":{"iopub.status.busy":"2023-12-15T16:38:48.712125Z","iopub.execute_input":"2023-12-15T16:38:48.712488Z","iopub.status.idle":"2023-12-15T16:38:48.716788Z","shell.execute_reply.started":"2023-12-15T16:38:48.712459Z","shell.execute_reply":"2023-12-15T16:38:48.715691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dir=os.path.join(base_dir,'train')\nos.mkdir(train_dir)","metadata":{"id":"qbSKES6uTnPj","execution":{"iopub.status.busy":"2023-12-15T16:38:48.718112Z","iopub.execute_input":"2023-12-15T16:38:48.718484Z","iopub.status.idle":"2023-12-15T16:38:48.728141Z","shell.execute_reply.started":"2023-12-15T16:38:48.718447Z","shell.execute_reply":"2023-12-15T16:38:48.727137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#This creates Train, Test and Validation directories with Dogs and Cats seperated\nvalidation_dir = os.path.join(base_dir, 'validation')\nos.mkdir(validation_dir)\n\ntest_dir = os.path.join(base_dir, 'test')\nos.mkdir(test_dir)\n\ntrain_cats_dir = os.path.join(train_dir, 'cats')\nos.mkdir(train_cats_dir)\n\ntrain_dogs_dir = os.path.join(train_dir, 'dogs')\nos.mkdir(train_dogs_dir)\n\nvalidation_cats_dir = os.path.join(validation_dir, 'cats')\nos.mkdir(validation_cats_dir)\n\nvalidation_dogs_dir = os.path.join(validation_dir, 'dogs')\nos.mkdir(validation_dogs_dir)\n\ntest_cats_dir = os.path.join(test_dir, 'cats')\nos.mkdir(test_cats_dir)\n\ntest_dogs_dir = os.path.join(test_dir, 'dogs')\nos.mkdir(test_dogs_dir)","metadata":{"id":"SzFCB8YUToQI","execution":{"iopub.status.busy":"2023-12-15T16:38:48.729417Z","iopub.execute_input":"2023-12-15T16:38:48.729704Z","iopub.status.idle":"2023-12-15T16:38:48.745466Z","shell.execute_reply.started":"2023-12-15T16:38:48.729675Z","shell.execute_reply":"2023-12-15T16:38:48.744471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(os.listdir('/kaggle/working/train'))","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:38:48.746682Z","iopub.execute_input":"2023-12-15T16:38:48.747041Z","iopub.status.idle":"2023-12-15T16:38:48.772785Z","shell.execute_reply.started":"2023-12-15T16:38:48.747015Z","shell.execute_reply":"2023-12-15T16:38:48.771873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\nfnames = ['cat.{}.jpg'.format(i) for i in range(10000)]\nfor fname in fnames:\n    src = os.path.join(original_dataset_dir, fname)\n    dst = os.path.join(train_cats_dir, fname)\n    #print(src,dst)\n    shutil.copyfile(src, dst)\n\nfnames = ['cat.{}.jpg'.format(i) for i in range(10000,11250)]\nfor fname in fnames:\n    src = os.path.join(original_dataset_dir, fname)\n    dst = os.path.join(validation_cats_dir, fname)\n    shutil.copyfile(src, dst)\n\nfnames = ['cat.{}.jpg'.format(i) for i in range(11250, 12500)]\nfor fname in fnames:\n    src = os.path.join(original_dataset_dir, fname)\n    dst = os.path.join(test_cats_dir, fname)\n    shutil.copyfile(src, dst)\n\nfnames = ['dog.{}.jpg'.format(i) for i in range(10000)]\nfor fname in fnames:\n    src = os.path.join(original_dataset_dir, fname)\n    dst = os.path.join(train_dogs_dir, fname)\n    shutil.copyfile(src, dst)\n\nfnames = ['dog.{}.jpg'.format(i) for i in range(10000, 11250)]\nfor fname in fnames:\n    src = os.path.join(original_dataset_dir, fname)\n    dst = os.path.join(validation_dogs_dir, fname)\n    shutil.copyfile(src, dst)\n\nfnames = ['dog.{}.jpg'.format(i) for i in range(11250, 12500)]\nfor fname in fnames:\n    src = os.path.join(original_dataset_dir, fname)\n    dst = os.path.join(test_dogs_dir, fname)\n    shutil.copyfile(src, dst)","metadata":{"id":"hnBcdLmUUJho","execution":{"iopub.status.busy":"2023-12-15T16:38:48.774162Z","iopub.execute_input":"2023-12-15T16:38:48.774980Z","iopub.status.idle":"2023-12-15T16:38:51.591007Z","shell.execute_reply.started":"2023-12-15T16:38:48.774940Z","shell.execute_reply":"2023-12-15T16:38:51.589978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('total training cat images:', len(os.listdir(train_cats_dir)))\nprint('total training dog images:', len(os.listdir(train_dogs_dir)))\nprint('total validation cat images:', len(os.listdir(validation_cats_dir)))\n\nprint('total validation dog images:', len(os.listdir(validation_dogs_dir)))\nprint('total test cat images:', len(os.listdir(test_cats_dir)))\nprint('total test dog images:', len(os.listdir(test_dogs_dir)))","metadata":{"id":"TBqhHWTIU3lF","outputId":"8c2afa13-025f-4929-8f00-3a3765a742a0","execution":{"iopub.status.busy":"2023-12-15T16:38:51.592471Z","iopub.execute_input":"2023-12-15T16:38:51.592837Z","iopub.status.idle":"2023-12-15T16:38:51.616397Z","shell.execute_reply.started":"2023-12-15T16:38:51.592797Z","shell.execute_reply":"2023-12-15T16:38:51.615458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Moving files into a seperate folder for test submission","metadata":{}},{"cell_type":"code","source":"# os.mkdir('/kaggle/working/test/test1')\n# test_original='/kaggle/working/test1'\n# test_final='/kaggle/working/test/test1'\n\n# fnames = ['{}.jpg'.format(i) for i in range(1,12501)]\n# for fname in fnames:\n#     src = os.path.join(test_original, fname)\n#     dst = os.path.join(test_final, fname)\n#     #print(src,dst)\n#     shutil.copyfile(src, dst)","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:38:51.617525Z","iopub.execute_input":"2023-12-15T16:38:51.617864Z","iopub.status.idle":"2023-12-15T16:38:51.622394Z","shell.execute_reply.started":"2023-12-15T16:38:51.617836Z","shell.execute_reply":"2023-12-15T16:38:51.621397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Rescaling,Dense,Conv2D,Flatten,Dropout,BatchNormalization,MaxPooling2D\nfrom tensorflow import keras\n\n","metadata":{"id":"-p908pi8U7h9","execution":{"iopub.status.busy":"2023-12-15T16:38:51.623562Z","iopub.execute_input":"2023-12-15T16:38:51.623967Z","iopub.status.idle":"2023-12-15T16:39:05.341476Z","shell.execute_reply.started":"2023-12-15T16:38:51.623909Z","shell.execute_reply":"2023-12-15T16:39:05.340614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Model Creation","metadata":{"id":"DtLsHXErWTAn"}},{"cell_type":"code","source":"model=Sequential()\n# model.add(Rescaling(1./255))\nmodel.add(Conv2D(32,(3,3),activation='relu',input_shape=(150,150,3)))\nmodel.add(BatchNormalization())\nmodel.add(MaxPooling2D(2,2))\nmodel.add(Conv2D(64,(3,3),activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(MaxPooling2D(2,2))\nmodel.add(Conv2D(128,(3,3),activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(MaxPooling2D(2,2))\nmodel.add(Conv2D(128,(3,3),activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(MaxPooling2D(2,2))\n# model.add(Conv2D(256,(3,3),activation='relu'))\n# model.add(MaxPooling2D(2,2))\nmodel.add(Flatten())\nmodel.add(Dense(512, activation='relu'))\nmodel.add(Dropout(0.5))\nmodel.add(Dense(1, activation='sigmoid'))\nmodel.summary()\n\n","metadata":{"id":"E0q3ow7rXd8c","outputId":"1e39c6ca-14d6-4958-9b28-771eb1bb0b9b","execution":{"iopub.status.busy":"2023-12-15T16:39:05.342778Z","iopub.execute_input":"2023-12-15T16:39:05.343836Z","iopub.status.idle":"2023-12-15T16:39:10.758071Z","shell.execute_reply.started":"2023-12-15T16:39:05.343795Z","shell.execute_reply":"2023-12-15T16:39:10.756689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])","metadata":{"id":"o37kBrpOW8Hu","execution":{"iopub.status.busy":"2023-12-15T16:39:10.760161Z","iopub.execute_input":"2023-12-15T16:39:10.760569Z","iopub.status.idle":"2023-12-15T16:39:10.785422Z","shell.execute_reply.started":"2023-12-15T16:39:10.760529Z","shell.execute_reply":"2023-12-15T16:39:10.784175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Data Preprocessing","metadata":{"id":"dczjvNL7aNlD"}},{"cell_type":"code","source":"from tensorflow.keras.utils import image_dataset_from_directory\nfrom keras.preprocessing.image import ImageDataGenerator","metadata":{"id":"zajyMLrTZ5_A","execution":{"iopub.status.busy":"2023-12-15T16:39:10.787168Z","iopub.execute_input":"2023-12-15T16:39:10.787566Z","iopub.status.idle":"2023-12-15T16:39:10.793769Z","shell.execute_reply.started":"2023-12-15T16:39:10.787529Z","shell.execute_reply":"2023-12-15T16:39:10.792725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_datagen=ImageDataGenerator(rescale=1./255,rotation_range=40,width_shift_range=0.2,height_shift_range=0.2,shear_range=0.2,zoom_range=0.2,horizontal_flip=True)\ntest_datagen=ImageDataGenerator(rescale=1./255)","metadata":{"id":"_B26wZDTaV7f","execution":{"iopub.status.busy":"2023-12-15T16:39:10.795141Z","iopub.execute_input":"2023-12-15T16:39:10.795450Z","iopub.status.idle":"2023-12-15T16:39:10.807358Z","shell.execute_reply.started":"2023-12-15T16:39:10.795423Z","shell.execute_reply":"2023-12-15T16:39:10.806320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Using 224x224 as VGG prefers this size","metadata":{}},{"cell_type":"code","source":"train_generator=train_datagen.flow_from_directory(train_dir,target_size=(224,224),batch_size=20,class_mode='binary')","metadata":{"id":"aulaJwIGugPY","outputId":"368f98a7-4b7b-4ccf-ad52-8f1f8fc95f3a","execution":{"iopub.status.busy":"2023-12-15T16:39:10.809009Z","iopub.execute_input":"2023-12-15T16:39:10.809380Z","iopub.status.idle":"2023-12-15T16:39:11.420023Z","shell.execute_reply.started":"2023-12-15T16:39:10.809350Z","shell.execute_reply":"2023-12-15T16:39:11.418970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"validation_generator=test_datagen.flow_from_directory(validation_dir,target_size=(224,224),batch_size=20,class_mode='binary')","metadata":{"id":"W0hKtHF_8CYK","outputId":"305d8142-ae90-4945-f96d-1f0023359b89","execution":{"iopub.status.busy":"2023-12-15T16:39:11.421296Z","iopub.execute_input":"2023-12-15T16:39:11.421597Z","iopub.status.idle":"2023-12-15T16:39:11.507613Z","shell.execute_reply.started":"2023-12-15T16:39:11.421554Z","shell.execute_reply":"2023-12-15T16:39:11.506698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_generator=test_datagen.flow_from_directory(test_dir,target_size=(224,224),batch_size=20,class_mode='binary')","metadata":{"id":"jjTG7zpqBVdQ","outputId":"1d2eb67c-3e8f-4a8c-8bb7-bd5a16386965","execution":{"iopub.status.busy":"2023-12-15T16:39:11.508792Z","iopub.execute_input":"2023-12-15T16:39:11.509091Z","iopub.status.idle":"2023-12-15T16:39:11.590930Z","shell.execute_reply.started":"2023-12-15T16:39:11.509065Z","shell.execute_reply":"2023-12-15T16:39:11.590089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%script False\nhistory=model.fit_generator(train_generator,steps_per_epoch=100,epochs=20,validation_data=validation_generator,validation_steps=10)","metadata":{"id":"tOjntAxFvnUn","outputId":"e7d23af6-ec5a-4f38-893f-6e0db249c00f","execution":{"iopub.status.busy":"2023-12-15T16:39:11.592057Z","iopub.execute_input":"2023-12-15T16:39:11.592343Z","iopub.status.idle":"2023-12-15T16:39:11.601517Z","shell.execute_reply.started":"2023-12-15T16:39:11.592316Z","shell.execute_reply":"2023-12-15T16:39:11.600428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt","metadata":{"id":"Bq22MHZmyhs9","execution":{"iopub.status.busy":"2023-12-15T16:39:11.602893Z","iopub.execute_input":"2023-12-15T16:39:11.603230Z","iopub.status.idle":"2023-12-15T16:39:11.611427Z","shell.execute_reply.started":"2023-12-15T16:39:11.603201Z","shell.execute_reply":"2023-12-15T16:39:11.610495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pd.DataFrame(history.history).plot(kind='line')","metadata":{"id":"ouXF7xLrwpuf","outputId":"4ec5bae4-edb0-46a1-e85e-6f6b60b4c3fd","execution":{"iopub.status.busy":"2023-12-15T16:39:11.612624Z","iopub.execute_input":"2023-12-15T16:39:11.613006Z","iopub.status.idle":"2023-12-15T16:39:11.623742Z","shell.execute_reply.started":"2023-12-15T16:39:11.612969Z","shell.execute_reply":"2023-12-15T16:39:11.622749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.applications import VGG19","metadata":{"id":"Cq0sHPKLyR80","execution":{"iopub.status.busy":"2023-12-15T16:39:11.625133Z","iopub.execute_input":"2023-12-15T16:39:11.625796Z","iopub.status.idle":"2023-12-15T16:39:11.635841Z","shell.execute_reply.started":"2023-12-15T16:39:11.625757Z","shell.execute_reply":"2023-12-15T16:39:11.634950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"conv_base=VGG19(weights='imagenet',include_top=False,input_shape=(224,224,3))","metadata":{"id":"2WBV0AyV9lRj","execution":{"iopub.status.busy":"2023-12-15T16:39:11.637337Z","iopub.execute_input":"2023-12-15T16:39:11.637692Z","iopub.status.idle":"2023-12-15T16:39:12.713624Z","shell.execute_reply.started":"2023-12-15T16:39:11.637662Z","shell.execute_reply":"2023-12-15T16:39:12.712700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"conv_base.trainable=False","metadata":{"id":"Nld7DweE9ysP","execution":{"iopub.status.busy":"2023-12-15T16:39:12.714995Z","iopub.execute_input":"2023-12-15T16:39:12.715318Z","iopub.status.idle":"2023-12-15T16:39:12.721254Z","shell.execute_reply.started":"2023-12-15T16:39:12.715290Z","shell.execute_reply":"2023-12-15T16:39:12.720045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=Sequential()\nmodel.add(conv_base)\nmodel.add(Flatten())\nmodel.add(Dense(256,activation='relu'))\nmodel.add(Dense(1,activation='sigmoid'))","metadata":{"id":"YU8Wa50U9u2h","execution":{"iopub.status.busy":"2023-12-15T16:39:12.722474Z","iopub.execute_input":"2023-12-15T16:39:12.722808Z","iopub.status.idle":"2023-12-15T16:39:12.871840Z","shell.execute_reply.started":"2023-12-15T16:39:12.722777Z","shell.execute_reply":"2023-12-15T16:39:12.870738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])","metadata":{"id":"sYyPWbKP-C9c","execution":{"iopub.status.busy":"2023-12-15T16:39:12.873400Z","iopub.execute_input":"2023-12-15T16:39:12.874143Z","iopub.status.idle":"2023-12-15T16:39:12.887173Z","shell.execute_reply.started":"2023-12-15T16:39:12.874103Z","shell.execute_reply":"2023-12-15T16:39:12.886210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"id":"rO6Y0Luc-Obf","outputId":"fdbecd30-6978-4490-e0b3-d5b6d1b83985","execution":{"iopub.status.busy":"2023-12-15T16:39:12.888451Z","iopub.execute_input":"2023-12-15T16:39:12.888836Z","iopub.status.idle":"2023-12-15T16:39:12.914502Z","shell.execute_reply.started":"2023-12-15T16:39:12.888808Z","shell.execute_reply":"2023-12-15T16:39:12.913587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history=model.fit_generator(train_generator,steps_per_epoch=100,epochs=20,validation_data=validation_generator,validation_steps=10)","metadata":{"id":"JlFC3TrT-IZo","outputId":"b3907c75-0b4c-4360-8b4f-d095918189e4","execution":{"iopub.status.busy":"2023-12-15T16:39:12.915827Z","iopub.execute_input":"2023-12-15T16:39:12.916229Z","iopub.status.idle":"2023-12-15T16:48:56.354524Z","shell.execute_reply.started":"2023-12-15T16:39:12.916193Z","shell.execute_reply":"2023-12-15T16:48:56.353571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.DataFrame(history.history).plot(kind='line')","metadata":{"id":"HQDB6gRd-RlW","outputId":"3a1ef24c-f95e-4864-8921-43b700dfd315","execution":{"iopub.status.busy":"2023-12-15T16:48:56.356575Z","iopub.execute_input":"2023-12-15T16:48:56.356965Z","iopub.status.idle":"2023-12-15T16:48:56.815768Z","shell.execute_reply.started":"2023-12-15T16:48:56.356904Z","shell.execute_reply":"2023-12-15T16:48:56.814680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.evaluate(validation_generator)","metadata":{"id":"tDNl6iGR_nv_","outputId":"c3d8ecb3-ff1c-40db-c3db-bfa22167cc04","execution":{"iopub.status.busy":"2023-12-15T16:48:56.817598Z","iopub.execute_input":"2023-12-15T16:48:56.818254Z","iopub.status.idle":"2023-12-15T16:49:14.635164Z","shell.execute_reply.started":"2023-12-15T16:48:56.818214Z","shell.execute_reply":"2023-12-15T16:49:14.634180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_datagen=ImageDataGenerator(rescale=1./255)\n# train_generator=train_datagen.flow_from_directory(train_dir,target_size=(150,150),batch_size=20,class_mode='binary')fro","metadata":{"id":"4aNO84ECCRNO","execution":{"iopub.status.busy":"2023-12-15T16:49:14.641950Z","iopub.execute_input":"2023-12-15T16:49:14.642260Z","iopub.status.idle":"2023-12-15T16:49:14.646977Z","shell.execute_reply.started":"2023-12-15T16:49:14.642232Z","shell.execute_reply":"2023-12-15T16:49:14.645673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.applications import ResNet50","metadata":{"execution":{"iopub.status.busy":"2023-12-15T17:26:43.349419Z","iopub.execute_input":"2023-12-15T17:26:43.350314Z","iopub.status.idle":"2023-12-15T17:26:43.354454Z","shell.execute_reply.started":"2023-12-15T17:26:43.350277Z","shell.execute_reply":"2023-12-15T17:26:43.353548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# test1_dir=('/kaggle/working/test')\n# test1_datagen=ImageDataGenerator(rescale=1./255)\n# # test1_generator=test1_datagen.flow_from_directory(test1_dir,target_size=(224,224),batch_size=20,class_mode='input')","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:49:14.648273Z","iopub.execute_input":"2023-12-15T16:49:14.648576Z","iopub.status.idle":"2023-12-15T16:49:14.664622Z","shell.execute_reply.started":"2023-12-15T16:49:14.648549Z","shell.execute_reply":"2023-12-15T16:49:14.663582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resnet=ResNet50(weights='imagenet',include_top=False,input_shape=(224,224,3))","metadata":{"execution":{"iopub.status.busy":"2023-12-15T17:26:46.514097Z","iopub.execute_input":"2023-12-15T17:26:46.514861Z","iopub.status.idle":"2023-12-15T17:26:48.351813Z","shell.execute_reply.started":"2023-12-15T17:26:46.514821Z","shell.execute_reply":"2023-12-15T17:26:48.350966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resnet.trainable=False","metadata":{"execution":{"iopub.status.busy":"2023-12-15T17:28:13.866512Z","iopub.execute_input":"2023-12-15T17:28:13.866960Z","iopub.status.idle":"2023-12-15T17:28:13.878699Z","shell.execute_reply.started":"2023-12-15T17:28:13.866905Z","shell.execute_reply":"2023-12-15T17:28:13.877625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=Sequential()\nmodel.add(resnet)\nmodel.add(Flatten())\nmodel.add(Dense(256,activation='relu'))\nmodel.add(Dense(1,activation='sigmoid'))","metadata":{"execution":{"iopub.status.busy":"2023-12-15T17:28:15.904723Z","iopub.execute_input":"2023-12-15T17:28:15.905714Z","iopub.status.idle":"2023-12-15T17:28:16.512899Z","shell.execute_reply.started":"2023-12-15T17:28:15.905674Z","shell.execute_reply":"2023-12-15T17:28:16.512078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-12-15T17:28:17.471343Z","iopub.execute_input":"2023-12-15T17:28:17.471710Z","iopub.status.idle":"2023-12-15T17:28:17.515962Z","shell.execute_reply.started":"2023-12-15T17:28:17.471681Z","shell.execute_reply":"2023-12-15T17:28:17.514853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-12-15T17:28:19.531833Z","iopub.execute_input":"2023-12-15T17:28:19.532761Z","iopub.status.idle":"2023-12-15T17:28:19.550224Z","shell.execute_reply.started":"2023-12-15T17:28:19.532721Z","shell.execute_reply":"2023-12-15T17:28:19.549204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history2=model.fit(train_generator,steps_per_epoch=100,epochs=20,validation_data=validation_generator,validation_steps=10)","metadata":{"execution":{"iopub.status.busy":"2023-12-15T17:28:29.670424Z","iopub.execute_input":"2023-12-15T17:28:29.671343Z","iopub.status.idle":"2023-12-15T17:37:34.982732Z","shell.execute_reply.started":"2023-12-15T17:28:29.671306Z","shell.execute_reply":"2023-12-15T17:37:34.981777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.evaluate(validation_generator)","metadata":{"execution":{"iopub.status.busy":"2023-12-15T17:37:34.984548Z","iopub.execute_input":"2023-12-15T17:37:34.984893Z","iopub.status.idle":"2023-12-15T17:37:44.679285Z","shell.execute_reply.started":"2023-12-15T17:37:34.984863Z","shell.execute_reply":"2023-12-15T17:37:44.678222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.DataFrame(history2.history).plot(kind='line')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}