{"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-30T09:03:24.287437Z","iopub.execute_input":"2023-07-30T09:03:24.287858Z","iopub.status.idle":"2023-07-30T09:03:24.298979Z","shell.execute_reply.started":"2023-07-30T09:03:24.287828Z","shell.execute_reply":"2023-07-30T09:03:24.297514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import 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-30T09:03:24.301221Z","iopub.execute_input":"2023-07-30T09:03:24.302158Z","iopub.status.idle":"2023-07-30T09:03:36.235397Z","shell.execute_reply.started":"2023-07-30T09:03:24.302116Z","shell.execute_reply":"2023-07-30T09:03:36.234558Z"},"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-30T09:03:36.237381Z","iopub.execute_input":"2023-07-30T09:03:36.238021Z","iopub.status.idle":"2023-07-30T09:03:36.261516Z","shell.execute_reply.started":"2023-07-30T09:03:36.237989Z","shell.execute_reply":"2023-07-30T09:03:36.259994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd \n#from keras.preprocessing.image \nfrom tensorflow.keras.utils import load_img\n#import ImageDataGenerator, load_img\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom keras.utils import to_categorical\nfrom sklearn.model_selection import train_test_split\nimport matplotlib.pyplot as plt\nimport random\nimport os\nprint(os.listdir(\"../input\"))","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:36.263068Z","iopub.execute_input":"2023-07-30T09:03:36.263592Z","iopub.status.idle":"2023-07-30T09:03:36.271648Z","shell.execute_reply.started":"2023-07-30T09:03:36.263556Z","shell.execute_reply":"2023-07-30T09:03:36.270198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"FAST_RUN = False\nIMAGE_WIDTH=128\nIMAGE_HEIGHT=128\nIMAGE_SIZE=(IMAGE_WIDTH, IMAGE_HEIGHT)\nIMAGE_CHANNELS=3","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:36.275909Z","iopub.execute_input":"2023-07-30T09:03:36.277535Z","iopub.status.idle":"2023-07-30T09:03:36.285427Z","shell.execute_reply.started":"2023-07-30T09:03:36.277480Z","shell.execute_reply":"2023-07-30T09:03:36.284290Z"},"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()","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:36.287270Z","iopub.execute_input":"2023-07-30T09:03:36.287857Z","iopub.status.idle":"2023-07-30T09:03:36.356087Z","shell.execute_reply.started":"2023-07-30T09:03:36.287814Z","shell.execute_reply":"2023-07-30T09:03:36.354711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.tail()","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:36.357617Z","iopub.execute_input":"2023-07-30T09:03:36.358060Z","iopub.status.idle":"2023-07-30T09:03:36.371306Z","shell.execute_reply.started":"2023-07-30T09:03:36.358005Z","shell.execute_reply":"2023-07-30T09:03:36.369779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['category'].value_counts().plot.bar()","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:36.373032Z","iopub.execute_input":"2023-07-30T09:03:36.373432Z","iopub.status.idle":"2023-07-30T09:03:36.636627Z","shell.execute_reply.started":"2023-07-30T09:03:36.373399Z","shell.execute_reply":"2023-07-30T09:03:36.635270Z"},"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-30T09:03:36.638450Z","iopub.execute_input":"2023-07-30T09:03:36.638935Z","iopub.status.idle":"2023-07-30T09:03:37.084875Z","shell.execute_reply.started":"2023-07-30T09:03:36.638899Z","shell.execute_reply":"2023-07-30T09:03:37.083883Z"},"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()","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:37.086401Z","iopub.execute_input":"2023-07-30T09:03:37.086969Z","iopub.status.idle":"2023-07-30T09:03:37.498405Z","shell.execute_reply.started":"2023-07-30T09:03:37.086934Z","shell.execute_reply":"2023-07-30T09:03:37.496727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.callbacks import EarlyStopping, ReduceLROnPlateau","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:37.504625Z","iopub.execute_input":"2023-07-30T09:03:37.505269Z","iopub.status.idle":"2023-07-30T09:03:37.512363Z","shell.execute_reply.started":"2023-07-30T09:03:37.505222Z","shell.execute_reply":"2023-07-30T09:03:37.510550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"earlystop = EarlyStopping(patience=10)","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:37.514784Z","iopub.execute_input":"2023-07-30T09:03:37.515294Z","iopub.status.idle":"2023-07-30T09:03:37.528250Z","shell.execute_reply.started":"2023-07-30T09:03:37.515250Z","shell.execute_reply":"2023-07-30T09:03:37.526569Z"},"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-30T09:03:37.529616Z","iopub.execute_input":"2023-07-30T09:03:37.530673Z","iopub.status.idle":"2023-07-30T09:03:37.540505Z","shell.execute_reply.started":"2023-07-30T09:03:37.530637Z","shell.execute_reply":"2023-07-30T09:03:37.539386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"callbacks = [earlystop, learning_rate_reduction]","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:37.542127Z","iopub.execute_input":"2023-07-30T09:03:37.542606Z","iopub.status.idle":"2023-07-30T09:03:37.554144Z","shell.execute_reply.started":"2023-07-30T09:03:37.542572Z","shell.execute_reply":"2023-07-30T09:03:37.552727Z"},"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()","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:37.556060Z","iopub.execute_input":"2023-07-30T09:03:37.556599Z","iopub.status.idle":"2023-07-30T09:03:37.831667Z","shell.execute_reply.started":"2023-07-30T09:03:37.556553Z","shell.execute_reply":"2023-07-30T09:03:37.830172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"validate_df['category'].value_counts().plot.bar()","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:37.833250Z","iopub.execute_input":"2023-07-30T09:03:37.833705Z","iopub.status.idle":"2023-07-30T09:03:38.087704Z","shell.execute_reply.started":"2023-07-30T09:03:37.833670Z","shell.execute_reply":"2023-07-30T09:03:38.086670Z"},"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","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:38.088791Z","iopub.execute_input":"2023-07-30T09:03:38.089139Z","iopub.status.idle":"2023-07-30T09:03:38.095825Z","shell.execute_reply.started":"2023-07-30T09:03:38.089108Z","shell.execute_reply":"2023-07-30T09:03:38.094548Z"},"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-30T09:03:38.097611Z","iopub.execute_input":"2023-07-30T09:03:38.098048Z","iopub.status.idle":"2023-07-30T09:03:38.391611Z","shell.execute_reply.started":"2023-07-30T09:03:38.098006Z","shell.execute_reply":"2023-07-30T09:03:38.390422Z"},"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)","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:03:59.957358Z","iopub.execute_input":"2023-07-30T09:03:59.957865Z","iopub.status.idle":"2023-07-30T09:04:00.046793Z","shell.execute_reply.started":"2023-07-30T09:03:59.957822Z","shell.execute_reply":"2023-07-30T09:04:00.045157Z"},"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-30T09:04:18.588170Z","iopub.execute_input":"2023-07-30T09:04:18.588592Z","iopub.status.idle":"2023-07-30T09:04:18.603068Z","shell.execute_reply.started":"2023-07-30T09:04:18.588562Z","shell.execute_reply":"2023-07-30T09:04:18.601737Z"},"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-30T09:04:32.980814Z","iopub.execute_input":"2023-07-30T09:04:32.981224Z","iopub.status.idle":"2023-07-30T09:04:35.996443Z","shell.execute_reply.started":"2023-07-30T09:04:32.981194Z","shell.execute_reply":"2023-07-30T09:04:35.995396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs=10 \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)","metadata":{"execution":{"iopub.status.busy":"2023-07-30T09:06:22.823196Z","iopub.execute_input":"2023-07-30T09:06:22.823680Z","iopub.status.idle":"2023-07-30T11:15:55.988752Z","shell.execute_reply.started":"2023-07-30T09:06:22.823645Z","shell.execute_reply":"2023-07-30T11:15:55.987271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save_weights(\"model.h5\")","metadata":{"execution":{"iopub.status.busy":"2023-07-30T11:17:20.554254Z","iopub.execute_input":"2023-07-30T11:17:20.554834Z","iopub.status.idle":"2023-07-30T11:17:20.726822Z","shell.execute_reply.started":"2023-07-30T11:17:20.554792Z","shell.execute_reply":"2023-07-30T11:17:20.725114Z"},"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-30T11:17:34.313366Z","iopub.execute_input":"2023-07-30T11:17:34.313833Z","iopub.status.idle":"2023-07-30T11:17:35.015401Z","shell.execute_reply.started":"2023-07-30T11:17:34.313801Z","shell.execute_reply":"2023-07-30T11:17:35.014095Z"},"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-30T11:18:07.073831Z","iopub.execute_input":"2023-07-30T11:18:07.074314Z","iopub.status.idle":"2023-07-30T11:18:07.095502Z","shell.execute_reply.started":"2023-07-30T11:18:07.074280Z","shell.execute_reply":"2023-07-30T11:18:07.094177Z"},"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-30T11:18:28.910761Z","iopub.execute_input":"2023-07-30T11:18:28.911239Z","iopub.status.idle":"2023-07-30T11:18:29.077887Z","shell.execute_reply.started":"2023-07-30T11:18:28.911206Z","shell.execute_reply":"2023-07-30T11:18:29.076313Z"},"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-30T11:18:47.100944Z","iopub.execute_input":"2023-07-30T11:18:47.101414Z","iopub.status.idle":"2023-07-30T11:20:10.079454Z","shell.execute_reply.started":"2023-07-30T11:18:47.101378Z","shell.execute_reply":"2023-07-30T11:20:10.077977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['category'] = np.argmax(predict, axis=-1)","metadata":{"execution":{"iopub.status.busy":"2023-07-30T11:20:59.839666Z","iopub.execute_input":"2023-07-30T11:20:59.840149Z","iopub.status.idle":"2023-07-30T11:20:59.848686Z","shell.execute_reply.started":"2023-07-30T11:20:59.840105Z","shell.execute_reply":"2023-07-30T11:20:59.847606Z"},"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-30T11:21:14.976511Z","iopub.execute_input":"2023-07-30T11:21:14.977006Z","iopub.status.idle":"2023-07-30T11:21:14.989858Z","shell.execute_reply.started":"2023-07-30T11:21:14.976973Z","shell.execute_reply":"2023-07-30T11:21:14.988167Z"},"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-30T11:21:26.923117Z","iopub.execute_input":"2023-07-30T11:21:26.923576Z","iopub.status.idle":"2023-07-30T11:21:26.942664Z","shell.execute_reply.started":"2023-07-30T11:21:26.923541Z","shell.execute_reply":"2023-07-30T11:21:26.940935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['category'].value_counts().plot.bar()","metadata":{"execution":{"iopub.status.busy":"2023-07-30T11:21:48.283756Z","iopub.execute_input":"2023-07-30T11:21:48.284279Z","iopub.status.idle":"2023-07-30T11:21:48.564169Z","shell.execute_reply.started":"2023-07-30T11:21:48.284238Z","shell.execute_reply":"2023-07-30T11:21:48.562861Z"},"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-30T11:23:01.581492Z","iopub.execute_input":"2023-07-30T11:23:01.582022Z","iopub.status.idle":"2023-07-30T11:23:07.166135Z","shell.execute_reply.started":"2023-07-30T11:23:01.581981Z","shell.execute_reply":"2023-07-30T11:23:07.163952Z"},"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-30T11:23:38.730293Z","iopub.execute_input":"2023-07-30T11:23:38.730986Z","iopub.status.idle":"2023-07-30T11:23:38.825506Z","shell.execute_reply.started":"2023-07-30T11:23:38.730926Z","shell.execute_reply":"2023-07-30T11:23:38.824296Z"},"trusted":true},"execution_count":null,"outputs":[]}]}