{"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"sourceId":70203,"databundleVersionId":8068726,"sourceType":"competition"},{"sourceId":1664376,"sourceType":"datasetVersion","datasetId":985270},{"sourceId":5181249,"sourceType":"datasetVersion","datasetId":3012199},{"sourceId":5190993,"sourceType":"datasetVersion","datasetId":3018185},{"sourceId":5196408,"sourceType":"datasetVersion","datasetId":3018885},{"sourceId":8036535,"sourceType":"datasetVersion","datasetId":4737648},{"sourceId":171367994,"sourceType":"kernelVersion"}],"dockerImageVersionId":30702,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.13"},"papermill":{"default_parameters":{},"duration":85.328891,"end_time":"2024-04-06T18:24:33.296159","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2024-04-06T18:23:07.967268","version":"2.5.0"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# Importing the necessary modules for system-specific operations\nimport sys, os   \n\n# Appending a directory path to the Python system path, allowing Python to search for modules in that directory\nsys.path.append('/kaggle/input/efficientnet-keras-dataset/efficientnet_kaggle')\n\n# Installing a TensorFlow extra library from a specific location using pip, with quiet mode and skipping dependency installation\n!pip install -q /kaggle/input/tensorflow-extra-lib-ds/tensorflow_extra-1.0.2-py3-none-any.whl --no-deps\n","metadata":{"papermill":{"duration":23.25675,"end_time":"2024-04-06T18:23:34.791789","exception":false,"start_time":"2024-04-06T18:23:11.535039","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:02:42.131316Z","iopub.execute_input":"2024-04-19T09:02:42.131964Z","iopub.status.idle":"2024-04-19T09:03:05.625950Z","shell.execute_reply.started":"2024-04-19T09:02:42.131892Z","shell.execute_reply":"2024-04-19T09:03:05.624290Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Importing TensorFlow library\nimport tensorflow as tf\n\n# Setting the logging level of TensorFlow to ERROR\ntf.get_logger().setLevel('ERROR')\n\n# Setting autograph verbosity level to 0\ntf.autograph.set_verbosity(0)\n\n# Importing the os module for interacting with the operating system\nimport os\n\n# Importing Pandas library and aliasing it as pd\nimport pandas as pd\n\n# Importing NumPy library and aliasing it as np\nimport numpy as np\n\n# Importing random module for generating random numbers\nimport random\n\n# Importing glob module to retrieve files/pathnames matching a specified pattern\nfrom glob import glob\n\n# Importing tqdm library for progress bars\nfrom tqdm import tqdm\ntqdm.pandas()\n\n# Importing garbage collection module for managing memory\nimport gc\n\n# Importing librosa library for audio analysis\nimport librosa\n\n# Importing scikit-learn library for machine learning tasks\nimport sklearn\n\n# Importing time module for time-related functions\nimport time\n\n# Importing matplotlib library for plotting\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\n# Importing librosa's display module and aliasing it as lid\nimport librosa.display as lid\n\n# Importing IPython's display module and aliasing it as ipd\nimport IPython.display as ipd\n\n# Enabling XLA (Accelerated Linear Algebra) for TensorFlow optimizer for speed up\ntf.config.optimizer.set_jit(True)\n\n# Importing TensorFlow IO library\nimport tensorflow_io as tfio\n\n# Importing TensorFlow Keras backend module and aliasing it as K\nimport tensorflow.keras.backend as K\n\n# Importing EfficientNet model from TensorFlow Keras implementation\nimport efficientnet.tfkeras as efn\n\n# Importing TensorFlow extra library\nimport tensorflow_extra as tfe","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":20.940562,"end_time":"2024-04-06T18:23:55.770098","exception":false,"start_time":"2024-04-06T18:23:34.829536","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:05.629036Z","iopub.execute_input":"2024-04-19T09:03:05.629625Z","iopub.status.idle":"2024-04-19T09:03:32.209488Z","shell.execute_reply.started":"2024-04-19T09:03:05.629572Z","shell.execute_reply":"2024-04-19T09:03:32.207613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Printing the version of NumPy library\nprint('np:', np.__version__)\n\n# Printing the version of Pandas library\nprint('pd:', pd.__version__)\n\n# Printing the version of scikit-learn library\nprint('sklearn:', sklearn.__version__)\n\n# Printing the version of librosa library\nprint('librosa:', librosa.__version__)\n\n# Printing the version of TensorFlow library\nprint('tf:', tf.__version__)\n\n# Printing the version of TensorFlow IO library\nprint('tfio:', tfio.__version__)","metadata":{"papermill":{"duration":0.035293,"end_time":"2024-04-06T18:23:55.842615","exception":false,"start_time":"2024-04-06T18:23:55.807322","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:32.211772Z","iopub.execute_input":"2024-04-19T09:03:32.212690Z","iopub.status.idle":"2024-04-19T09:03:32.221051Z","shell.execute_reply.started":"2024-04-19T09:03:32.212645Z","shell.execute_reply":"2024-04-19T09:03:32.219999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class CFG:\n    # Debug mode and verbosity level\n    debug = False  # Set debug mode to False\n    verbose = 0    # Set verbosity level to 0\n    \n    # Device settings and seed for reproducibility\n    device = 'CPU'  # Set device to 'CPU' by default\n    seed = 42       # Set seed for reproducibility\n    \n    # Input image size and batch size\n    img_size = [128, 384]  # Set input image size to [128, 384]\n    batch_size = 16         # Set batch size for training\n    infer_bs = 2            # Set batch size for inference\n    tta = 1                 # Set Test Time Augmentation (TTA) to 1\n    drop_remainder = True   # Drop remainder of the batches\n    \n    # STFT parameters\n    duration = 5                    # Duration for test\n    train_duration = 10             # Duration for training\n    sample_rate = 32000             # Sampling rate\n    downsample = 1                  # Downsample rate\n    audio_len = duration * sample_rate  # Length of audio\n    nfft = 2028                     # Number of FFT points\n    window = 2048                   # Window size\n    hop_length = train_duration * 32000 // (img_size[1] - 1)  # Hop length\n    fmin = 20                       # Minimum frequency\n    fmax = 16000                    # Maximum frequency\n    normalize = True                # Normalize the data\n    \n    # Data Preprocessing Settings\n    class_names = sorted(os.listdir('/kaggle/input/birdclef-2024/train_audio/'))  # Get sorted list of class names\n    num_classes = len(class_names)  # Get the number of classes\n    class_labels = list(range(num_classes))  # Generate labels for classes\n    label2name = dict(zip(class_labels, class_names))  # Map labels to class names\n    name2label = {v: k for k, v in label2name.items()}  # Map class names to labels\n    \n    target_col = ['target']  # Set target column\n    tab_cols = ['filename', 'common_name', 'rate']  # Set table columns","metadata":{"_kg_hide-input":false,"papermill":{"duration":0.043831,"end_time":"2024-04-06T18:23:55.926667","exception":false,"start_time":"2024-04-06T18:23:55.882836","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:32.223650Z","iopub.execute_input":"2024-04-19T09:03:32.224521Z","iopub.status.idle":"2024-04-19T09:03:32.268011Z","shell.execute_reply.started":"2024-04-19T09:03:32.224475Z","shell.execute_reply":"2024-04-19T09:03:32.266746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.keras.utils.set_random_seed(CFG.seed)","metadata":{"_kg_hide-input":true,"papermill":{"duration":0.021933,"end_time":"2024-04-06T18:23:55.984654","exception":false,"start_time":"2024-04-06T18:23:55.962721","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:32.269648Z","iopub.execute_input":"2024-04-19T09:03:32.270408Z","iopub.status.idle":"2024-04-19T09:03:32.277473Z","shell.execute_reply.started":"2024-04-19T09:03:32.270368Z","shell.execute_reply":"2024-04-19T09:03:32.275790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_device():\n    \"\"\"\n    Detects and initializes GPU/TPU automatically.\n    \n    Returns:\n        strategy: Distributed training strategy (TPU or GPU)\n        device: Device on which the code is running (CPU, GPU, or TPU)\n        tpu: TPU cluster resolver (None if not running on TPU)\n    \"\"\"\n    # Check TPU category\n    tpu = 'local' if CFG.device == 'TPU-VM' else None\n    \n    try:\n        # Connect to TPU\n        tpu = tf.distribute.cluster_resolver.TPUClusterResolver.connect(tpu=tpu) \n        \n        # Set TPU strategy\n        strategy = tf.distribute.TPUStrategy(tpu)\n        \n        # Print TPU details\n        print(f'> Running on {CFG.device} ', tpu.master(), end=' | ')\n        print('Num of TPUs: ', strategy.num_replicas_in_sync)\n        \n        device = CFG.device\n        \n    except:\n        # If TPU is not available, detect GPUs\n        gpus = tf.config.list_logical_devices('GPU')\n        ngpu = len(gpus)\n        \n        # Check number of GPUs\n        if ngpu:\n            # Set GPU strategy\n            strategy = tf.distribute.MirroredStrategy(gpus) # single-GPU or multi-GPU\n            \n            # Print GPU details\n            print(\"> Running on GPU\", end=' | ')\n            print(\"Num of GPUs: \", ngpu)\n            \n            device = 'GPU'\n            \n        else:\n            # If no GPUs are available, use CPU\n            print(\"> Running on CPU\")\n            strategy = tf.distribute.get_strategy()\n            device = 'CPU'\n    \n    return strategy, device, tpu","metadata":{"_kg_hide-input":true,"papermill":{"duration":0.035385,"end_time":"2024-04-06T18:23:56.061052","exception":false,"start_time":"2024-04-06T18:23:56.025667","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:32.279655Z","iopub.execute_input":"2024-04-19T09:03:32.280219Z","iopub.status.idle":"2024-04-19T09:03:32.295972Z","shell.execute_reply.started":"2024-04-19T09:03:32.280178Z","shell.execute_reply":"2024-04-19T09:03:32.294684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Initialize GPU/TPU/TPU-VM\nstrategy, CFG.device, tpu = get_device()\nCFG.replicas = strategy.num_replicas_in_sync","metadata":{"papermill":{"duration":0.031624,"end_time":"2024-04-06T18:23:56.105848","exception":false,"start_time":"2024-04-06T18:23:56.074224","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:32.297562Z","iopub.execute_input":"2024-04-19T09:03:32.299023Z","iopub.status.idle":"2024-04-19T09:03:32.337575Z","shell.execute_reply.started":"2024-04-19T09:03:32.298964Z","shell.execute_reply":"2024-04-19T09:03:32.336452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_PATH = '/kaggle/input/birdclef-2024'\nGCS_PATH = BASE_PATH","metadata":{"papermill":{"duration":0.022691,"end_time":"2024-04-06T18:23:56.167179","exception":false,"start_time":"2024-04-06T18:23:56.144488","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:32.339401Z","iopub.execute_input":"2024-04-19T09:03:32.340146Z","iopub.status.idle":"2024-04-19T09:03:32.350455Z","shell.execute_reply.started":"2024-04-19T09:03:32.340097Z","shell.execute_reply":"2024-04-19T09:03:32.349286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Directory containing test audio files\ntest_audio_dir = '/kaggle/input/birdclef-2024/test_soundscapes/'\n\n# List of paths to test audio files\ntest_paths = [test_audio_dir + f for f in sorted(os.listdir(test_audio_dir))]\n\n# If there is only one file in the test audio directory\nif len(test_paths) == 1:\n    # Use the directory containing unlabeled soundscapes instead\n    test_audio_dir = '/kaggle/input/birdclef-2024/unlabeled_soundscapes/'\n\n    # Select the first two files from the directory\n    test_paths = [test_audio_dir + f for f in sorted(os.listdir(test_audio_dir))][:2]\n\n# Create a DataFrame with the file paths\ntest_df = pd.DataFrame(test_paths, columns=['filepath'])\n\n# Extract filenames from file paths and create a new column\ntest_df['filename'] = test_df.filepath.map(lambda x: x.split('/')[-1].replace('.ogg', ''))\n\n# Display the first few rows of the DataFrame\ntest_df.head()","metadata":{"papermill":{"duration":0.345655,"end_time":"2024-04-06T18:23:56.551086","exception":false,"start_time":"2024-04-06T18:23:56.205431","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:32.352682Z","iopub.execute_input":"2024-04-19T09:03:32.353700Z","iopub.status.idle":"2024-04-19T09:03:32.474101Z","shell.execute_reply.started":"2024-04-19T09:03:32.353644Z","shell.execute_reply":"2024-04-19T09:03:32.472651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.io.gfile.exists(test_df.filepath.iloc[0])","metadata":{"papermill":{"duration":0.026736,"end_time":"2024-04-06T18:23:56.590731","exception":false,"start_time":"2024-04-06T18:23:56.563995","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:32.478107Z","iopub.execute_input":"2024-04-19T09:03:32.478579Z","iopub.status.idle":"2024-04-19T09:03:32.488030Z","shell.execute_reply.started":"2024-04-19T09:03:32.478544Z","shell.execute_reply":"2024-04-19T09:03:32.486790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_audio(filepath, sr=32000, normalize=True):\n    \"\"\"\n    Load audio file from filepath and return as a tensor.\n\n    Args:\n        filepath (str): Path to the audio file.\n        sr (int): Target sampling rate. Default is 32000.\n        normalize (bool): Whether to normalize the audio. Default is True.\n\n    Returns:\n        audio (tensor): Loaded audio as a tensor.\n    \"\"\"\n    # Load audio using librosa\n    audio, orig_sr = librosa.load(filepath, sr=None)\n    \n    # Resample audio if the target sampling rate is different from the original sampling rate\n    if sr != orig_sr:\n        audio = librosa.resample(audio, orig_sr, sr)\n    \n    # Convert audio to float32 and flatten it\n    audio = audio.astype('float32').ravel()\n    \n    # Convert audio to a TensorFlow tensor\n    audio = tf.convert_to_tensor(audio)\n    \n    return audio\n\n@tf.function(jit_compile=True)\ndef MakeFrame(audio, duration=5, sr=32000):\n    \"\"\"\n    Split audio into frames.\n\n    Args:\n        audio (tensor): Input audio tensor.\n        duration (int): Duration of each frame in seconds. Default is 5.\n        sr (int): Sampling rate of the audio. Default is 32000.\n\n    Returns:\n        chunks (tensor): Frames of audio as a tensor.\n    \"\"\"\n    # Calculate frame length and frame step\n    frame_length = int(duration * sr)\n    frame_step = int(duration * sr)\n    \n    # Split audio into frames\n    chunks = tf.signal.frame(audio, frame_length, frame_step, pad_end=True)\n    \n    return chunks","metadata":{"_kg_hide-input":true,"papermill":{"duration":0.026981,"end_time":"2024-04-06T18:23:56.656559","exception":false,"start_time":"2024-04-06T18:23:56.629578","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:32.489524Z","iopub.execute_input":"2024-04-19T09:03:32.491089Z","iopub.status.idle":"2024-04-19T09:03:32.506145Z","shell.execute_reply.started":"2024-04-19T09:03:32.491034Z","shell.execute_reply":"2024-04-19T09:03:32.505041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def display_audio(row):\n    \"\"\"\n    Display audio waveform and audio playback for a given row in the DataFrame.\n\n    Args:\n        row: Row from the DataFrame containing filepath and filename.\n\n    Returns:\n        None\n    \"\"\"\n    # Caption for visualization\n    caption = f'Id: {row.filename}'\n    \n    # Read audio file\n    audio = load_audio(row.filepath)\n    \n    # Keep fixed length audio\n    audio = audio[:CFG.audio_len]\n    \n    # Display audio\n    print(\"# Audio:\")\n    display(ipd.Audio(audio.numpy(), rate=CFG.sample_rate))\n    \n    print('# Visualization:')\n    # Create a plot for waveform visualization\n    plt.figure(figsize=(12, 3))\n    plt.title(caption)\n    \n    # Plot waveform\n    lid.waveshow(audio.numpy(), sr=CFG.sample_rate)\n                 \n    plt.xlabel('')\n    plt.show()","metadata":{"_kg_hide-input":true,"papermill":{"duration":0.02567,"end_time":"2024-04-06T18:23:56.746096","exception":false,"start_time":"2024-04-06T18:23:56.720426","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:32.507462Z","iopub.execute_input":"2024-04-19T09:03:32.508419Z","iopub.status.idle":"2024-04-19T09:03:32.529188Z","shell.execute_reply.started":"2024-04-19T09:03:32.508381Z","shell.execute_reply":"2024-04-19T09:03:32.528031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_audio(test_df.iloc[0])","metadata":{"papermill":{"duration":15.507278,"end_time":"2024-04-06T18:24:12.291933","exception":false,"start_time":"2024-04-06T18:23:56.784655","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:32.530780Z","iopub.execute_input":"2024-04-19T09:03:32.532181Z","iopub.status.idle":"2024-04-19T09:03:50.285734Z","shell.execute_reply.started":"2024-04-19T09:03:32.532134Z","shell.execute_reply":"2024-04-19T09:03:50.284204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\n\n# Directory of checkpoint\nCKPT_DIR = '/kaggle/input/birdclef24-pretraining-train-model'\n\n# Get file paths of all trained models in the directory\nCKPT_PATHS = sorted([x for x in glob(f'{CKPT_DIR}/fold-*keras')])\nprint(\"Checkpoints: \", CKPT_PATHS)\n\n# Define a writable directory\nWRITABLE_DIR = '/kaggle/working/models/'\n\n# Create the writable directory if it does not exist\nif not os.path.exists(WRITABLE_DIR):\n    os.makedirs(WRITABLE_DIR)\n\n# Copy the model files to the writable directory\nfor ckpt_path in CKPT_PATHS:\n    shutil.copy(ckpt_path, WRITABLE_DIR)\n\n# Update the checkpoint paths to the writable directory\nCKPT_PATHS = sorted([f'{WRITABLE_DIR}/{os.path.basename(x)}' for x in glob(f'{CKPT_DIR}/fold-*keras')])\n\n# Load all the models in memory to speed up\nCKPTS = [tf.keras.models.load_model(x, compile=False) for x in tqdm(CKPT_PATHS, desc=\"Loading ckpts \")]\n\n# Num of ckpt to use\nNUM_CKPTS = 1","metadata":{"papermill":{"duration":8.586829,"end_time":"2024-04-06T18:24:20.941753","exception":false,"start_time":"2024-04-06T18:24:12.354924","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:03:50.287885Z","iopub.execute_input":"2024-04-19T09:03:50.288748Z","iopub.status.idle":"2024-04-19T09:04:00.264889Z","shell.execute_reply.started":"2024-04-19T09:03:50.288688Z","shell.execute_reply":"2024-04-19T09:04:00.263491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Start stopwatch\ntick = time.time()\n\n# Initialize empty list to store ids\nids = []\n# Initialize empty array to store predictions\npreds = np.empty(shape=(0, 182), dtype='float32')\n\n# Iterate over each audio file in the test dataset\nfor filepath in tqdm(test_df.filepath.tolist(), 'test '):\n    # Extract the filename without the extension\n    filename = filepath.split('/')[-1].replace('.ogg','')\n    \n    # Load audio from file and create audio frames, each recording will be a batch input\n    audio = load_audio(filepath)\n    chunks = MakeFrame(audio)\n    \n    # Predict bird species for all frames in a recording using all trained models\n    chunk_preds = np.zeros(shape=(len(chunks), 182), dtype=np.float32)\n    for model in CKPTS[:NUM_CKPTS]:\n        # Get the model's predictions for the current audio frames\n        rec_preds = model(chunks, training=False).numpy()\n        # Ensemble all prediction with average\n        chunk_preds += rec_preds/len(CKPTS)\n    \n    # Create a ID for each frame in a recording using the filename and frame number\n    rec_ids = [f'{filename}_{(frame_id+1)*5}' for frame_id in range(len(chunks))]\n    \n    # Concatenate the ids\n    ids += rec_ids\n    # Concatenate the predictions\n    preds = np.concatenate([preds, chunk_preds], axis=0)\n    \n# Stop stopwatch\ntock = time.time()","metadata":{"papermill":{"duration":8.25077,"end_time":"2024-04-06T18:24:29.254015","exception":false,"start_time":"2024-04-06T18:24:21.003245","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:04:00.267184Z","iopub.execute_input":"2024-04-19T09:04:00.268313Z","iopub.status.idle":"2024-04-19T09:04:10.175388Z","shell.execute_reply.started":"2024-04-19T09:04:00.268235Z","shell.execute_reply":"2024-04-19T09:04:10.173886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds.shape","metadata":{"papermill":{"duration":0.032619,"end_time":"2024-04-06T18:24:29.351816","exception":false,"start_time":"2024-04-06T18:24:29.319197","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:04:10.177607Z","iopub.execute_input":"2024-04-19T09:04:10.178290Z","iopub.status.idle":"2024-04-19T09:04:10.187421Z","shell.execute_reply.started":"2024-04-19T09:04:10.178250Z","shell.execute_reply":"2024-04-19T09:04:10.185750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submit prediction\npred_df = pd.DataFrame(ids, columns=['row_id'])\npred_df.loc[:, CFG.class_names] = preds\npred_df.to_csv('submission.csv',index=False)\npred_df","metadata":{"papermill":{"duration":0.220742,"end_time":"2024-04-06T18:24:29.593948","exception":false,"start_time":"2024-04-06T18:24:29.373206","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:04:10.189855Z","iopub.execute_input":"2024-04-19T09:04:10.190368Z","iopub.status.idle":"2024-04-19T09:04:10.418583Z","shell.execute_reply.started":"2024-04-19T09:04:10.190327Z","shell.execute_reply":"2024-04-19T09:04:10.416898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_time = (tock-tick)*550 # ~1100 recording on the test data\nsub_time = time.gmtime(sub_time)\nsub_time = time.strftime(\"%H hr: %M min : %S sec\", sub_time)\nprint(f\">> Time for submission: ~ {sub_time}\")","metadata":{"_kg_hide-input":true,"papermill":{"duration":0.034257,"end_time":"2024-04-06T18:24:29.793347","exception":false,"start_time":"2024-04-06T18:24:29.759090","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-19T09:04:10.420082Z","iopub.execute_input":"2024-04-19T09:04:10.420473Z","iopub.status.idle":"2024-04-19T09:04:10.429072Z","shell.execute_reply.started":"2024-04-19T09:04:10.420442Z","shell.execute_reply":"2024-04-19T09:04:10.427627Z"},"trusted":true},"execution_count":null,"outputs":[]}]}