{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":19596,"databundleVersionId":1292430,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"from pathlib import Path\nimport shutil\nimport random\n\nroot_dir = Path('/kaggle/input/birdsong-recognition/train_audio')\nassert root_dir.exists(), 'Invalid path'\n\nnum_categories = 20\nexamples_per_category = 100\n\nsubset_dir = Path(f'bird_call_{num_categories}_{examples_per_category}')\nsubset_dir.mkdir(exist_ok=True)\n\nall_classes = sorted([d for d in root_dir.iterdir() if d.is_dir()])\nselected_categories = 0\n\nfor bird_class in all_classes:\n    if selected_categories >= num_categories:\n        break\n    \n    audio_files = list(bird_class.glob('*.mp3'))\n    \n    if len(audio_files) >= examples_per_category:\n        print(f\"Processing {bird_class.name}: {len(audio_files)} files available\")\n        \n        dest = subset_dir / bird_class.name\n        dest.mkdir(exist_ok=True)\n        \n        selected_files = random.sample(audio_files, examples_per_category)\n        \n        for audio_file in selected_files:\n            shutil.copy2(audio_file, dest / audio_file.name)\n        \n        selected_categories += 1\n        print(f\"✓ Copied {examples_per_category} files to {bird_class.name}\")\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-21T10:28:20.201539Z","iopub.execute_input":"2025-08-21T10:28:20.201826Z","iopub.status.idle":"2025-08-21T10:28:56.407683Z","shell.execute_reply.started":"2025-08-21T10:28:20.201797Z","shell.execute_reply":"2025-08-21T10:28:56.406788Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(f\"\\nCompleted! Selected {selected_categories} categories with {examples_per_category} examples each\")\nprint(f\"Total files: {selected_categories * examples_per_category}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-21T10:28:57.471050Z","iopub.execute_input":"2025-08-21T10:28:57.471334Z","iopub.status.idle":"2025-08-21T10:28:57.476519Z","shell.execute_reply.started":"2025-08-21T10:28:57.471311Z","shell.execute_reply":"2025-08-21T10:28:57.475422Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"zip_path = f\"/kaggle/working/bird_call_{num_categories}_{examples_per_category}\"\nshutil.make_archive(zip_path, 'zip', f\"/kaggle/working/bird_call_{num_categories}_{examples_per_category}\")\nprint(f\"Archive created: {zip_path}.zip\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-21T10:31:49.402784Z","iopub.execute_input":"2025-08-21T10:31:49.403172Z","iopub.status.idle":"2025-08-21T10:34:00.155369Z","shell.execute_reply.started":"2025-08-21T10:31:49.403145Z","shell.execute_reply":"2025-08-21T10:34:00.153434Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}