{"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":"markdown","source":"### Code modified from https://github.com/kahst/BirdNET-Analyzer,  Version 18 rank 1 in public and 2 in private leaderboard. The code is under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (https://creativecommons.org/licenses/by-nc-sa/4.0/).\n  \n","metadata":{}},{"cell_type":"markdown","source":"## Note 1: Honestly we didn't originally intend to use this model as a submission, until we sse this issue (https://github.com/kahst/BirdNET-Analyzer/issues/40)  \n\n## Note 2: The ensemble of the ensemble of our own model could also reach gold zone, and we published all trained model (refer: https://www.kaggle.com/code/leonshangguan/private-7-8-final-of-submission Version 6)  \n\n## Note 3: But the BirdNet is run on CPU within 2h inference time, while ours cost about 8h to run.\n","metadata":{}},{"cell_type":"markdown","source":"\n# Conclusion: BirdNet wins!!! The host beats all participants!!!","metadata":{}},{"cell_type":"code","source":"!python ../input/birdnet/BirdNET-Analyzer/analyze.py --i ../input/birdclef-2022/test_soundscapes/ --o ./ --slist ./example --overlap 0 --rtype table --min_conf 0.9 --threads 8","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !python ../input/birdnet/BirdNET-Analyzer/analyze.py --i ../input/birdclef-2022/train_audio/ --o ./ --slist ./example --overlap 0 --rtype table --min_conf 0.001 --threads 8","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import glob\nimport pandas as pd\nresult_files = glob.glob(\"./*.txt\")","metadata":{"execution":{"iopub.status.busy":"2022-05-11T07:35:30.229028Z","iopub.execute_input":"2022-05-11T07:35:30.229658Z","iopub.status.idle":"2022-05-11T07:35:30.262191Z","shell.execute_reply.started":"2022-05-11T07:35:30.229537Z","shell.execute_reply":"2022-05-11T07:35:30.261522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_dicts = {}\nfor file in result_files:\n    data = pd.read_csv(file, sep='\\t')\n    for time in range(5, 65, 5):\n        pred = []\n        pre = file.split('.')[1][1:] + '_' + str(time)\n        labels = data[(time-5 <= data[\"Begin Time (s)\"]) & (data[\"Begin Time (s)\"] < time)][\"Species Code\"].values.tolist()\n        labels += data[(time-5 <= data[\"End Time (s)\"]) & (data[\"Begin Time (s)\"] < time)][\"Species Code\"].values.tolist()\n\n        pred = set(labels)\n#         print(pred, \" \".join(pred))\n#         for l in labels:\n#             if l not in pred:\n#                 pred.append(l)\n#         print(\"*******************************************************************\")\n#         print(pre, pred)\n        pred_dicts[pre] = \" \".join(pred)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_dicts","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission = pd.read_csv('../input/birdclef-2022/sample_submission.csv')\nsample_submission","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(len(sample_submission)):\n    sample = sample_submission.row_id[i]\n    key = sample.split(\"_\")[0] + \"_\" + sample.split(\"_\")[1] + \"_\" + sample.split(\"_\")[3]\n    target_bird = sample.split(\"_\")[2]\n    print(key, target_bird)\n    if key in pred_dicts:\n        sample_submission.iat[i, 1] = (target_bird in pred_dicts[key])\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm ./*.txt","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.to_csv(\"submission.csv\", index=False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}