{"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":"2023-07-27T01:48:36.928119Z","iopub.execute_input":"2023-07-27T01:48:36.928574Z","iopub.status.idle":"2023-07-27T01:48:36.946129Z","shell.execute_reply.started":"2023-07-27T01:48:36.928539Z","shell.execute_reply":"2023-07-27T01:48:36.944998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nimport numpy as np\nimport pandas as pd \n\nimport matplotlib.pyplot as plt\nimport matplotlib.image as img\n%matplotlib inline\nimport seaborn as sns\nfrom PIL import Image, ImageFilter, ImageEnhance\nimport cv2\n\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras import layers\nfrom tensorflow.keras.layers.experimental import preprocessing\nimport os\nfrom numpy import asarray\n\nimport zipfile\n\nzip_files = ['test1', 'train']\n\nfor zip_file in zip_files:\n    with zipfile.ZipFile(\"../input/dogs-vs-cats/{}.zip\".format(zip_file),\"r\") as z:\n        z.extractall(\".\")\n        print(\"{} unzipped\".format(zip_file))","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:36.948323Z","iopub.execute_input":"2023-07-27T01:48:36.948985Z","iopub.status.idle":"2023-07-27T01:48:50.406657Z","shell.execute_reply.started":"2023-07-27T01:48:36.948951Z","shell.execute_reply":"2023-07-27T01:48:50.405279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"TRAIN_DIR_PATH = './train'\nfile_names = os.listdir(TRAIN_DIR_PATH)\nprint('There are {} number of images in directory.'.format(len(file_names)))","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:50.408532Z","iopub.execute_input":"2023-07-27T01:48:50.409009Z","iopub.status.idle":"2023-07-27T01:48:50.438554Z","shell.execute_reply.started":"2023-07-27T01:48:50.408964Z","shell.execute_reply":"2023-07-27T01:48:50.437163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#import numpy as np\n#import pandas as pd \n#from keras.preprocessing.image \n#from tensorflow.keras.utils import load_img\n#import ImageDataGenerator, load_img\n#from keras.utils import to_categorical\n#from sklearn.model_selection import train_test_split\n#import matplotlib.pyplot as plt\n#import random\n#import os\n#print(os.listdir(\"../input\"))","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:50.442185Z","iopub.execute_input":"2023-07-27T01:48:50.44268Z","iopub.status.idle":"2023-07-27T01:48:50.451214Z","shell.execute_reply.started":"2023-07-27T01:48:50.442632Z","shell.execute_reply":"2023-07-27T01:48:50.449523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nFAST_RUN = False\nIMAGE_WIDTH=128\nIMAGE_HEIGHT=128\nIMAGE_SIZE=(IMAGE_WIDTH, IMAGE_HEIGHT)\nIMAGE_CHANNELS=3\n\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:50.452812Z","iopub.execute_input":"2023-07-27T01:48:50.45322Z","iopub.status.idle":"2023-07-27T01:48:50.466593Z","shell.execute_reply.started":"2023-07-27T01:48:50.453186Z","shell.execute_reply":"2023-07-27T01:48:50.465213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#filenames = os.listdir(\"../input/train/train\")\nfilenames = os.listdir(TRAIN_DIR_PATH)\ncategories = []\nfor filename in filenames:\n    category = filename.split('.')[0]\n    if category == 'dog':\n        categories.append(1)\n    else:\n        categories.append(0)\n\ndf = pd.DataFrame({\n    'filename': filenames,\n    'category': categories\n})\n\ndf.head()\n\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:50.468211Z","iopub.execute_input":"2023-07-27T01:48:50.468613Z","iopub.status.idle":"2023-07-27T01:48:50.544148Z","shell.execute_reply.started":"2023-07-27T01:48:50.468577Z","shell.execute_reply":"2023-07-27T01:48:50.542774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\ndf.tail()\n\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:50.546043Z","iopub.execute_input":"2023-07-27T01:48:50.546441Z","iopub.status.idle":"2023-07-27T01:48:50.55768Z","shell.execute_reply.started":"2023-07-27T01:48:50.546406Z","shell.execute_reply":"2023-07-27T01:48:50.556419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['category'].value_counts().plot.bar()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:50.559441Z","iopub.execute_input":"2023-07-27T01:48:50.559896Z","iopub.status.idle":"2023-07-27T01:48:50.783307Z","shell.execute_reply.started":"2023-07-27T01:48:50.559852Z","shell.execute_reply":"2023-07-27T01:48:50.782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = random.choice(filenames)\n#image = load_img(\"../input/train/train/\"+sample)\nimage = load_img(\"./train/\"+sample)\nplt.imshow(image)","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:50.784732Z","iopub.execute_input":"2023-07-27T01:48:50.785117Z","iopub.status.idle":"2023-07-27T01:48:51.197801Z","shell.execute_reply.started":"2023-07-27T01:48:50.785083Z","shell.execute_reply":"2023-07-27T01:48:51.196521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.models import Sequential\nfrom keras.layers import Conv2D, MaxPooling2D, Dropout, Flatten, Dense, Activation, BatchNormalization\n\nmodel = Sequential()\n\nmodel.add(Conv2D(32, (3, 3), activation='relu', input_shape=(IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_CHANNELS)))\nmodel.add(BatchNormalization())\nmodel.add(MaxPooling2D(pool_size=(2, 2)))\nmodel.add(Dropout(0.25))\n\nmodel.add(Conv2D(64, (3, 3), activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(MaxPooling2D(pool_size=(2, 2)))\nmodel.add(Dropout(0.25))\n\nmodel.add(Conv2D(128, (3, 3), activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(MaxPooling2D(pool_size=(2, 2)))\nmodel.add(Dropout(0.25))\n\nmodel.add(Flatten())\nmodel.add(Dense(512, activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(Dropout(0.5))\nmodel.add(Dense(2, activation='softmax')) # 2 because we have cat and dog classes\n\nmodel.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])\n\nmodel.summary()\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:51.202497Z","iopub.execute_input":"2023-07-27T01:48:51.202906Z","iopub.status.idle":"2023-07-27T01:48:51.593418Z","shell.execute_reply.started":"2023-07-27T01:48:51.202871Z","shell.execute_reply":"2023-07-27T01:48:51.591737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nfrom keras.callbacks import EarlyStopping, ReduceLROnPlateau\n\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:51.59513Z","iopub.execute_input":"2023-07-27T01:48:51.596047Z","iopub.status.idle":"2023-07-27T01:48:51.602335Z","shell.execute_reply.started":"2023-07-27T01:48:51.596Z","shell.execute_reply":"2023-07-27T01:48:51.600839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nearlystop = EarlyStopping(patience=10)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:51.604582Z","iopub.execute_input":"2023-07-27T01:48:51.605087Z","iopub.status.idle":"2023-07-27T01:48:51.617245Z","shell.execute_reply.started":"2023-07-27T01:48:51.605043Z","shell.execute_reply":"2023-07-27T01:48:51.615848Z"},"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)","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:51.619393Z","iopub.execute_input":"2023-07-27T01:48:51.619852Z","iopub.status.idle":"2023-07-27T01:48:51.632463Z","shell.execute_reply.started":"2023-07-27T01:48:51.61981Z","shell.execute_reply":"2023-07-27T01:48:51.631233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"callbacks = [earlystop, learning_rate_reduction]","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:51.634142Z","iopub.execute_input":"2023-07-27T01:48:51.634484Z","iopub.status.idle":"2023-07-27T01:48:51.647218Z","shell.execute_reply.started":"2023-07-27T01:48:51.634455Z","shell.execute_reply":"2023-07-27T01:48:51.645399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"category\"] = df[\"category\"].replace({0: 'cat', 1: 'dog'}) \n\ntrain_df, validate_df = train_test_split(df, test_size=0.20, random_state=42)\ntrain_df = train_df.reset_index(drop=True)\nvalidate_df = validate_df.reset_index(drop=True)\n\ntrain_df['category'].value_counts().plot.bar()\n\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:51.648883Z","iopub.execute_input":"2023-07-27T01:48:51.649331Z","iopub.status.idle":"2023-07-27T01:48:51.911868Z","shell.execute_reply.started":"2023-07-27T01:48:51.649295Z","shell.execute_reply":"2023-07-27T01:48:51.910416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nvalidate_df['category'].value_counts().plot.bar()\n\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:51.913735Z","iopub.execute_input":"2023-07-27T01:48:51.914119Z","iopub.status.idle":"2023-07-27T01:48:52.155237Z","shell.execute_reply.started":"2023-07-27T01:48:51.914085Z","shell.execute_reply":"2023-07-27T01:48:52.154013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"total_train = train_df.shape[0]\ntotal_validate = validate_df.shape[0]\nbatch_size=15\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:52.157104Z","iopub.execute_input":"2023-07-27T01:48:52.157642Z","iopub.status.idle":"2023-07-27T01:48:52.161696Z","shell.execute_reply.started":"2023-07-27T01:48:52.157609Z","shell.execute_reply":"2023-07-27T01:48:52.160834Z"},"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    #\"../input/train/train/\", \n    \"./train/\", \n    x_col='filename',\n    y_col='category',\n    target_size=IMAGE_SIZE,\n    class_mode='categorical',\n    batch_size=batch_size\n)","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:52.163207Z","iopub.execute_input":"2023-07-27T01:48:52.163559Z","iopub.status.idle":"2023-07-27T01:48:52.463143Z","shell.execute_reply.started":"2023-07-27T01:48:52.163528Z","shell.execute_reply":"2023-07-27T01:48:52.462004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"validation_datagen = ImageDataGenerator(rescale=1./255)\nvalidation_generator = validation_datagen.flow_from_dataframe(\n    validate_df, \n    #\"../input/train/train/\", \n    \"./train/\", \n    x_col='filename',\n    y_col='category',\n    target_size=IMAGE_SIZE,\n    class_mode='categorical',\n    batch_size=batch_size\n)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:52.464773Z","iopub.execute_input":"2023-07-27T01:48:52.465174Z","iopub.status.idle":"2023-07-27T01:48:52.551297Z","shell.execute_reply.started":"2023-07-27T01:48:52.465135Z","shell.execute_reply":"2023-07-27T01:48:52.55002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_df = train_df.sample(n=1).reset_index(drop=True)\nexample_generator = train_datagen.flow_from_dataframe(\n    example_df, \n    #\"../input/train/train/\", \n    \"./train/\", \n    x_col='filename',\n    y_col='category',\n    target_size=IMAGE_SIZE,\n    class_mode='categorical'\n)","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:52.553164Z","iopub.execute_input":"2023-07-27T01:48:52.553869Z","iopub.status.idle":"2023-07-27T01:48:52.568475Z","shell.execute_reply.started":"2023-07-27T01:48:52.55382Z","shell.execute_reply":"2023-07-27T01:48:52.567159Z"},"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        break\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:52.570344Z","iopub.execute_input":"2023-07-27T01:48:52.570917Z","iopub.status.idle":"2023-07-27T01:48:56.488091Z","shell.execute_reply.started":"2023-07-27T01:48:52.570881Z","shell.execute_reply":"2023-07-27T01:48:56.487026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs=3 \n#if FAST_RUN else 50\nhistory = model.fit(\n    train_generator, \n    epochs=epochs,\n    validation_data=validation_generator,\n    validation_steps=total_validate//batch_size,\n    steps_per_epoch=total_train//batch_size,\n    callbacks=callbacks\n)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T01:48:56.489888Z","iopub.execute_input":"2023-07-27T01:48:56.490587Z","iopub.status.idle":"2023-07-27T02:21:56.784818Z","shell.execute_reply.started":"2023-07-27T01:48:56.490549Z","shell.execute_reply":"2023-07-27T02:21:56.783028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save_weights(\"model.h5\")\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:21:56.787363Z","iopub.execute_input":"2023-07-27T02:21:56.78787Z","iopub.status.idle":"2023-07-27T02:21:57.034361Z","shell.execute_reply.started":"2023-07-27T02:21:56.787822Z","shell.execute_reply":"2023-07-27T02:21:57.03317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 12))\nax1.plot(history.history['loss'], color='b', label=\"Training loss\")\nax1.plot(history.history['val_loss'], color='r', label=\"validation loss\")\nax1.set_xticks(np.arange(1, epochs, 1))\nax1.set_yticks(np.arange(0, 1, 0.1))\n\nax2.plot(history.history['accuracy'], color='b', label=\"Training accuracy\")\nax2.plot(history.history['val_accuracy'], color='r',label=\"Validation accuracy\")\nax2.set_xticks(np.arange(1, epochs, 1))\nax2.set_yticks(np.arange(0, 1, 0.1))\n\nlegend = plt.legend(loc='best', shadow=True)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:21:57.036116Z","iopub.execute_input":"2023-07-27T02:21:57.036601Z","iopub.status.idle":"2023-07-27T02:21:57.61105Z","shell.execute_reply.started":"2023-07-27T02:21:57.036556Z","shell.execute_reply":"2023-07-27T02:21:57.60985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_filenames = os.listdir(\"../input/test1/test1\")\ntest_filenames = os.listdir(\"./test1\")\ntest_df = pd.DataFrame({\n    'filename': test_filenames\n})\nnb_samples = test_df.shape[0]","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:21:57.612806Z","iopub.execute_input":"2023-07-27T02:21:57.614003Z","iopub.status.idle":"2023-07-27T02:21:57.636416Z","shell.execute_reply.started":"2023-07-27T02:21:57.613962Z","shell.execute_reply":"2023-07-27T02:21:57.635379Z"},"trusted":true},"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    #\"../input/test1/test1/\", \n    \"./test1/\", \n    x_col='filename',\n    y_col=None,\n    class_mode=None,\n    target_size=IMAGE_SIZE,\n    batch_size=batch_size,\n    shuffle=False\n)","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:21:57.637856Z","iopub.execute_input":"2023-07-27T02:21:57.638847Z","iopub.status.idle":"2023-07-27T02:21:57.811524Z","shell.execute_reply.started":"2023-07-27T02:21:57.63881Z","shell.execute_reply":"2023-07-27T02:21:57.809932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict = model.predict(test_generator, steps=np.ceil(nb_samples/batch_size))","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:21:57.813711Z","iopub.execute_input":"2023-07-27T02:21:57.814523Z","iopub.status.idle":"2023-07-27T02:23:19.958333Z","shell.execute_reply.started":"2023-07-27T02:21:57.814474Z","shell.execute_reply":"2023-07-27T02:23:19.957251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\ntest_df['category'] = np.argmax(predict, axis=-1)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:23:19.965061Z","iopub.execute_input":"2023-07-27T02:23:19.965497Z","iopub.status.idle":"2023-07-27T02:23:19.972792Z","shell.execute_reply.started":"2023-07-27T02:23:19.96546Z","shell.execute_reply":"2023-07-27T02:23:19.971334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_map = dict((v,k) for k,v in train_generator.class_indices.items())\ntest_df['category'] = test_df['category'].replace(label_map)","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:23:19.974686Z","iopub.execute_input":"2023-07-27T02:23:19.975051Z","iopub.status.idle":"2023-07-27T02:23:19.99091Z","shell.execute_reply.started":"2023-07-27T02:23:19.975021Z","shell.execute_reply":"2023-07-27T02:23:19.989543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['category'] = test_df['category'].replace({ 'dog': 1, 'cat': 0 })","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:23:19.992798Z","iopub.execute_input":"2023-07-27T02:23:19.993869Z","iopub.status.idle":"2023-07-27T02:23:20.015249Z","shell.execute_reply.started":"2023-07-27T02:23:19.993832Z","shell.execute_reply":"2023-07-27T02:23:20.013779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['category'].value_counts().plot.bar()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:23:20.017549Z","iopub.execute_input":"2023-07-27T02:23:20.018576Z","iopub.status.idle":"2023-07-27T02:23:20.271779Z","shell.execute_reply.started":"2023-07-27T02:23:20.018538Z","shell.execute_reply":"2023-07-27T02:23:20.270405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_test = test_df.head(18)\nsample_test.head()\nplt.figure(figsize=(12, 24))\nfor index, row in sample_test.iterrows():\n    filename = row['filename']\n    category = row['category']\n    #img = load_img(\"../input/test1/test1/\"+filename, target_size=IMAGE_SIZE)\n    img = load_img(\"./test1/\"+filename, target_size=IMAGE_SIZE)\n    plt.subplot(6, 3, index+1)\n    plt.imshow(img)\n    plt.xlabel(filename + '(' + \"{}\".format(category) + ')' )\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:23:20.273629Z","iopub.execute_input":"2023-07-27T02:23:20.274047Z","iopub.status.idle":"2023-07-27T02:23:25.84826Z","shell.execute_reply.started":"2023-07-27T02:23:20.274013Z","shell.execute_reply":"2023-07-27T02:23:25.84454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = test_df.copy()\nsubmission_df['id'] = submission_df['filename'].str.split('.').str[0]\nsubmission_df['label'] = submission_df['category']\nsubmission_df.drop(['filename', 'category'], axis=1, inplace=True)\nsubmission_df.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:23:25.850362Z","iopub.execute_input":"2023-07-27T02:23:25.850783Z","iopub.status.idle":"2023-07-27T02:23:25.929488Z","shell.execute_reply.started":"2023-07-27T02:23:25.850747Z","shell.execute_reply":"2023-07-27T02:23:25.928088Z"},"trusted":true},"execution_count":null,"outputs":[]}]}