{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":3362,"databundleVersionId":31148,"sourceType":"competition"}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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":"2024-10-31T16:05:19.841860Z","iopub.execute_input":"2024-10-31T16:05:19.842289Z","iopub.status.idle":"2024-10-31T16:05:21.565579Z","shell.execute_reply.started":"2024-10-31T16:05:19.842249Z","shell.execute_reply":"2024-10-31T16:05:21.564205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport random as rnd\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\nfrom sklearn.model_selection import train_test_split\n\nimport keras\nfrom keras.models import Sequential\nfrom keras.utils import to_categorical\nfrom keras.preprocessing.image import load_img\nfrom keras.layers import Flatten, Dense, Dropout\nfrom keras.layers import Conv2D, MaxPool2D, BatchNormalization, Activation\n\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\n\nprint(os.listdir(\"/kaggle/input/dogs-vs-cats\"))","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:06:09.908383Z","iopub.execute_input":"2024-10-31T16:06:09.909180Z","iopub.status.idle":"2024-10-31T16:06:27.788073Z","shell.execute_reply.started":"2024-10-31T16:06:09.909131Z","shell.execute_reply":"2024-10-31T16:06:27.786610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"FAST_RUN = False\nIMAGE_WIDTH=128\nIMAGE_HEIGHT=128\nIMAGE_CHANNELS=3\nIMAGE_SIZE=(IMAGE_WIDTH, IMAGE_HEIGHT)","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:06:46.546434Z","iopub.execute_input":"2024-10-31T16:06:46.547573Z","iopub.status.idle":"2024-10-31T16:06:46.553456Z","shell.execute_reply.started":"2024-10-31T16:06:46.547519Z","shell.execute_reply":"2024-10-31T16:06:46.551877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import zipfile\n\n# zip_files = ['test1', 'train']\n\n# for zip_file in zip_files:\n#     with zipfile.ZipFile(f\"../input/dogs-vs-cats/{zip_file}.zip\", \"r\") as z:\n#         z.extractall(\".\")\n#         print(f\"{zip_file} unzipped\")","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:06:58.468801Z","iopub.execute_input":"2024-10-31T16:06:58.469238Z","iopub.status.idle":"2024-10-31T16:06:58.475485Z","shell.execute_reply.started":"2024-10-31T16:06:58.469203Z","shell.execute_reply":"2024-10-31T16:06:58.473807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import zipfile\n\npath = \"/kaggle/input/dogs-vs-cats\"\nfor zip_file in os.listdir(path)[:2]:\n    zipfile.ZipFile(f\"{path}/{zip_file}\", 'r').extractall(\".\")\n#     print(f\"{path}/{zip_file}\")\n    print(f\"{zip_file} unzipped\")","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:07:08.623935Z","iopub.execute_input":"2024-10-31T16:07:08.625493Z","iopub.status.idle":"2024-10-31T16:07:23.334291Z","shell.execute_reply.started":"2024-10-31T16:07:08.625440Z","shell.execute_reply":"2024-10-31T16:07:23.333111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images = os.listdir(\"/kaggle/working/train\")\nCATEGORIES = []\n\nfor image_name in train_images:\n    class_name = image_name.split('.')[0]  # cat.588.jpg\n    CATEGORIES.append(0 if class_name=='cat' else 1)\n\ndf = pd.DataFrame({\"train_images\": train_images, \"CATEGORIES\": CATEGORIES})","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:07:57.155899Z","iopub.execute_input":"2024-10-31T16:07:57.156370Z","iopub.status.idle":"2024-10-31T16:07:57.206861Z","shell.execute_reply.started":"2024-10-31T16:07:57.156331Z","shell.execute_reply":"2024-10-31T16:07:57.205506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()\n","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:08:07.659060Z","iopub.execute_input":"2024-10-31T16:08:07.659646Z","iopub.status.idle":"2024-10-31T16:08:07.688274Z","shell.execute_reply.started":"2024-10-31T16:08:07.659596Z","shell.execute_reply":"2024-10-31T16:08:07.686561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.tail()\n","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:08:32.546507Z","iopub.execute_input":"2024-10-31T16:08:32.547006Z","iopub.status.idle":"2024-10-31T16:08:32.562778Z","shell.execute_reply.started":"2024-10-31T16:08:32.546965Z","shell.execute_reply":"2024-10-31T16:08:32.560947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()\n","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:08:43.163733Z","iopub.execute_input":"2024-10-31T16:08:43.164306Z","iopub.status.idle":"2024-10-31T16:08:43.192513Z","shell.execute_reply.started":"2024-10-31T16:08:43.164257Z","shell.execute_reply":"2024-10-31T16:08:43.191023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"CATEGORIES\"].value_counts()\n","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:08:57.162619Z","iopub.execute_input":"2024-10-31T16:08:57.163161Z","iopub.status.idle":"2024-10-31T16:08:57.185141Z","shell.execute_reply.started":"2024-10-31T16:08:57.163114Z","shell.execute_reply":"2024-10-31T16:08:57.183441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"CATEGORIES\"].value_counts().plot.bar()\n","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:09:10.425201Z","iopub.execute_input":"2024-10-31T16:09:10.425714Z","iopub.status.idle":"2024-10-31T16:09:10.721389Z","shell.execute_reply.started":"2024-10-31T16:09:10.425673Z","shell.execute_reply":"2024-10-31T16:09:10.720130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shapes = []\n\nfor image in df[\"train_images\"]:\n    path = os.path.join(\"/kaggle/working/train\",image)\n    image_array = plt.imread(path)\n    shapes.append(image_array.shape)\n    \nprint(pd.Series(shapes).value_counts())\n\nindex = np.argmin(shapes)\nprint(f\"\\nThe Minimum Dimension is ==> {shapes[index]}\\n\")","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:09:38.051055Z","iopub.execute_input":"2024-10-31T16:09:38.051695Z","iopub.status.idle":"2024-10-31T16:10:15.194474Z","shell.execute_reply.started":"2024-10-31T16:09:38.051635Z","shell.execute_reply":"2024-10-31T16:10:15.192825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = rnd.choice(train_images)\nimage = load_img(os.path.join(\"/kaggle/working/train\", sample))\nprint(type(image))\nplt.imshow(image)\nplt.axis(\"off\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:10:20.677487Z","iopub.execute_input":"2024-10-31T16:10:20.678652Z","iopub.status.idle":"2024-10-31T16:10:20.932036Z","shell.execute_reply.started":"2024-10-31T16:10:20.678599Z","shell.execute_reply":"2024-10-31T16:10:20.930358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"CATEGORIES\"] = df[\"CATEGORIES\"].replace({0: 'cat', 1: 'dog'})\n","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:10:47.185977Z","iopub.execute_input":"2024-10-31T16:10:47.186869Z","iopub.status.idle":"2024-10-31T16:10:47.200663Z","shell.execute_reply.started":"2024-10-31T16:10:47.186807Z","shell.execute_reply":"2024-10-31T16:10:47.198917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df, valid_df = train_test_split(df, test_size=0.20, random_state=42)\n\ntrain_df = train_df.reset_index(drop=True)\nvalid_df = valid_df.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:10:59.826894Z","iopub.execute_input":"2024-10-31T16:10:59.827408Z","iopub.status.idle":"2024-10-31T16:10:59.855819Z","shell.execute_reply.started":"2024-10-31T16:10:59.827362Z","shell.execute_reply":"2024-10-31T16:10:59.854430Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['CATEGORIES'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:12:33.782635Z","iopub.execute_input":"2024-10-31T16:12:33.783113Z","iopub.status.idle":"2024-10-31T16:12:33.795305Z","shell.execute_reply.started":"2024-10-31T16:12:33.783072Z","shell.execute_reply":"2024-10-31T16:12:33.793788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['CATEGORIES'].value_counts().plot.bar()","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:12:27.232540Z","iopub.execute_input":"2024-10-31T16:12:27.233003Z","iopub.status.idle":"2024-10-31T16:12:27.481952Z","shell.execute_reply.started":"2024-10-31T16:12:27.232958Z","shell.execute_reply":"2024-10-31T16:12:27.480600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"valid_df['CATEGORIES'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:12:00.672288Z","iopub.execute_input":"2024-10-31T16:12:00.672869Z","iopub.status.idle":"2024-10-31T16:12:00.684841Z","shell.execute_reply.started":"2024-10-31T16:12:00.672822Z","shell.execute_reply":"2024-10-31T16:12:00.683236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"valid_df['CATEGORIES'].value_counts().plot.bar()","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:12:19.753638Z","iopub.execute_input":"2024-10-31T16:12:19.754196Z","iopub.status.idle":"2024-10-31T16:12:19.989162Z","shell.execute_reply.started":"2024-10-31T16:12:19.754152Z","shell.execute_reply":"2024-10-31T16:12:19.987872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"total_train = train_df.shape[0]\ntotal_validate = valid_df.shape[0]\nbatch_size=15","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:13:05.933829Z","iopub.execute_input":"2024-10-31T16:13:05.934317Z","iopub.status.idle":"2024-10-31T16:13:05.940983Z","shell.execute_reply.started":"2024-10-31T16:13:05.934277Z","shell.execute_reply":"2024-10-31T16:13:05.939376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:13:13.641378Z","iopub.execute_input":"2024-10-31T16:13:13.641880Z","iopub.status.idle":"2024-10-31T16:13:13.654823Z","shell.execute_reply.started":"2024-10-31T16:13:13.641831Z","shell.execute_reply":"2024-10-31T16:13:13.653387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_datagen = ImageDataGenerator(\n    rotation_range=15,\n    rescale=1./255,\n    shear_range=0.1,\n    zoom_range=0.2,\n    horizontal_flip=True,\n    width_shift_range=0.1,\n    height_shift_range=0.1\n)\n\ntrain_generator = train_datagen.flow_from_dataframe(\n    train_df, \n    \"/kaggle/working/train\", \n    x_col='train_images',\n    y_col='CATEGORIES',\n    target_size=IMAGE_SIZE,\n    class_mode='categorical',\n    batch_size=batch_size\n)","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:13:34.805019Z","iopub.execute_input":"2024-10-31T16:13:34.805613Z","iopub.status.idle":"2024-10-31T16:13:35.035826Z","shell.execute_reply.started":"2024-10-31T16:13:34.805558Z","shell.execute_reply":"2024-10-31T16:13:35.034387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"valid_datagen = ImageDataGenerator(rescale=1./255)\n\nvalid_generator = valid_datagen.flow_from_dataframe(\n    valid_df, \n    \"/kaggle/working/train\", \n    x_col='train_images',\n    y_col='CATEGORIES',\n    target_size=IMAGE_SIZE,\n    class_mode='categorical',\n    batch_size=batch_size\n)","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:13:47.531991Z","iopub.execute_input":"2024-10-31T16:13:47.532592Z","iopub.status.idle":"2024-10-31T16:13:47.605349Z","shell.execute_reply.started":"2024-10-31T16:13:47.532539Z","shell.execute_reply":"2024-10-31T16:13:47.603818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_df = train_df.sample(n=1) # take 1 image-sample\nprint(example_df, \"\\n\")\n\nexample_df= example_df.reset_index(drop=True)\nprint(example_df, \"\\n\")\n\nexample_generator = train_datagen.flow_from_dataframe(\n    example_df, \n    \"/kaggle/working/train\", \n    x_col='train_images',\n    y_col='CATEGORIES',\n    target_size=IMAGE_SIZE,\n    class_mode='categorical'\n)","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:14:00.530373Z","iopub.execute_input":"2024-10-31T16:14:00.530987Z","iopub.status.idle":"2024-10-31T16:14:00.550474Z","shell.execute_reply.started":"2024-10-31T16:14:00.530930Z","shell.execute_reply":"2024-10-31T16:14:00.548690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 12))\nfor i in range(0, 15):\n    plt.subplot(5, 3, i+1)\n    for X_batch, Y_batch in example_generator:\n        image = X_batch[0]\n        plt.imshow(image)\n        plt.axis('off')\n        break\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:14:18.827458Z","iopub.execute_input":"2024-10-31T16:14:18.829211Z","iopub.status.idle":"2024-10-31T16:14:20.114500Z","shell.execute_reply.started":"2024-10-31T16:14:18.829141Z","shell.execute_reply":"2024-10-31T16:14:20.113118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential([\n    Conv2D(32, (3, 3), activation='relu', input_shape=(IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_CHANNELS)),\n#     BatchNormalization(),\n    MaxPool2D(pool_size=(4,4)),\n    Dropout(rate=0.25),\n    \n    Conv2D(64, (3, 3), activation='relu'),\n    BatchNormalization(),\n    MaxPool2D(pool_size=(4,4)),\n    Dropout(rate=0.25),\n    \n    Conv2D(128, (3, 3), activation='relu'),\n    BatchNormalization(),\n    MaxPool2D(pool_size=(4,4)),\n    Dropout(rate=0.25),\n    \n    Flatten(),\n    \n    Dense(512, activation='relu'),\n    Dropout(rate=0.5),\n\n    Dense(2, activation='softmax') # 2 because we have cat and dog classes\n\n])\n\n# Compile\nmodel.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\n\n# Summary of Model\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:15:20.683297Z","iopub.execute_input":"2024-10-31T16:15:20.684637Z","iopub.status.idle":"2024-10-31T16:15:20.913331Z","shell.execute_reply.started":"2024-10-31T16:15:20.684583Z","shell.execute_reply":"2024-10-31T16:15:20.911960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.callbacks import EarlyStopping, ReduceLROnPlateau\n","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:15:38.801719Z","iopub.execute_input":"2024-10-31T16:15:38.802204Z","iopub.status.idle":"2024-10-31T16:15:38.809967Z","shell.execute_reply.started":"2024-10-31T16:15:38.802159Z","shell.execute_reply":"2024-10-31T16:15:38.808411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"earlystop = EarlyStopping(patience=5)","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:15:48.105801Z","iopub.execute_input":"2024-10-31T16:15:48.106268Z","iopub.status.idle":"2024-10-31T16:15:48.112970Z","shell.execute_reply.started":"2024-10-31T16:15:48.106228Z","shell.execute_reply":"2024-10-31T16:15:48.111307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learning_rate_reduction = ReduceLROnPlateau(monitor='val_acc', \n                                            patience=2, \n                                            verbose=1, \n                                            factor=0.5, \n                                            min_lr=0.00001)\n\ncallbacks = [earlystop, learning_rate_reduction]","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:25:18.464857Z","iopub.execute_input":"2024-10-31T16:25:18.465334Z","iopub.status.idle":"2024-10-31T16:25:18.472586Z","shell.execute_reply.started":"2024-10-31T16:25:18.465288Z","shell.execute_reply":"2024-10-31T16:25:18.471334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs = 3 if FAST_RUN else 10\n\nhistory = model.fit(train_generator,\n                    epochs=epochs,\n                    validation_data=valid_generator,\n#                     validation_steps=total_validate//batch_size, # 5000//15  = 333\n#                     steps_per_epoch=total_train//batch_size,     # 20000//15 = 1333\n                    callbacks=callbacks)","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:37:34.241380Z","iopub.execute_input":"2024-10-31T16:37:34.241928Z","iopub.status.idle":"2024-10-31T17:09:24.710691Z","shell.execute_reply.started":"2024-10-31T16:37:34.241859Z","shell.execute_reply":"2024-10-31T17:09:24.709221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy = history.history[\"accuracy\"]\nval_accuracy = history.history[\"val_accuracy\"]\n\nloss = history.history[\"loss\"]\nval_loss = history.history[\"val_loss\"]\n\nepochs = range(len(accuracy))\n\nplt.figure(figsize=(12,6))\n\nplt.subplot(1,2,1)\nplt.plot(epochs, accuracy, 'bo', label=\"Train_Acc\")\nplt.plot(epochs, val_accuracy, 'r', label=\"val_Acc\")\nplt.legend(loc='best', shadow=True)\n\nplt.subplot(1,2,2)\nplt.plot(epochs, loss, 'bo', label=\"Train_Loss\")\nplt.plot(epochs, val_loss, 'r', label=\"val_Loss\")\nplt.legend(loc='best', shadow=True)\n\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-10-31T16:37:02.308920Z","iopub.execute_input":"2024-10-31T16:37:02.309501Z","iopub.status.idle":"2024-10-31T16:37:02.812514Z","shell.execute_reply.started":"2024-10-31T16:37:02.309447Z","shell.execute_reply":"2024-10-31T16:37:02.811313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_file_names = os.listdir(\"/kaggle/working/test1\")\ntest_df = pd.DataFrame({'file_name': test_file_names})\n\ntotal_testing = test_df.shape[0]","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_gen = ImageDataGenerator(rescale=1./255)\ntest_generator = test_gen.flow_from_dataframe(\n    test_df, \n    \"/kaggle/working/test1\", \n    x_col='file_name',\n    y_col=None,\n    class_mode=None,\n    target_size=IMAGE_SIZE,\n    batch_size=batch_size,\n    shuffle=False\n)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = model.predict(test_generator)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df[\"CATEGORIES\"] = np.argmax(predictions, axis=1)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_map = dict((v,k) for k,v in train_generator.class_indices.items())\ntest_df['CATEGORIES'] = test_df['CATEGORIES'].replace(label_map)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['CATEGORIES'] = test_df['CATEGORIES'].replace({ 'dog': 1, 'cat': 0 })","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df[\"CATEGORIES\"].value_counts().plot.bar()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_test = test_df.head(36)\n\nplt.figure(figsize=(15,15))\n\nfor index, row in sample_test.iterrows():\n    file_name = row['file_name']\n    category = row['CATEGORIES']\n    path = os.path.join(\"/kaggle/working/test1\", file_name)\n    img = load_img(path, target_size=IMAGE_SIZE)\n    plt.subplot(6,6,index+1)\n    plt.imshow(img)\n    plt.title(f\"{file_name}\\n is ==> {'cat' if category==0 else 'dog'}\")\n    plt.axis('off')\nplt.tight_layout()\nplt.show()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save(\"CNN.h5\")\nmodel.save_weights(\"CNN.weights.h5\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = test_df.copy()\nsubmission_df['id'] = submission_df['file_name'].str.split('.').str[0]\nsubmission_df['label'] = submission_df['CATEGORIES']\nsubmission_df.drop(['file_name', 'CATEGORIES'], axis=1, inplace=True)\nsubmission_df.to_csv(\"submission.csv\", index=False)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!wget https://wl-genial.cf.tsp.li/resize/728x/jpg/27e/3ac/d457dd54cdbe4443445792ccb8.jpg\nimagen = load_img('d457dd54cdbe4443445792ccb8.jpg', target_size=IMAGE_SIZE)\nimg = np.expand_dims(imagen, 0) # make 'batch' of 1\npred = model.predict(img)\n#pred = labels[\"label_names\"][np.argmax(pred)]\ncategory = np.argmax(pred)\nplt.imshow(imagen)\nplt.title(f\"esa imagen es \\n ==> {'cat' if category==0 else 'dog'}\")\nplt.axis('off')\nplt.tight_layout()\nplt.show()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!wget https://oglebay.com/wp-content/uploads/2022/06/IMG_5670_M-e1654806092422.jpg\nimagen = load_img('IMG_5670_M-e1654806092422.jpg', target_size=IMAGE_SIZE)\nimg = np.expand_dims(imagen, 0) # make 'batch' of 1\npred = model.predict(img)\n#pred = labels[\"label_names\"][np.argmax(pred)]\ncategory = np.argmax(pred)\nplt.imshow(imagen)\nplt.title(f\"esa imagen es \\n ==> {'cat' if category==0 else 'dog'}\")\nplt.axis('off')\nplt.tight_layout()\nplt.show()","metadata":{},"execution_count":null,"outputs":[]}]}