{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":44224,"databundleVersionId":5188730,"sourceType":"competition"},{"sourceId":12252032,"sourceType":"datasetVersion","datasetId":7719828},{"sourceId":12253213,"sourceType":"datasetVersion","datasetId":7719905},{"sourceId":12254544,"sourceType":"datasetVersion","datasetId":7719874}],"dockerImageVersionId":31040,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install /kaggle/input/model1/onnxruntime-1.22.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl --no-deps","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T08:29:28.413650Z","iopub.execute_input":"2025-06-23T08:29:28.413926Z","iopub.status.idle":"2025-06-23T08:29:33.644730Z","shell.execute_reply.started":"2025-06-23T08:29:28.413903Z","shell.execute_reply":"2025-06-23T08:29:33.643383Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import sys\nsys.path.append('/kaggle/input/bird11/')\nimport pandas as pd\nimport numpy as np\nimport librosa\nimport os\nimport torch\nimport onnxruntime as ort\nfrom glob import glob\n\nfrom code_base.datasets import WaveAllFileDataset\nfrom code_base.utils.inference_utils import apply_avarage_weights_on_swa_path\nfrom code_base.inefernce import BirdsInference\nfrom code_base.utils import load_json, compose_submission_dataframe\nfrom code_base.utils.metrics import padded_cmap_numpy","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-23T08:29:33.646219Z","iopub.execute_input":"2025-06-23T08:29:33.646598Z","iopub.status.idle":"2025-06-23T08:29:40.895349Z","shell.execute_reply.started":"2025-06-23T08:29:33.646545Z","shell.execute_reply":"2025-06-23T08:29:40.894446Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_au_pathes = glob(\"/kaggle/input/birdclef-2023/test_soundscapes/*.ogg\")\n\ntest_df = pd.DataFrame({\n    \"filename\": test_au_pathes,\n    \"duration_s\": [librosa.get_duration(path=el) for el in test_au_pathes]\n})","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T08:29:40.897570Z","iopub.execute_input":"2025-06-23T08:29:40.897985Z","iopub.status.idle":"2025-06-23T08:29:45.468655Z","shell.execute_reply.started":"2025-06-23T08:29:40.897962Z","shell.execute_reply":"2025-06-23T08:29:45.467649Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"CONFIG = {\n    \"run_validation\": False,\n    \"run_test\": True,\n    \"use_sigmoid\": False,\n    \"folds\": [0],\n    \"test_data_root\": \"/kaggle/input/birdclef-2023/test_soundscapes/*.ogg\",\n    # \"test_data_root\": \"data/birdclef_2023/test_soundscapes/*.ogg\",\n    \"label_map_data_path\": \"/kaggle/input/bird2int/bird2int_2023.json\",\n    # \"label_map_data_path\": 'data/bird2int_2023.json',\n    \"lookback\": None,\n    \"lookahead\": None,\n    \"segment_len\": 5,\n    \"step\": None,\n    \"late_normalize\": True,\n    \"exp_name\": \"convnext_small_fb_in22k_ft_in1k_384__convnextv2_tiny_fcmae_ft_in22k_in1k_384__eca_nfnet_l0_noval_v32_075Clipwise025TimeMax_GausMean\",\n}\nbird2id = load_json(CONFIG[\"label_map_data_path\"])\nds_config_test = {\n       \"root\": \"\",\n       \"label_str2int_mapping_path\": CONFIG[\"label_map_data_path\"],\n       \"n_cores\": 64,\n       \"use_audio_cache\": True,\n       \"test_mode\": True,\n       \"segment_len\": CONFIG[\"segment_len\"],\n       \"lookback\":CONFIG[\"lookback\"],\n       \"lookahead\":CONFIG[\"lookahead\"],\n        \"sample_id\": None,\n        \"late_normalize\": CONFIG[\"late_normalize\"],\n        \"step\": CONFIG[\"step\"],\n        \"validate_sr\": 32_000\n    }\nloader_config = {\n    \"batch_size\": 4,\n    \"drop_last\": False,\n    \"shuffle\": False,\n    \"num_workers\": 0,\n}\nds_test = WaveAllFileDataset(df=test_df, **ds_config_test)\nloader_test = torch.utils.data.DataLoader(\n        ds_test,\n        **loader_config,\n    )","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T08:29:45.469494Z","iopub.execute_input":"2025-06-23T08:29:45.469886Z","iopub.status.idle":"2025-06-23T08:29:45.506819Z","shell.execute_reply.started":"2025-06-23T08:29:45.469865Z","shell.execute_reply":"2025-06-23T08:29:45.505852Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = ort.InferenceSession(\"/kaggle/input/bird2int/model_simpl.onnx\")\n\ninference_class = BirdsInference(\n    device=\"cpu\",\n    verbose_tqdm=True,\n    use_sigmoid=CONFIG[\"use_sigmoid\"],\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T08:29:45.507801Z","iopub.execute_input":"2025-06-23T08:29:45.508142Z","iopub.status.idle":"2025-06-23T08:29:49.233112Z","shell.execute_reply.started":"2025-06-23T08:29:45.508109Z","shell.execute_reply":"2025-06-23T08:29:49.232263Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_preds, test_preds_long, test_dfidx, test_end = inference_class.predict_test_loader(\n        nn_models=model,\n        data_loader=loader_test,\n        is_onnx_model=True\n    )\ntest_pred_df = compose_submission_dataframe(\n    probs=test_preds,\n    dfidxs=test_dfidx,\n    end_seconds=test_end,\n    filenames=loader_test.dataset.df[loader_test.dataset.name_col].copy(),\n    bird2id=bird2id,\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T08:29:49.234091Z","iopub.execute_input":"2025-06-23T08:29:49.234467Z","iopub.status.idle":"2025-06-23T08:30:23.626810Z","shell.execute_reply.started":"2025-06-23T08:29:49.234443Z","shell.execute_reply":"2025-06-23T08:30:23.625884Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_pred_df.to_csv(\"submission.csv\", index=False)\nimport pandas as pd\npd.read_csv(\"submission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T08:31:59.615063Z","iopub.execute_input":"2025-06-23T08:31:59.615422Z","iopub.status.idle":"2025-06-23T08:31:59.731274Z","shell.execute_reply.started":"2025-06-23T08:31:59.615396Z","shell.execute_reply":"2025-06-23T08:31:59.730252Z"}},"outputs":[],"execution_count":null}]}