{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"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":"2022-11-13T04:50:07.487603Z","iopub.execute_input":"2022-11-13T04:50:07.488103Z","iopub.status.idle":"2022-11-13T04:50:07.504230Z","shell.execute_reply.started":"2022-11-13T04:50:07.487995Z","shell.execute_reply":"2022-11-13T04:50:07.502835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Extract image from zip\nimport zipfile\n\ntrain_zip = zipfile.ZipFile(\"/kaggle/input/dogs-vs-cats/train.zip\")\ntrain_zip.extractall(\"/kaggle/working/dataset\")\ntrain_zip.close()\n\ntest_zip = zipfile.ZipFile(\"/kaggle/input/dogs-vs-cats/test1.zip\")\ntest_zip.extractall(\"/kaggle/working/dataset\")\ntest_zip.close()","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:07.506466Z","iopub.execute_input":"2022-11-13T04:50:07.506846Z","iopub.status.idle":"2022-11-13T04:50:30.282744Z","shell.execute_reply.started":"2022-11-13T04:50:07.506814Z","shell.execute_reply":"2022-11-13T04:50:30.281609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# List up train and test image file name into\ntrain_dirname, test_dirname = \"/kaggle/working/dataset/train\", \"/kaggle/working/dataset/test1\"\ntrain_filenames, test_filenames = [], []\nfor dirname, _, filenames in os.walk('/kaggle/working/dataset/'):\n    for filename in filenames:\n        if dirname == train_dirname:\n            train_filenames.append(filename)\n        elif dirname == test_dirname:\n            test_filenames.append(filename)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:30.284168Z","iopub.execute_input":"2022-11-13T04:50:30.284597Z","iopub.status.idle":"2022-11-13T04:50:30.349167Z","shell.execute_reply.started":"2022-11-13T04:50:30.284557Z","shell.execute_reply":"2022-11-13T04:50:30.347959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create y list based on file names (1 = dog, 0 = cat)\ntrain_target = []\nfor filename in train_filenames:\n    if \"dog\" in filename:\n        train_target.append(1)\n    elif \"cat\" in filename:\n        train_target.append(0)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:30.351787Z","iopub.execute_input":"2022-11-13T04:50:30.352183Z","iopub.status.idle":"2022-11-13T04:50:30.371827Z","shell.execute_reply.started":"2022-11-13T04:50:30.352149Z","shell.execute_reply":"2022-11-13T04:50:30.370583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#no.of cores each processor is having\n!lscpu | grep 'Core(s) per socket'\n\n#no.of threads each core is having\n!lscpu | grep 'Thread(s) per core'","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:30.373542Z","iopub.execute_input":"2022-11-13T04:50:30.374053Z","iopub.status.idle":"2022-11-13T04:50:32.561926Z","shell.execute_reply.started":"2022-11-13T04:50:30.374018Z","shell.execute_reply":"2022-11-13T04:50:32.560436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\n\n# configuration to resolve performance issue\ninit = tf.compat.v1.global_variables_initializer()\nconfig = tf.compat.v1.ConfigProto(intra_op_parallelism_threads=2,\n                       inter_op_parallelism_threads=2,\n                       allow_soft_placement=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:32.564152Z","iopub.execute_input":"2022-11-13T04:50:32.564515Z","iopub.status.idle":"2022-11-13T04:50:38.756380Z","shell.execute_reply.started":"2022-11-13T04:50:32.564478Z","shell.execute_reply":"2022-11-13T04:50:38.755115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Resizing image data\n@tf.function\ndef scale_resize_image(image):\n    image = tf.image.convert_image_dtype(image, tf.float32)\n    image = tf.image.resize(image, (224, 224))\n    return image","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:38.758175Z","iopub.execute_input":"2022-11-13T04:50:38.759275Z","iopub.status.idle":"2022-11-13T04:50:38.765427Z","shell.execute_reply.started":"2022-11-13T04:50:38.759230Z","shell.execute_reply":"2022-11-13T04:50:38.764365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Spread 9 random images with their target\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\n\ndef get_random_images(dirname, images, targets, seed):\n    if seed is not None:\n        np.random.seed(seed)\n    \n    index = [*range(0, len(images))]\n    np.random.shuffle(index)\n    \n    fig, axs = plt.subplots(3, 3, figsize=(10, 10))\n    \n    for i in range(9):\n        img = mpimg.imread(os.path.join(dirname, images[index[i]]))\n        axs[i//3, i%3].imshow(scale_resize_image(img))\n        axs[i//3, i%3].set_title(\"cat\" if targets[index[i]] == 0 else \"dog\")\n","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:38.766956Z","iopub.execute_input":"2022-11-13T04:50:38.767914Z","iopub.status.idle":"2022-11-13T04:50:38.779440Z","shell.execute_reply.started":"2022-11-13T04:50:38.767845Z","shell.execute_reply":"2022-11-13T04:50:38.778237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"get_random_images(train_dirname, train_filenames, train_target, None)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:38.781145Z","iopub.execute_input":"2022-11-13T04:50:38.781491Z","iopub.status.idle":"2022-11-13T04:50:40.537590Z","shell.execute_reply.started":"2022-11-13T04:50:38.781461Z","shell.execute_reply":"2022-11-13T04:50:40.536070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow import keras\nfrom tensorflow.keras import layers\nfrom tensorflow.keras.models import Sequential","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:40.541770Z","iopub.execute_input":"2022-11-13T04:50:40.542255Z","iopub.status.idle":"2022-11-13T04:50:41.601478Z","shell.execute_reply.started":"2022-11-13T04:50:40.542219Z","shell.execute_reply":"2022-11-13T04:50:41.599960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\n\n# To use image_dataset_from_directory split dog and cat\ndog_dir = \"/kaggle/working/dataset/train/dog/\"\ncat_dir = \"/kaggle/working/dataset/train/cat/\"\n\nif not os.path.exists(dog_dir):\n    os.mkdir(dog_dir)\n    \nif not os.path.exists(cat_dir):\n    os.mkdir(cat_dir)\n\nfor filename in train_filenames:\n    if \"dog\" in filename:\n        shutil.move(os.path.join(train_dirname, filename), dog_dir + filename)\n    elif \"cat\" in filename:\n        shutil.move(os.path.join(train_dirname, filename), cat_dir + filename)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:41.603404Z","iopub.execute_input":"2022-11-13T04:50:41.604108Z","iopub.status.idle":"2022-11-13T04:50:42.456687Z","shell.execute_reply.started":"2022-11-13T04:50:41.604069Z","shell.execute_reply":"2022-11-13T04:50:42.455280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_ds = tf.keras.preprocessing.image_dataset_from_directory(\n    train_dirname,\n    validation_split=0.2,\n    subset=\"training\",\n    seed=123,\n    image_size=(224, 224),\n    batch_size=32\n)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:42.458082Z","iopub.execute_input":"2022-11-13T04:50:42.458433Z","iopub.status.idle":"2022-11-13T04:50:43.249400Z","shell.execute_reply.started":"2022-11-13T04:50:42.458401Z","shell.execute_reply":"2022-11-13T04:50:43.247904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_ds = tf.keras.preprocessing.image_dataset_from_directory(\n    train_dirname,\n    validation_split=0.2,\n    subset=\"validation\",\n    seed=123,\n    image_size=(224, 224),\n    batch_size=32\n)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:43.251000Z","iopub.execute_input":"2022-11-13T04:50:43.251673Z","iopub.status.idle":"2022-11-13T04:50:43.967769Z","shell.execute_reply.started":"2022-11-13T04:50:43.251634Z","shell.execute_reply":"2022-11-13T04:50:43.966669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_names = train_ds.class_names\nprint(class_names)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:43.969044Z","iopub.execute_input":"2022-11-13T04:50:43.970030Z","iopub.status.idle":"2022-11-13T04:50:43.976149Z","shell.execute_reply.started":"2022-11-13T04:50:43.969994Z","shell.execute_reply":"2022-11-13T04:50:43.975040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 10))\nfor images, labels in train_ds.take(1):\n    for i in range(9):\n        ax = plt.subplot(3, 3, i + 1)\n        plt.imshow(images[i].numpy().astype(\"uint8\"))\n        plt.title(class_names[labels[i]])\n        plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:43.978454Z","iopub.execute_input":"2022-11-13T04:50:43.979039Z","iopub.status.idle":"2022-11-13T04:50:45.211424Z","shell.execute_reply.started":"2022-11-13T04:50:43.978814Z","shell.execute_reply":"2022-11-13T04:50:45.210077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for image_batch, labels_batch in train_ds:\n    print(image_batch.shape)\n    print(labels_batch.shape)\n    break","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:45.213061Z","iopub.execute_input":"2022-11-13T04:50:45.213430Z","iopub.status.idle":"2022-11-13T04:50:45.528204Z","shell.execute_reply.started":"2022-11-13T04:50:45.213396Z","shell.execute_reply":"2022-11-13T04:50:45.526938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AUTOTUNE = tf.data.experimental.AUTOTUNE\n\ntrain_ds = train_ds.cache().shuffle(1000).prefetch(buffer_size=AUTOTUNE)\nval_ds = val_ds.cache().prefetch(buffer_size=AUTOTUNE)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:45.529547Z","iopub.execute_input":"2022-11-13T04:50:45.529869Z","iopub.status.idle":"2022-11-13T04:50:45.538235Z","shell.execute_reply.started":"2022-11-13T04:50:45.529840Z","shell.execute_reply":"2022-11-13T04:50:45.537124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"normalization_layer = layers.experimental.preprocessing.Rescaling(1./255)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:45.539514Z","iopub.execute_input":"2022-11-13T04:50:45.539859Z","iopub.status.idle":"2022-11-13T04:50:45.565025Z","shell.execute_reply.started":"2022-11-13T04:50:45.539828Z","shell.execute_reply":"2022-11-13T04:50:45.563943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"normalized_ds = train_ds.map(lambda x, y: (normalization_layer(x), y))\nimage_batch, labels_batch = next(iter(normalized_ds))\nfirst_image = image_batch[0]\nprint(np.min(first_image), np.max(first_image))","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:50:45.566460Z","iopub.execute_input":"2022-11-13T04:50:45.567071Z","iopub.status.idle":"2022-11-13T04:51:00.678163Z","shell.execute_reply.started":"2022-11-13T04:50:45.567028Z","shell.execute_reply":"2022-11-13T04:51:00.676973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_classes = len(class_names)\n\nmodel = Sequential([\n    layers.experimental.preprocessing.Rescaling(1./255, input_shape=(224, 224, 3)),\n    layers.Conv2D(16, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Conv2D(32, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Conv2D(64, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Flatten(),\n    layers.Dense(128, activation='relu'),\n    layers.Dense(num_classes),\n])","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:51:00.679915Z","iopub.execute_input":"2022-11-13T04:51:00.680358Z","iopub.status.idle":"2022-11-13T04:51:00.840460Z","shell.execute_reply.started":"2022-11-13T04:51:00.680315Z","shell.execute_reply":"2022-11-13T04:51:00.839259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer='adam',\n             loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n             metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:51:00.842764Z","iopub.execute_input":"2022-11-13T04:51:00.843100Z","iopub.status.idle":"2022-11-13T04:51:00.861533Z","shell.execute_reply.started":"2022-11-13T04:51:00.843070Z","shell.execute_reply":"2022-11-13T04:51:00.860306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:51:00.862985Z","iopub.execute_input":"2022-11-13T04:51:00.863435Z","iopub.status.idle":"2022-11-13T04:51:00.871588Z","shell.execute_reply.started":"2022-11-13T04:51:00.863391Z","shell.execute_reply":"2022-11-13T04:51:00.870416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs = 10\nhistory = model.fit(\n    train_ds,\n    validation_data=val_ds,\n    epochs=epochs\n)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T04:51:00.873759Z","iopub.execute_input":"2022-11-13T04:51:00.874672Z","iopub.status.idle":"2022-11-13T05:33:45.110726Z","shell.execute_reply.started":"2022-11-13T04:51:00.874623Z","shell.execute_reply":"2022-11-13T05:33:45.109914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def visualize_training_results(history, epochs):\n    acc = history.history['accuracy']\n    val_acc = history.history['val_accuracy']\n    \n    loss = history.history['loss']\n    val_loss = history.history['val_loss']\n    \n    epochs_range = range(epochs)\n    \n    plt.figure(figsize=(8, 8))\n    plt.subplot(121)\n    plt.plot(epochs_range, acc, label=\"Training Accuracy\")\n    plt.plot(epochs_range, val_acc, label=\"Validation Accuracy\")\n    plt.legend(loc='best')\n    plt.title(\"Training and Validation Accuracy\")\n    \n    plt.subplot(122)\n    plt.plot(epochs_range, loss, label=\"Training Loss\")\n    plt.plot(epochs_range, val_loss, label=\"Validation Loss\")\n    plt.legend(loc='best')\n    plt.title(\"Training and Validation Loss\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-11-13T05:33:45.112142Z","iopub.execute_input":"2022-11-13T05:33:45.112472Z","iopub.status.idle":"2022-11-13T05:33:45.121251Z","shell.execute_reply.started":"2022-11-13T05:33:45.112443Z","shell.execute_reply":"2022-11-13T05:33:45.120160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"visualize_training_results(history, epochs)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T05:33:45.122853Z","iopub.execute_input":"2022-11-13T05:33:45.123323Z","iopub.status.idle":"2022-11-13T05:33:45.484974Z","shell.execute_reply.started":"2022-11-13T05:33:45.123292Z","shell.execute_reply":"2022-11-13T05:33:45.483455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_height, img_width = 224, 224\ndata_augmentation = keras.Sequential(\n    [\n        layers.experimental.preprocessing.RandomFlip(\"horizontal\",\n                                                    input_shape=(img_height,\n                                                                img_width,\n                                                                3)),\n        layers.experimental.preprocessing.RandomRotation(0.1),\n        layers.experimental.preprocessing.RandomZoom(0.1),\n    ]\n)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T05:33:45.486352Z","iopub.execute_input":"2022-11-13T05:33:45.486709Z","iopub.status.idle":"2022-11-13T05:33:45.641514Z","shell.execute_reply.started":"2022-11-13T05:33:45.486677Z","shell.execute_reply":"2022-11-13T05:33:45.640364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 10))\nfor images, _ in train_ds.take(1):\n    for i in range(9):\n        augmented_images = data_augmentation(images)\n        ax = plt.subplot(3, 3, i+1)\n        plt.imshow(augmented_images[0].numpy().astype('uint8'))\n        plt.axis('off')","metadata":{"execution":{"iopub.status.busy":"2022-11-13T05:33:45.642982Z","iopub.execute_input":"2022-11-13T05:33:45.643325Z","iopub.status.idle":"2022-11-13T05:33:48.742394Z","shell.execute_reply.started":"2022-11-13T05:33:45.643295Z","shell.execute_reply":"2022-11-13T05:33:48.741245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential([\n    data_augmentation,\n    layers.experimental.preprocessing.Rescaling(1./255),\n    layers.Conv2D(16, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Conv2D(32, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Conv2D(64, 3, padding='same', activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Dropout(0.2),\n    layers.Flatten(),\n    layers.Dense(128, activation='relu'),\n    layers.Dense(num_classes)\n])","metadata":{"execution":{"iopub.status.busy":"2022-11-13T05:33:48.747868Z","iopub.execute_input":"2022-11-13T05:33:48.748297Z","iopub.status.idle":"2022-11-13T05:33:49.000443Z","shell.execute_reply.started":"2022-11-13T05:33:48.748263Z","shell.execute_reply":"2022-11-13T05:33:48.999172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(\n    optimizer='adam',\n    loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n    metrics=['accuracy'],\n)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T05:33:49.002059Z","iopub.execute_input":"2022-11-13T05:33:49.002569Z","iopub.status.idle":"2022-11-13T05:33:49.014971Z","shell.execute_reply.started":"2022-11-13T05:33:49.002524Z","shell.execute_reply":"2022-11-13T05:33:49.014102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2022-11-13T05:33:49.016646Z","iopub.execute_input":"2022-11-13T05:33:49.017659Z","iopub.status.idle":"2022-11-13T05:33:49.028003Z","shell.execute_reply.started":"2022-11-13T05:33:49.017607Z","shell.execute_reply":"2022-11-13T05:33:49.026604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs = 30 # 20\n\ncheckpoint_filepath = '/kaggle/working/checkpoint'\nmodel_checkpoint_callback = tf.keras.callbacks.ModelCheckpoint(\n    filepath=checkpoint_filepath,\n    save_weights_only=True,\n    monitor='val_accuracy',\n    mode='max',\n    save_best_only=True)\n\nhistory = model.fit(\n    train_ds,\n    validation_data = val_ds,\n    epochs = epochs,\n    callbacks = [model_checkpoint_callback]\n)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T05:33:49.029668Z","iopub.execute_input":"2022-11-13T05:33:49.030633Z","iopub.status.idle":"2022-11-13T08:08:52.225876Z","shell.execute_reply.started":"2022-11-13T05:33:49.030592Z","shell.execute_reply":"2022-11-13T08:08:52.224980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"visualize_training_results(history, epochs)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T08:08:52.228037Z","iopub.execute_input":"2022-11-13T08:08:52.228864Z","iopub.status.idle":"2022-11-13T08:08:52.581988Z","shell.execute_reply.started":"2022-11-13T08:08:52.228819Z","shell.execute_reply":"2022-11-13T08:08:52.580710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_image(image):\n    img = tf.keras.utils.load_img(image, target_size=(img_height, img_width))\n    img_array = tf.keras.utils.img_to_array(img)\n    img_array = tf.expand_dims(img_array, 0)\n    return img_array","metadata":{"execution":{"iopub.status.busy":"2022-11-13T08:08:52.583261Z","iopub.execute_input":"2022-11-13T08:08:52.583579Z","iopub.status.idle":"2022-11-13T08:08:52.590248Z","shell.execute_reply.started":"2022-11-13T08:08:52.583551Z","shell.execute_reply":"2022-11-13T08:08:52.588966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv(\"/kaggle/input/dogs-vs-cats/sampleSubmission.csv\")\n\nmodel.load_weights(checkpoint_filepath)\n\nfor file in test_filenames:\n    prediction = model.predict(load_image(os.path.join(test_dirname, file)))\n    predict = np.argmax(prediction[0])\n    submission[\"label\"][int(os.path.splitext(file)[0])-1] = predict","metadata":{"execution":{"iopub.status.busy":"2022-11-13T08:08:52.591675Z","iopub.execute_input":"2022-11-13T08:08:52.592008Z","iopub.status.idle":"2022-11-13T08:22:12.261902Z","shell.execute_reply.started":"2022-11-13T08:08:52.591979Z","shell.execute_reply":"2022-11-13T08:22:12.260621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T08:28:00.111564Z","iopub.execute_input":"2022-11-13T08:28:00.112787Z","iopub.status.idle":"2022-11-13T08:28:00.134477Z","shell.execute_reply.started":"2022-11-13T08:28:00.112723Z","shell.execute_reply":"2022-11-13T08:28:00.133256Z"},"trusted":true},"execution_count":null,"outputs":[]}]}