{"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-02-23T15:43:37.703321Z","iopub.execute_input":"2023-02-23T15:43:37.704250Z","iopub.status.idle":"2023-02-23T15:43:37.733299Z","shell.execute_reply.started":"2023-02-23T15:43:37.704164Z","shell.execute_reply":"2023-02-23T15:43:37.732365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\n\n!pip install py7zr\nfrom py7zr import unpack_7zarchive\n\nimport shutil\n\nimport re\n\nimport gc","metadata":{"execution":{"iopub.status.busy":"2023-02-23T15:43:37.734977Z","iopub.execute_input":"2023-02-23T15:43:37.735244Z","iopub.status.idle":"2023-02-23T15:43:58.354372Z","shell.execute_reply.started":"2023-02-23T15:43:37.735219Z","shell.execute_reply":"2023-02-23T15:43:58.352847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Input Data","metadata":{}},{"cell_type":"markdown","source":"## Extract images","metadata":{}},{"cell_type":"code","source":"shutil.register_unpack_format('7zip',['.7z'],unpack_7zarchive)\nshutil.unpack_archive('/kaggle/input/cifar-10/train.7z', '/kaggle/temp')","metadata":{"execution":{"iopub.status.busy":"2023-02-23T15:43:58.356415Z","iopub.execute_input":"2023-02-23T15:43:58.358131Z","iopub.status.idle":"2023-02-23T15:44:46.978995Z","shell.execute_reply.started":"2023-02-23T15:43:58.358085Z","shell.execute_reply":"2023-02-23T15:44:46.977735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Checking the structure of the input folder","metadata":{}},{"cell_type":"code","source":"for path, dirs, files in os.walk('/kaggle/temp/train'):\n    print('path: ',path,' len(dirs): ',len(dirs),' len(files): ',len(files))\n    \nprint(files[0])","metadata":{"execution":{"iopub.status.busy":"2023-02-23T15:44:46.981175Z","iopub.execute_input":"2023-02-23T15:44:46.981866Z","iopub.status.idle":"2023-02-23T15:44:47.063562Z","shell.execute_reply.started":"2023-02-23T15:44:46.981839Z","shell.execute_reply":"2023-02-23T15:44:47.062792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Sample an image","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nsample_img = tf.keras.preprocessing.image.load_img(os.path.join(path, files[0]))\ndisplay(sample_img)\nplt.imshow(sample_img)","metadata":{"execution":{"iopub.status.busy":"2023-02-23T15:44:47.064838Z","iopub.execute_input":"2023-02-23T15:44:47.065358Z","iopub.status.idle":"2023-02-23T15:44:48.179124Z","shell.execute_reply.started":"2023-02-23T15:44:47.065329Z","shell.execute_reply":"2023-02-23T15:44:48.178005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_img_array = tf.keras.preprocessing.image.img_to_array(sample_img)\nsample_img_array.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-23T15:44:48.180470Z","iopub.execute_input":"2023-02-23T15:44:48.180731Z","iopub.status.idle":"2023-02-23T15:44:48.191647Z","shell.execute_reply.started":"2023-02-23T15:44:48.180707Z","shell.execute_reply":"2023-02-23T15:44:48.190635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\nnp.set_printoptions(threshold=sys.maxsize, linewidth=1000)\nprint(sample_img_array.T)","metadata":{"execution":{"iopub.status.busy":"2023-02-23T15:44:48.193038Z","iopub.execute_input":"2023-02-23T15:44:48.193716Z","iopub.status.idle":"2023-02-23T15:44:48.235213Z","shell.execute_reply.started":"2023-02-23T15:44:48.193676Z","shell.execute_reply":"2023-02-23T15:44:48.233734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can see some patterns, although it is difficult to make out what they are.","metadata":{}},{"cell_type":"markdown","source":"## Prepare dataset","metadata":{}},{"cell_type":"code","source":"BATCH_SIZE = 32\ndef return_paths_ids(path, files):\n    '''\n    path: root path\n    files: image files\n    returns file_path_list(list), img_ids(numpy array)\n    '''\n    file_path_list = [os.path.join(path, fname) for fname in files]\n    img_ids = np.array([re.findall('(.*)\\.', fname) for fname in files]).astype(np.int32).reshape((-1,))\n    print('ids: ',len(img_ids))\n    return file_path_list, img_ids\n                       \ndef create_dataset(path=path, files=files, label_file_path=''):\n    ''' \n    path: root path\n    files: image files\n    label_file: csv file with ids and corresponding labels\n    returns(for training) dataset with images and corresponding labels,\n    returns(for prediction) image_array(numpy array) and image_id(numpy array) in this order\n    '''\n    \n    if label_file_path:\n        training_data = pd.read_csv(label_file_path)\n        training_data = training_data.assign(image= lambda x: x.astype('string').id+'.png')\n        training_data['image'] = training_data['image'].map(lambda x: tf.keras.preprocessing.image.img_to_array(tf.keras.preprocessing.image.load_img(os.path.join(path, x))))\n        return training_data[['image','label']]\n    \n    file_path_list, img_ids = return_paths_ids(path=path,files=files)\n    image_array = np.array([tf.keras.preprocessing.image.img_to_array(tf.keras.preprocessing.image.load_img(file_path)) for file_path in file_path_list])\n    print('image_array.shape: ',image_array.shape)\n    return image_array, img_ids\ntraining_dataset = create_dataset(label_file_path='/kaggle/input/cifar-10/trainLabels.csv')\ntraining_dataset.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-23T15:46:27.255749Z","iopub.execute_input":"2023-02-23T15:46:27.256602Z","iopub.status.idle":"2023-02-23T15:46:42.483102Z","shell.execute_reply.started":"2023-02-23T15:46:27.256566Z","shell.execute_reply":"2023-02-23T15:46:42.482102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Replace labels with numbers","metadata":{}},{"cell_type":"code","source":"LABEL_MAP = tuple(training_dataset['label'].unique())\nprint('LABEL_MAP: ',LABEL_MAP)\ntraining_dataset['label'] = training_dataset['label'].map(lambda label: LABEL_MAP.index(label))\ntraining_dataset.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-23T15:45:03.232504Z","iopub.execute_input":"2023-02-23T15:45:03.232984Z","iopub.status.idle":"2023-02-23T15:45:04.682973Z","shell.execute_reply.started":"2023-02-23T15:45:03.232913Z","shell.execute_reply":"2023-02-23T15:45:04.681949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Check if the dataframe is correctly formed","metadata":{}},{"cell_type":"code","source":"print('shape: ',training_dataset['image'].values.shape)\nprint('shape: ',np.array(training_dataset['image'].values.tolist()).reshape(50000, 32,32,3).shape)\nfor i, row in training_dataset.head(3).iterrows():\n#     print('type: ',type(row['image']))\n    sample_image = tf.keras.preprocessing.image.array_to_img(row['image'])\n    display(sample_image)\n    plt.imshow(sample_image)\n    plt.show()\n    print('label: ',row['label'])\n    print('label_map: ',LABEL_MAP[row['label']])","metadata":{"execution":{"iopub.status.busy":"2023-02-23T15:45:20.687118Z","iopub.execute_input":"2023-02-23T15:45:20.687500Z","iopub.status.idle":"2023-02-23T15:45:21.504630Z","shell.execute_reply.started":"2023-02-23T15:45:20.687473Z","shell.execute_reply":"2023-02-23T15:45:21.503983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Checking the balance of the dataset","metadata":{}},{"cell_type":"code","source":"import seaborn as sns\n\nsns.countplot(training_dataset['label'])","metadata":{"execution":{"iopub.status.busy":"2023-02-23T15:37:25.111613Z","iopub.execute_input":"2023-02-23T15:37:25.112117Z","iopub.status.idle":"2023-02-23T15:37:25.756605Z","shell.execute_reply.started":"2023-02-23T15:37:25.112079Z","shell.execute_reply":"2023-02-23T15:37:25.755462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Split training and validation data","metadata":{}},{"cell_type":"code","source":"training_dataset = training_dataset.sample(frac=1)\nvalidation_dataset = training_dataset.iloc[int(len(training_dataset) * 0.8):]\ntraining_dataset = training_dataset.iloc[:int(len(training_dataset) * 0.8)]\nprint('validation: ',validation_dataset.shape)\nprint('training: ',training_dataset.shape)","metadata":{"execution":{"iopub.status.busy":"2023-02-22T20:52:34.203135Z","iopub.execute_input":"2023-02-22T20:52:34.205624Z","iopub.status.idle":"2023-02-22T20:52:34.224414Z","shell.execute_reply.started":"2023-02-22T20:52:34.205586Z","shell.execute_reply":"2023-02-22T20:52:34.223531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nx_train = np.array(training_dataset['image'].values.tolist())\ny_train = np.array(training_dataset['label'].values.tolist()).reshape((-1, 1)).astype(int)\nx_val = np.array(validation_dataset['image'].values.tolist())\ny_val = np.array(validation_dataset['label'].values.tolist()).reshape((-1, 1)).astype(int)\nprint('train images: ',x_train.shape)\nprint('train labels: ',y_train.shape)\nprint('val images: ',x_val.shape)\nprint('val labels: ',y_val.shape)","metadata":{"execution":{"iopub.status.busy":"2023-02-22T20:52:34.228584Z","iopub.execute_input":"2023-02-22T20:52:34.230814Z","iopub.status.idle":"2023-02-22T20:52:34.533355Z","shell.execute_reply.started":"2023-02-22T20:52:34.230778Z","shell.execute_reply":"2023-02-22T20:52:34.532382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Training\n","metadata":{}},{"cell_type":"markdown","source":"## Callback","metadata":{}},{"cell_type":"code","source":"class CallBack1(tf.keras.callbacks.Callback):\n    def on_epoch_end(self, epoch, logs):\n        if logs.get('val_accuracy') and logs.get('accuracy'):\n            if logs.get('val_accuracy') - logs.get('accuracy') < -4:\n                print('Whoa! That looks like overfitting, let\\'s stop training now...')\n                self.model.stop_training = True\n            \ncallback = CallBack1()","metadata":{"execution":{"iopub.status.busy":"2023-02-22T20:52:34.537672Z","iopub.execute_input":"2023-02-22T20:52:34.539867Z","iopub.status.idle":"2023-02-22T20:52:34.547846Z","shell.execute_reply.started":"2023-02-22T20:52:34.539828Z","shell.execute_reply":"2023-02-22T20:52:34.546933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def conv(inputs, n_filters, filter_size, dropout_prob=0, conv_padding='valid', pool_padding='valid', pool_strides=1, max_pool=False, depthwise=False, batch_norm=True, activation=True, training=True):\n    if depthwise:\n        conv_output = tf.keras.layers.DepthwiseConv2D(kernel_size=filter_size, padding=conv_padding)(inputs)\n    else:\n        conv_output = tf.keras.layers.Conv2D(n_filters, kernel_size=filter_size, padding=conv_padding)(inputs)\n    \n    if batch_norm:\n        conv_output = tf.keras.layers.BatchNormalization(axis=3)(conv_output, training=training)\n        \n    conv_output = tf.keras.layers.Dropout(dropout_prob)(conv_output)\n    if activation:\n        conv_output = tf.keras.layers.Activation('relu')(conv_output)\n    \n    if max_pool and filter_size > 1:\n        conv_output = tf.keras.layers.MaxPooling2D(strides = pool_strides, padding=pool_padding)(dropout)\n    \n    return conv_output","metadata":{"execution":{"iopub.status.busy":"2023-02-22T20:52:34.552107Z","iopub.execute_input":"2023-02-22T20:52:34.554653Z","iopub.status.idle":"2023-02-22T20:52:34.565356Z","shell.execute_reply.started":"2023-02-22T20:52:34.554616Z","shell.execute_reply":"2023-02-22T20:52:34.564472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Augmentation\nAugmenting images can prevent overfitting, as can be seen in results.","metadata":{}},{"cell_type":"code","source":"def augment(inputs):\n    '''\n    Image augmentation layers\n    '''\n    print('entered aug')\n    print('aug_inputs: ',inputs.shape)\n    aug_output = tf.keras.layers.Rescaling(1/255)(inputs)\n    print('aug_output1: ',aug_output.shape)\n    aug_output = tf.keras.layers.Resizing(32, 32)(aug_output)\n    print('aug_output2: ',aug_output.shape)\n    aug_output = tf.keras.layers.RandomFlip()(aug_output)\n    print('aug_output3: ',aug_output.shape)\n    aug_output = tf.keras.layers.RandomRotation(0.2)(aug_output)\n    print('aug_output4: ',aug_output.shape)\n    aug_output = tf.keras.layers.RandomZoom(0.2,0.2)(aug_output)\n    print('aug_output5: ',aug_output.shape)\n    return aug_output","metadata":{"execution":{"iopub.status.busy":"2023-02-22T20:52:34.592019Z","iopub.execute_input":"2023-02-22T20:52:34.592470Z","iopub.status.idle":"2023-02-22T20:52:34.606751Z","shell.execute_reply.started":"2023-02-22T20:52:34.592430Z","shell.execute_reply":"2023-02-22T20:52:34.605676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Network with residual blocks","metadata":{}},{"cell_type":"code","source":"def res_block(inputs, n_filters, filter_size, dropout_prob=0, conv_padding='same', pool_padding='same', pool_strides=1, max_pool=False, depthwise=False, training=True):\n    '''\n    Residual block that uses skip connections to add output of one layer to another farther away from it.\n    '''\n    print('inputs: ',inputs.shape)\n    res_output = conv(inputs, n_filters, filter_size, conv_padding=conv_padding, dropout_prob=dropout_prob)\n    print('res_output1: ',res_output.shape)\n    shortcut = res_output\n    print('shortcut: ',shortcut.shape)\n    res_output = conv(res_output, n_filters, filter_size, conv_padding=conv_padding, dropout_prob=dropout_prob)\n    print('res_output2: ',res_output.shape)\n        \n    res_output = conv(res_output, n_filters, filter_size, conv_padding=conv_padding, activation=False)\n    print('res_output3: ',res_output.shape)\n    res_output = tf.keras.layers.Add()([res_output, shortcut])\n    print('res_output4: ', res_output.shape)\n    res_output = tf.keras.layers.Activation('relu')(res_output)\n    print('res_output5: ',res_output.shape)\n    \n    if max_pool and filter_size > 1:\n        res_output = tf.keras.layers.MaxPooling2D(strides = pool_strides, padding=pool_padding)(res_output)\n    \n    return res_output","metadata":{"execution":{"iopub.status.busy":"2023-02-22T20:52:34.610342Z","iopub.execute_input":"2023-02-22T20:52:34.611266Z","iopub.status.idle":"2023-02-22T20:52:34.624721Z","shell.execute_reply.started":"2023-02-22T20:52:34.611221Z","shell.execute_reply":"2023-02-22T20:52:34.623898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def res_model(n_filters=128, filter_size=3):\n    '''\n    Network built with residual blocks.\n    '''\n    inputs = tf.keras.Input(shape=(32, 32, 3))\n    inputs2 = augment(inputs)\n    res_model_output = res_block(inputs2, n_filters, filter_size=filter_size)\n    res_model_output = res_block(res_model_output, n_filters*2, filter_size=filter_size+2, dropout_prob=0.2)\n    res_model_output = tf.keras.layers.Flatten()(res_model_output)\n    res_model_output = tf.keras.layers.Dense(128, activation='relu')(res_model_output)\n    res_model_output = tf.keras.layers.Dense(128, activation='relu')(res_model_output)\n    res_model_output = tf.keras.layers.Dense(10, activation='softmax')(res_model_output)\n    model = tf.keras.Model(inputs=inputs, outputs=res_model_output)\n    print(model.summary())\n    return model","metadata":{"execution":{"iopub.status.busy":"2023-02-22T20:52:34.626178Z","iopub.execute_input":"2023-02-22T20:52:34.631964Z","iopub.status.idle":"2023-02-22T20:52:34.644194Z","shell.execute_reply.started":"2023-02-22T20:52:34.631926Z","shell.execute_reply":"2023-02-22T20:52:34.643325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = res_model()\nmodel.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\nhistory = model.fit(x_train, y_train, validation_data=(x_val, y_val), batch_size=32, epochs=55, callbacks=[callback])","metadata":{"execution":{"iopub.status.busy":"2023-02-22T20:53:09.273695Z","iopub.execute_input":"2023-02-22T20:53:09.274103Z","iopub.status.idle":"2023-02-22T21:51:55.902521Z","shell.execute_reply.started":"2023-02-22T20:53:09.274071Z","shell.execute_reply":"2023-02-22T21:51:55.901531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Result:\n<br>Without residual blocks(plain network): training accuracy around 0.1 indicating high bias\n<br>Without image augmentation: Overfitting at around epoch 7, training accuracy:0.7 and validation-accuracy:0.67\n<br>With image augmentation: At epoch 55, training accuracy is around 0.74 and validation accuracy is around 0.73**","metadata":{}},{"cell_type":"markdown","source":"# Plot Accuracy","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.plot(history.history['accuracy'], label='training accuracy')\nplt.plot(history.history['val_accuracy'], label='validation accuracy')\nplt.title('accuracy')\nplt.legend()\nplt.show()\nplt.plot(history.history['loss'], label='training loss')\nplt.plot(history.history['val_loss'], label='validation loss')\nplt.title('loss')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-22T21:51:55.904897Z","iopub.execute_input":"2023-02-22T21:51:55.905583Z","iopub.status.idle":"2023-02-22T21:51:56.293461Z","shell.execute_reply.started":"2023-02-22T21:51:55.905541Z","shell.execute_reply":"2023-02-22T21:51:56.292423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Testing","metadata":{}},{"cell_type":"code","source":"shutil.unpack_archive('/kaggle/input/cifar-10/test.7z', '/kaggle/temp')","metadata":{"execution":{"iopub.status.busy":"2023-02-22T21:51:56.294748Z","iopub.execute_input":"2023-02-22T21:51:56.295103Z","iopub.status.idle":"2023-02-22T22:05:58.293258Z","shell.execute_reply.started":"2023-02-22T21:51:56.295067Z","shell.execute_reply":"2023-02-22T22:05:58.292082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Check the structure of the test folder","metadata":{}},{"cell_type":"code","source":"for path, dirs, files in os.walk('/kaggle/temp/test'):\n    print('path: ',path,' len(dirs): ',len(dirs),' len(files): ',len(files))\n\nprint(files[0])","metadata":{"execution":{"iopub.status.busy":"2023-02-22T22:05:58.295874Z","iopub.execute_input":"2023-02-22T22:05:58.296285Z","iopub.status.idle":"2023-02-22T22:05:58.708521Z","shell.execute_reply.started":"2023-02-22T22:05:58.296241Z","shell.execute_reply":"2023-02-22T22:05:58.707420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Create test dataset","metadata":{}},{"cell_type":"code","source":"gc.collect()\nimage_array, img_ids = create_dataset(path=path,files=files)","metadata":{"execution":{"iopub.status.busy":"2023-02-22T22:05:58.710069Z","iopub.execute_input":"2023-02-22T22:05:58.710463Z","iopub.status.idle":"2023-02-22T22:07:31.503320Z","shell.execute_reply.started":"2023-02-22T22:05:58.710424Z","shell.execute_reply":"2023-02-22T22:07:31.502261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model = tf.keras.models.load_model('/kaggle/working/')\npredictions = model.predict(image_array, batch_size=32)","metadata":{"execution":{"iopub.status.busy":"2023-02-22T22:07:31.508547Z","iopub.execute_input":"2023-02-22T22:07:31.510294Z","iopub.status.idle":"2023-02-22T22:09:55.857590Z","shell.execute_reply.started":"2023-02-22T22:07:31.510253Z","shell.execute_reply":"2023-02-22T22:09:55.856468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('shape: ',predictions.shape)\nprint('sample: ',predictions[:3])\nprint('max: ',tf.math.argmax(predictions[:3]))\npredictions = [LABEL_MAP[int(tf.math.argmax(p))] for p in predictions]\npredictions = pd.DataFrame(zip(img_ids, predictions), columns=['id','label'])","metadata":{"execution":{"iopub.status.busy":"2023-02-22T22:09:55.859686Z","iopub.execute_input":"2023-02-22T22:09:55.860092Z","iopub.status.idle":"2023-02-22T22:11:03.911285Z","shell.execute_reply.started":"2023-02-22T22:09:55.860053Z","shell.execute_reply":"2023-02-22T22:11:03.910193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Output\n## Check the output","metadata":{}},{"cell_type":"code","source":"for i, row in predictions.head().iterrows():\n    sample_image = tf.keras.preprocessing.image.load_img(os.path.join(path,row.astype('string').id+'.png'))\n    display(sample_image)\n    plt.imshow(sample_image)\n    plt.show()\n    print('id: ', row['id'])\n    print('label: ',row['label'])","metadata":{"execution":{"iopub.status.busy":"2023-02-22T22:11:03.912632Z","iopub.execute_input":"2023-02-22T22:11:03.913014Z","iopub.status.idle":"2023-02-22T22:11:03.964270Z","shell.execute_reply.started":"2023-02-22T22:11:03.912977Z","shell.execute_reply":"2023-02-22T22:11:03.963283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Submit","metadata":{}},{"cell_type":"code","source":"predictions.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-22T22:11:03.965846Z","iopub.execute_input":"2023-02-22T22:11:03.966200Z","iopub.status.idle":"2023-02-22T22:11:03.977646Z","shell.execute_reply.started":"2023-02-22T22:11:03.966164Z","shell.execute_reply":"2023-02-22T22:11:03.976678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions.to_csv('/kaggle/working/submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-02-22T22:11:03.980570Z","iopub.execute_input":"2023-02-22T22:11:03.981204Z","iopub.status.idle":"2023-02-22T22:11:04.256207Z","shell.execute_reply.started":"2023-02-22T22:11:03.981164Z","shell.execute_reply":"2023-02-22T22:11:04.254971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}