{"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":"!pip --quiet install efficientnet -q","metadata":{"papermill":{"duration":9.65023,"end_time":"2021-09-05T12:40:56.869917","exception":false,"start_time":"2021-09-05T12:40:47.219687","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:16.417437Z","iopub.execute_input":"2022-12-16T01:35:16.417999Z","iopub.status.idle":"2022-12-16T01:35:26.580573Z","shell.execute_reply.started":"2022-12-16T01:35:16.417935Z","shell.execute_reply":"2022-12-16T01:35:26.579368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nfrom kaggle_datasets import KaggleDatasets\nfrom sklearn.metrics import classification_report\nfrom sklearn.model_selection import train_test_split\nimport tensorflow as tf\nimport efficientnet.tfkeras as efn\nfrom tensorflow.keras.models import Model\nfrom tensorflow.keras.applications import VGG19,ResNet50,Xception,InceptionResNetV2,InceptionV3,ResNet152V2\nfrom sklearn.preprocessing import LabelEncoder\nimport cv2,random,math,warnings\nimport matplotlib.pyplot as plt\nimport tensorflow_hub as hub\nimport tensorflow_addons as tfa\nimport tensorflow.keras.backend as K\nimport random,glob\nwarnings.filterwarnings('ignore')","metadata":{"id":"mEEdv_6ThCKp","papermill":{"duration":8.214365,"end_time":"2021-09-05T12:41:05.102040","exception":false,"start_time":"2021-09-05T12:40:56.887675","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:26.587079Z","iopub.execute_input":"2022-12-16T01:35:26.587327Z","iopub.status.idle":"2022-12-16T01:35:34.258389Z","shell.execute_reply.started":"2022-12-16T01:35:26.587295Z","shell.execute_reply":"2022-12-16T01:35:34.257465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def seed_everything(seed=0):\n    random.seed(seed)\n    np.random.seed(seed)\n    tf.random.set_seed(seed)\n    os.environ['PYTHONHASHSEED'] = str(seed)\n    os.environ['TF_DETERMINISTIC_OPS'] = '1'\n\nseed = 42\n#seed_everything(seed)","metadata":{"papermill":{"duration":0.024678,"end_time":"2021-09-05T12:41:05.143286","exception":false,"start_time":"2021-09-05T12:41:05.118608","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:34.259637Z","iopub.execute_input":"2022-12-16T01:35:34.260512Z","iopub.status.idle":"2022-12-16T01:35:34.265425Z","shell.execute_reply.started":"2022-12-16T01:35:34.260477Z","shell.execute_reply":"2022-12-16T01:35:34.264870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('../input/datathonindoml-2022/train_labels.csv')\ntest = pd.read_csv('../input/datathonindoml-2022/sample_submission.csv')\ntrain.head()","metadata":{"id":"AMxVdwcOinrc","outputId":"45562ade-5bcf-44d8-a6b8-36fc7e9ed55e","papermill":{"duration":0.09516,"end_time":"2021-09-05T12:41:05.254312","exception":false,"start_time":"2021-09-05T12:41:05.159152","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:34.267447Z","iopub.execute_input":"2022-12-16T01:35:34.268299Z","iopub.status.idle":"2022-12-16T01:35:34.327603Z","shell.execute_reply.started":"2022-12-16T01:35:34.268266Z","shell.execute_reply":"2022-12-16T01:35:34.326779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape, test.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-16T01:35:34.329069Z","iopub.execute_input":"2022-12-16T01:35:34.329317Z","iopub.status.idle":"2022-12-16T01:35:34.337721Z","shell.execute_reply.started":"2022-12-16T01:35:34.329290Z","shell.execute_reply":"2022-12-16T01:35:34.336767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def give_path(row, test=False):\n    if test:\n        return '../input/indoml-t-dataset/test/' + row + '.jpeg'\n    return '../input/indoml-t-dataset/train/' + row + '.jpeg'","metadata":{"id":"PSLvRiC3itTy","outputId":"0c23727a-030b-4fef-80c9-67569dfacc91","papermill":{"duration":0.024082,"end_time":"2021-09-05T12:41:05.294816","exception":false,"start_time":"2021-09-05T12:41:05.270734","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:34.339278Z","iopub.execute_input":"2022-12-16T01:35:34.340075Z","iopub.status.idle":"2022-12-16T01:35:34.344508Z","shell.execute_reply.started":"2022-12-16T01:35:34.340040Z","shell.execute_reply":"2022-12-16T01:35:34.343752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['file_path'] = train['id'].apply(lambda x : give_path(str(x)))\ntest['file_path'] = test['id'].apply(lambda x : give_path(str(x), True))","metadata":{"execution":{"iopub.status.busy":"2022-12-16T01:35:34.346113Z","iopub.execute_input":"2022-12-16T01:35:34.346395Z","iopub.status.idle":"2022-12-16T01:35:34.372100Z","shell.execute_reply.started":"2022-12-16T01:35:34.346366Z","shell.execute_reply":"2022-12-16T01:35:34.371293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T01:35:34.373218Z","iopub.execute_input":"2022-12-16T01:35:34.373480Z","iopub.status.idle":"2022-12-16T01:35:34.389028Z","shell.execute_reply.started":"2022-12-16T01:35:34.373453Z","shell.execute_reply":"2022-12-16T01:35:34.388036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def auto_select_accelerator():\n    \"\"\"\n    Reference: \n        * https://www.kaggle.com/mgornergoogle/getting-started-with-100-flowers-on-tpu\n        * https://www.kaggle.com/xhlulu/ranzcr-efficientnet-tpu-training\n    \"\"\"\n    try:\n        tpu = tf.distribute.cluster_resolver.TPUClusterResolver()\n        tf.config.experimental_connect_to_cluster(tpu)\n        tf.tpu.experimental.initialize_tpu_system(tpu)\n        strategy = tf.distribute.experimental.TPUStrategy(tpu)\n        print(\"Running on TPU:\", tpu.master())\n    except ValueError:\n        strategy = tf.distribute.get_strategy()\n    print(f\"Running on {strategy.num_replicas_in_sync} replicas\")\n    \n    return strategy\n\n\ndef build_decoder(with_labels=True, target_size=(256, 256), ext='png'):\n    def decode(path):\n        file_bytes = tf.io.read_file(path)\n        if ext == 'png':\n            img = tf.image.decode_png(file_bytes, channels=3)\n        elif ext in ['jpg', 'jpeg']:\n            img = tf.image.decode_jpeg(file_bytes, channels=3)\n        else:\n            raise ValueError(\"Image extension not supported\")\n\n        img = tf.cast(img, tf.float32) / 255.0\n        img = tf.image.resize(img, target_size)\n        return img\n    \n    def decode_with_labels(path, label):\n        return decode(path), label\n    \n    return decode_with_labels if with_labels else decode\n\n\ndef build_augmenter(with_labels=True):\n    def augment(image):\n        image = tf.image.random_flip_left_right(image)\n        image = tf.image.random_flip_up_down(image)\n        image = tf.image.random_brightness(image, max_delta = 0.1)\n#         image = tf.image.random_saturation(image, lower = 0.75, upper = 1.5)\n#         image = tf.image.random_hue(image, max_delta = 0.15)\n#         image = tf.image.random_contrast(image, lower = 0.75, upper = 1.5)\n        image = tf.image.rot90(image)\n        image = tf.image.transpose(image)\n        \n        return image\n    \n    def augment_with_labels(img, label):\n        return augment(img), label\n    \n    return augment_with_labels if with_labels else augment\n\n\ndef build_dataset(paths, labels=None, bsize=32, cache=True,\n                  decode_fn=None, augment_fn=None,\n                  augment=True, repeat=True, shuffle=1024, \n                  cache_dir=\"\"):\n    if cache_dir != \"\" and cache is True:\n        os.makedirs(cache_dir, exist_ok=True)\n    \n    if decode_fn is None:\n        decode_fn = build_decoder(labels is not None)\n    \n    if augment_fn is None:\n        augment_fn = build_augmenter(labels is not None)\n    \n    AUTO = tf.data.experimental.AUTOTUNE\n    slices = paths if labels is None else (paths, labels)\n    \n    dset = tf.data.Dataset.from_tensor_slices(slices)\n    dset = dset.map(decode_fn, num_parallel_calls=AUTO)\n    dset = dset.cache(cache_dir) if cache else dset\n    dset = dset.map(augment_fn, num_parallel_calls=AUTO) if augment else dset\n    dset = dset.repeat() if repeat else dset\n    dset = dset.shuffle(shuffle) if shuffle else dset\n    dset = dset.batch(bsize).prefetch(AUTO)\n    \n    return dset","metadata":{"papermill":{"duration":0.041531,"end_time":"2021-09-05T12:41:05.402679","exception":false,"start_time":"2021-09-05T12:41:05.361148","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:34.390447Z","iopub.execute_input":"2022-12-16T01:35:34.390720Z","iopub.status.idle":"2022-12-16T01:35:34.586074Z","shell.execute_reply.started":"2022-12-16T01:35:34.390680Z","shell.execute_reply":"2022-12-16T01:35:34.585063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"COMPETITION_NAME = \"indoml-t-dataset\"\nstrategy = auto_select_accelerator()\nBATCH_SIZE = strategy.num_replicas_in_sync * 8\nGCS_DS_PATH = KaggleDatasets().get_gcs_path(COMPETITION_NAME)","metadata":{"papermill":{"duration":6.451786,"end_time":"2021-09-05T12:41:11.870829","exception":false,"start_time":"2021-09-05T12:41:05.419043","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:34.587493Z","iopub.execute_input":"2022-12-16T01:35:34.587858Z","iopub.status.idle":"2022-12-16T01:35:41.338811Z","shell.execute_reply.started":"2022-12-16T01:35:34.587812Z","shell.execute_reply":"2022-12-16T01:35:41.337514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"paths = []\nlabels = []\nfor i in range(len(train['file_path'].values)):\n    name = train['id'].values[i]\n    label = train['label'].values[i]\n    paths.append(GCS_DS_PATH + '/train/' + str(name) + '.jpeg')\n    labels.append(label)","metadata":{"papermill":{"duration":0.094764,"end_time":"2021-09-05T12:41:11.983421","exception":false,"start_time":"2021-09-05T12:41:11.888657","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:41.340451Z","iopub.execute_input":"2022-12-16T01:35:41.340787Z","iopub.status.idle":"2022-12-16T01:35:41.508043Z","shell.execute_reply.started":"2022-12-16T01:35:41.340750Z","shell.execute_reply":"2022-12-16T01:35:41.507264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"one_hot = True\nif one_hot:\n    labels = tf.keras.utils.to_categorical(labels , num_classes = 16)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T01:35:41.509232Z","iopub.execute_input":"2022-12-16T01:35:41.509496Z","iopub.status.idle":"2022-12-16T01:35:41.518003Z","shell.execute_reply.started":"2022-12-16T01:35:41.509460Z","shell.execute_reply":"2022-12-16T01:35:41.517092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(paths) , len(labels)","metadata":{"papermill":{"duration":0.028465,"end_time":"2021-09-05T12:41:12.028911","exception":false,"start_time":"2021-09-05T12:41:12.000446","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:41.521782Z","iopub.execute_input":"2022-12-16T01:35:41.522035Z","iopub.status.idle":"2022-12-16T01:35:41.529071Z","shell.execute_reply.started":"2022-12-16T01:35:41.522008Z","shell.execute_reply":"2022-12-16T01:35:41.528143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_paths,valid_paths,train_labels,valid_labels = train_test_split(paths , labels , stratify = labels , test_size = 0.1 , random_state = 42)","metadata":{"papermill":{"duration":0.040492,"end_time":"2021-09-05T12:41:12.087240","exception":false,"start_time":"2021-09-05T12:41:12.046748","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:41.530454Z","iopub.execute_input":"2022-12-16T01:35:41.530786Z","iopub.status.idle":"2022-12-16T01:35:41.797409Z","shell.execute_reply.started":"2022-12-16T01:35:41.530754Z","shell.execute_reply":"2022-12-16T01:35:41.796355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T01:35:41.798796Z","iopub.execute_input":"2022-12-16T01:35:41.799042Z","iopub.status.idle":"2022-12-16T01:35:41.809477Z","shell.execute_reply.started":"2022-12-16T01:35:41.799014Z","shell.execute_reply":"2022-12-16T01:35:41.808512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = os.listdir('../input/indoml-t-dataset/test/')\ntest_paths = []\nfor i in range(len(temp)):\n    name = temp[i]\n    test_paths.append(GCS_DS_PATH + '/test/' + str(name))","metadata":{"papermill":{"duration":0.042934,"end_time":"2021-09-05T12:41:12.148389","exception":false,"start_time":"2021-09-05T12:41:12.105455","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:41.811103Z","iopub.execute_input":"2022-12-16T01:35:41.811438Z","iopub.status.idle":"2022-12-16T01:35:42.085388Z","shell.execute_reply.started":"2022-12-16T01:35:41.811371Z","shell.execute_reply":"2022-12-16T01:35:42.084439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Build the tensorflow datasets\nIMSIZES = (224, 240, 260, 300, 380, 456, 512, 600)\nim_size = 1024\n\ndecoder = build_decoder(with_labels=True, target_size=(im_size, im_size))\ntest_decoder = build_decoder(with_labels=False, target_size=(im_size, im_size))\n\ntrain_dataset = build_dataset(\n    train_paths, train_labels, bsize=BATCH_SIZE, decode_fn=decoder\n)\n\nvalid_dataset = build_dataset(\n    valid_paths, valid_labels, bsize=BATCH_SIZE, decode_fn=decoder,\n    repeat=False, shuffle=False, augment=False\n)\n\ntest_decoder = build_decoder(with_labels=False, target_size=(im_size, im_size))\ndtest = build_dataset(\n    test_paths, bsize=BATCH_SIZE, repeat=False, \n    shuffle=False, augment=False, cache=False,\n    decode_fn=test_decoder\n)","metadata":{"papermill":{"duration":0.535596,"end_time":"2021-09-05T12:41:12.702842","exception":false,"start_time":"2021-09-05T12:41:12.167246","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:42.088612Z","iopub.execute_input":"2022-12-16T01:35:42.088905Z","iopub.status.idle":"2022-12-16T01:35:42.517416Z","shell.execute_reply.started":"2022-12-16T01:35:42.088867Z","shell.execute_reply":"2022-12-16T01:35:42.516755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_model(name):\n    if name == 'effnetb0':\n        with strategy.scope():\n            base_model = efn.EfficientNetB0(input_shape=(im_size, im_size, 3), weights='noisy-student', include_top = False)\n    elif name == 'effnetb1':\n        with strategy.scope():\n            base_model = efn.EfficientNetB1(input_shape=(im_size, im_size, 3), weights='noisy-student', include_top = False)\n    elif name == 'effnetb2':\n        with strategy.scope():\n            base_model = efn.EfficientNetB2(input_shape=(im_size, im_size, 3), weights='noisy-student', include_top = False)\n    elif name == 'effnetb3':\n        with strategy.scope():\n            base_model = efn.EfficientNetB3(input_shape=(im_size, im_size, 3), weights='noisy-student', include_top = False)\n    elif name == 'effnetb4':\n        with strategy.scope():\n            base_model = efn.EfficientNetB4(input_shape=(im_size, im_size, 3), weights='noisy-student', include_top = False)\n    elif name == 'effnetb5':\n        with strategy.scope():\n            base_model = efn.EfficientNetB5(input_shape=(im_size, im_size, 3), weights='noisy-student', include_top = False)\n    elif name == 'effnetb6':\n        with strategy.scope():\n            base_model = efn.EfficientNetB6(input_shape=(im_size, im_size, 3), weights='noisy-student', include_top = False)\n    elif name == 'effnetb7':\n        with strategy.scope():\n            base_model = efn.EfficientNetB7(input_shape=(im_size, im_size, 3), weights='noisy-student', include_top = False)\n    elif name == 'resnet':\n        with strategy.scope():\n            base_model = ResNet50(input_shape=(im_size, im_size, 3), weights='imagenet', include_top = False)\n    elif name == 'xception':\n        with strategy.scope():\n            base_model = Xception(input_shape=(im_size, im_size, 3), weights='imagenet', include_top = False)\n    elif name == 'inception':\n        with strategy.scope():\n            base_model = InceptionV3(input_shape=(im_size, im_size, 3), weights='imagenet', include_top = False)\n    elif name == 'inceptionresnet':\n        with strategy.scope():\n            base_model = InceptionResNetV2(input_shape=(im_size, im_size, 3), weights='imagenet', include_top = False)\n        \n    with strategy.scope():\n        model = tf.keras.Sequential([\n            base_model,\n            tf.keras.layers.GlobalAveragePooling2D(),\n            tf.keras.layers.Dense(16, activation='softmax')\n        ])\n        model.compile(\n            optimizer=tf.keras.optimizers.Adam(lr = 1e-4),\n            loss= tf.keras.losses.CategoricalCrossentropy(label_smoothing = 0.001) , #'sparse_categorical_crossentropy',\n            metrics=[\"accuracy\"])\n    return model","metadata":{"papermill":{"duration":0.038444,"end_time":"2021-09-05T12:41:12.759536","exception":false,"start_time":"2021-09-05T12:41:12.721092","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:42.519019Z","iopub.execute_input":"2022-12-16T01:35:42.519350Z","iopub.status.idle":"2022-12-16T01:35:42.536936Z","shell.execute_reply.started":"2022-12-16T01:35:42.519307Z","shell.execute_reply":"2022-12-16T01:35:42.535844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_name = \"inceptionresnet\"\nmodel = get_model(model_name)\nmodel.summary()","metadata":{"papermill":{"duration":19.86136,"end_time":"2021-09-05T12:41:32.639323","exception":false,"start_time":"2021-09-05T12:41:12.777963","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:35:42.538265Z","iopub.execute_input":"2022-12-16T01:35:42.538536Z","iopub.status.idle":"2022-12-16T01:36:20.137123Z","shell.execute_reply.started":"2022-12-16T01:35:42.538505Z","shell.execute_reply":"2022-12-16T01:36:20.136315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_paths = np.array(train_paths)\nsteps_per_epoch = train_paths.shape[0] // BATCH_SIZE\ncheckpoint = tf.keras.callbacks.ModelCheckpoint(\n    f'{model_name}.h5', save_best_only=True, monitor='val_loss', mode='min')\nlr_reducer = tf.keras.callbacks.ReduceLROnPlateau(\n    monitor=\"val_loss\", patience = 3, min_lr = 1e-7, mode='min')","metadata":{"papermill":{"duration":0.034563,"end_time":"2021-09-05T12:41:32.695000","exception":false,"start_time":"2021-09-05T12:41:32.660437","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:36:20.138276Z","iopub.execute_input":"2022-12-16T01:36:20.138529Z","iopub.status.idle":"2022-12-16T01:36:20.149267Z","shell.execute_reply.started":"2022-12-16T01:36:20.138499Z","shell.execute_reply":"2022-12-16T01:36:20.148325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    train_dataset,\n    epochs = 20,\n    verbose = 1,\n    callbacks=[checkpoint, lr_reducer],\n    steps_per_epoch=steps_per_epoch,\n    validation_data=valid_dataset)","metadata":{"papermill":{"duration":553.063433,"end_time":"2021-09-05T12:50:45.779684","exception":false,"start_time":"2021-09-05T12:41:32.716251","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T01:36:20.150540Z","iopub.execute_input":"2022-12-16T01:36:20.150815Z","iopub.status.idle":"2022-12-16T02:31:19.515978Z","shell.execute_reply.started":"2022-12-16T01:36:20.150787Z","shell.execute_reply":"2022-12-16T02:31:19.514233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.load_weights(f'./{model_name}.h5')\npreds = model.predict(dtest, verbose=1)","metadata":{"papermill":{"duration":95.213508,"end_time":"2021-09-05T12:52:22.000762","exception":false,"start_time":"2021-09-05T12:50:46.787254","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T02:31:24.818566Z","iopub.execute_input":"2022-12-16T02:31:24.818886Z","iopub.status.idle":"2022-12-16T02:32:33.294915Z","shell.execute_reply.started":"2022-12-16T02:31:24.818856Z","shell.execute_reply":"2022-12-16T02:32:33.293875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_preds = model.predict(valid_dataset, verbose=1)\nval_preds = np.round(val_preds, decimals = 0)\nprint(classification_report(valid_labels , val_preds))","metadata":{"papermill":{"duration":8.66322,"end_time":"2021-09-05T12:52:31.602194","exception":false,"start_time":"2021-09-05T12:52:22.938974","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-12-16T02:32:33.296773Z","iopub.execute_input":"2022-12-16T02:32:33.297029Z","iopub.status.idle":"2022-12-16T02:33:01.548124Z","shell.execute_reply.started":"2022-12-16T02:32:33.297001Z","shell.execute_reply":"2022-12-16T02:33:01.547019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.DataFrame()\nsub['id'] = test_paths\nsub['id'] = sub['id'].apply(lambda x: int(x.split('.')[-2].split('/')[-1]))\nsub['label'] = np.argmax(preds, axis=-1)\nsub.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T02:33:01.549507Z","iopub.execute_input":"2022-12-16T02:33:01.549838Z","iopub.status.idle":"2022-12-16T02:33:01.571266Z","shell.execute_reply.started":"2022-12-16T02:33:01.549803Z","shell.execute_reply":"2022-12-16T02:33:01.570330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.to_csv('sub.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T02:33:01.573458Z","iopub.execute_input":"2022-12-16T02:33:01.573803Z","iopub.status.idle":"2022-12-16T02:33:01.587549Z","shell.execute_reply.started":"2022-12-16T02:33:01.573763Z","shell.execute_reply":"2022-12-16T02:33:01.585972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}