{
  "id": 412869,
  "title": "37th place solution - TF CNN + BirdNet emb. cls. & XGB",
  "url": "/competitions/birdclef-2023/writeups/kirderf-37th-place-solution-tf-cnn-birdnet-emb-cls",
  "author_name": "",
  "post_date": "2023-05-26T08:21:34.267Z",
  "votes": 13,
  "comment_count": 3,
  "views": 0,
  "content": "<p>Congrats to the winners and also to the host that create these annual competitions. 👌</p>\n<p><strong>Summary of the solution</strong></p>\n<p>Inference with 12 models all together within the 2 hours CPU inference window.</p>\n<p>5 different Tensorflow CNN, SOTA techniques trained with previous competition data and finetuned with current data, post ONNX converted. Ensembled together with: 1. The latest BirdNet TFlite version with 124 of the 264 birds. 2. custom classification TF head trained with Birdnet embeddings on competition data. 3. XGB 5 fold trained with Birdnet embeddings on competition data. Also used the non-bird classes from Birdnet to reduce the probabilities with 50% over the birds if the non-birds classes had higher probability in 5 seconds window, nothing of use here but interesting to implement.</p>\n<p><strong>Training and data</strong></p>\n<p>As starter code I used <a href=\"https://www.kaggle.com/awsaf49\" target=\"_blank\">@awsaf49</a> <a href=\"https://www.kaggle.com/code/awsaf49/birdclef23-pretraining-is-all-you-need-train\" target=\"_blank\">https://www.kaggle.com/code/awsaf49/birdclef23-pretraining-is-all-you-need-train</a>. Tensorflow based TPU training with W&amp;B logging and latest SOTA audio techniques, SpecAug like Time Freq masking and Audio Augmentation like Gaussian Noise, Random CropPad, CutMix and MixUp.</p>\n<blockquote>\n  <p>Methodology 🎯<br>\n  In this notebook, we will explore how to identify bird calls using TensorFlow. Specifically, this notebook will cover:<br>\n  How to use tf.data for audio processing tasks and reading .ogg files in TensorFlow<br>\n  How to extract spectrogram features from raw audio on TPU/GPU, which reduces CPU bottleneck significantly, speeding up the process by ~ 4×on P100 GPU compared to the previous notebook.<br>\n  Unlike the previous tutorial, this notebook will perform spectrogram augmentation such as TimeFreqMask and Normalization on GPU/TPU and perform CutMix and MixUp with audio data on CPU.<br>\n  This notebook demonstrates how pre-training on the BirdCLEF - 2020, 2021, 2022 &amp; Xeno-Canto Extend dataset can improve transfer learning performance. CNN backbones, like EfficientNet, struggle with spectrogram data even with ImageNet pre-trained weights as they are not fimilar with audio data. Pre-training on an audio dataset, like BirdCLEF, can mitigate this issue and can yield a ~ 5% improvement in local validation and ~ 2% improvement in leaderboard. This notebook is compatible with both GPU, TPU, and the newly launched TPU-VM device is automatically selected, so you won't have to do anything to allocate the device.</p>\n</blockquote>\n<p>Credit to <a href=\"https://www.kaggle.com/awsaf49\" target=\"_blank\">@awsaf49</a> </p>\n<p><strong>Inference and submissions</strong></p>\n<p>TF CNN models trained and used: <br>\nEfficientnetb1, Eficientnetb0, Efficientnetv1b1ns, Efficientnetv2m, Efficientnetv2s – some trained with all the data some in single fold, many also trained/saved with weighted average over 2-5 checkpoints-weights, during the pretraining phase for better generalization. All models converted to ONNX format in test mode. All models picked based on speed and performance, e.g. could it be onnx converted and in what cpu inference speed while in onnx format. <br>\nBirdNet:<br>\nUsed the code and models from <a href=\"https://github.com/kahst/BirdNET-Analyzer\" target=\"_blank\">https://github.com/kahst/BirdNET-Analyzer</a> and used the latest V.2.3 tflite model for best test time speed. I could find 124 of the 264 competition birds in model and also some other interesting classes within the 3K BirdNet classes.<br>\nI used the BirdNet to create and use 4 models to the CNN ensemble.</p>\n<ol>\n<li>Classify and extract the 124 birds and also ~100 non-bird classes for further ensemble and testing.</li>\n<li>Used the same model’s embeddings to classify on a custom cls-head which I had pretrained on all the classes. Describe in the BirdNet code but I used another deeper architecture.</li>\n<li>Used the same model’s embeddings to classify on 5-fold XGB models which I had pretrained on all the classes with multi:softprob and aucpr metric.</li>\n<li>I concatenated the ensembled classes together with the non-bird classes and extracted which 5 second windows that had highest probabilities within the non-bird classes and reduced the probability by 50% in the 264 bird classes as it was either noisy or other sounds that might would reduce the like hood of a birdcall. Now, this was of no use in this metric but still interesting testing for other purpose and metrics 😊</li>\n</ol>\n<p>Then all CNNs and BirdNet variants where power averaged and weighted ensembled.<br>\nBelow is a progress for the competition metric with the different models/solutions. Not the same as the picked submissions but only another ensemble weight and also the best scored, so tested on that post deadline.</p>\n<p>Private – Public - Models</p>\n<p>.71621 – .81447 – Only CNNs<br>\n.72391 – .81885 – With CNNs + BirdNet classifier and extract the 124 birds.<br>\n.72250 – .81873 – With CNNs + BirdNet embeddings to classify on a custom cls-head which I had pretrained on all the classes.<br>\n.72459 – .81996 – With CNNs + BirdNet embeddings to classify on 5-fold XGB which I had pretrained on all the classes.<br>\n.73132 – .82337 – All above weighted ensembled.</p>\n<p><strong>That’s it!</strong></p>\n<hr>",
  "messages": [
    {
      "id": "2274015",
      "postDate": "05/25/2023 14:54:01",
      "content": "<p>Congrats to the winners and also to the host that create these annual competitions. 👌</p>\n<p><strong>Summary of the solution</strong></p>\n<p>Inference with 12 models all together within the 2 hours CPU inference window.</p>\n<p>5 different Tensorflow CNN, SOTA techniques trained with previous competition data and finetuned with current data, post ONNX converted. Ensembled together with: 1. The latest BirdNet TFlite version with 124 of the 264 birds. 2. custom classification TF head trained with Birdnet embeddings on competition data. 3. XGB 5 fold trained with Birdnet embeddings on competition data. Also used the non-bird classes from Birdnet to reduce the probabilities with 50% over the birds if the non-birds classes had higher probability in 5 seconds window, nothing of use here but interesting to implement.</p>\n<p><strong>Training and data</strong></p>\n<p>As starter code I used <a href=\"https://www.kaggle.com/awsaf49\" target=\"_blank\">@awsaf49</a> <a href=\"https://www.kaggle.com/code/awsaf49/birdclef23-pretraining-is-all-you-need-train\" target=\"_blank\">https://www.kaggle.com/code/awsaf49/birdclef23-pretraining-is-all-you-need-train</a>. Tensorflow based TPU training with W&amp;B logging and latest SOTA audio techniques, SpecAug like Time Freq masking and Audio Augmentation like Gaussian Noise, Random CropPad, CutMix and MixUp.</p>\n<blockquote>\n  <p>Methodology 🎯<br>\n  In this notebook, we will explore how to identify bird calls using TensorFlow. Specifically, this notebook will cover:<br>\n  How to use tf.data for audio processing tasks and reading .ogg files in TensorFlow<br>\n  How to extract spectrogram features from raw audio on TPU/GPU, which reduces CPU bottleneck significantly, speeding up the process by ~ 4×on P100 GPU compared to the previous notebook.<br>\n  Unlike the previous tutorial, this notebook will perform spectrogram augmentation such as TimeFreqMask and Normalization on GPU/TPU and perform CutMix and MixUp with audio data on CPU.<br>\n  This notebook demonstrates how pre-training on the BirdCLEF - 2020, 2021, 2022 &amp; Xeno-Canto Extend dataset can improve transfer learning performance. CNN backbones, like EfficientNet, struggle with spectrogram data even with ImageNet pre-trained weights as they are not fimilar with audio data. Pre-training on an audio dataset, like BirdCLEF, can mitigate this issue and can yield a ~ 5% improvement in local validation and ~ 2% improvement in leaderboard. This notebook is compatible with both GPU, TPU, and the newly launched TPU-VM device is automatically selected, so you won't have to do anything to allocate the device.</p>\n</blockquote>\n<p>Credit to <a href=\"https://www.kaggle.com/awsaf49\" target=\"_blank\">@awsaf49</a> </p>\n<p><strong>Inference and submissions</strong></p>\n<p>TF CNN models trained and used: <br>\nEfficientnetb1, Eficientnetb0, Efficientnetv1b1ns, Efficientnetv2m, Efficientnetv2s – some trained with all the data some in single fold, many also trained/saved with weighted average over 2-5 checkpoints-weights, during the pretraining phase for better generalization. All models converted to ONNX format in test mode. All models picked based on speed and performance, e.g. could it be onnx converted and in what cpu inference speed while in onnx format. <br>\nBirdNet:<br>\nUsed the code and models from <a href=\"https://github.com/kahst/BirdNET-Analyzer\" target=\"_blank\">https://github.com/kahst/BirdNET-Analyzer</a> and used the latest V.2.3 tflite model for best test time speed. I could find 124 of the 264 competition birds in model and also some other interesting classes within the 3K BirdNet classes.<br>\nI used the BirdNet to create and use 4 models to the CNN ensemble.</p>\n<ol>\n<li>Classify and extract the 124 birds and also ~100 non-bird classes for further ensemble and testing.</li>\n<li>Used the same model’s embeddings to classify on a custom cls-head which I had pretrained on all the classes. Describe in the BirdNet code but I used another deeper architecture.</li>\n<li>Used the same model’s embeddings to classify on 5-fold XGB models which I had pretrained on all the classes with multi:softprob and aucpr metric.</li>\n<li>I concatenated the ensembled classes together with the non-bird classes and extracted which 5 second windows that had highest probabilities within the non-bird classes and reduced the probability by 50% in the 264 bird classes as it was either noisy or other sounds that might would reduce the like hood of a birdcall. Now, this was of no use in this metric but still interesting testing for other purpose and metrics 😊</li>\n</ol>\n<p>Then all CNNs and BirdNet variants where power averaged and weighted ensembled.<br>\nBelow is a progress for the competition metric with the different models/solutions. Not the same as the picked submissions but only another ensemble weight and also the best scored, so tested on that post deadline.</p>\n<p>Private – Public - Models</p>\n<p>.71621 – .81447 – Only CNNs<br>\n.72391 – .81885 – With CNNs + BirdNet classifier and extract the 124 birds.<br>\n.72250 – .81873 – With CNNs + BirdNet embeddings to classify on a custom cls-head which I had pretrained on all the classes.<br>\n.72459 – .81996 – With CNNs + BirdNet embeddings to classify on 5-fold XGB which I had pretrained on all the classes.<br>\n.73132 – .82337 – All above weighted ensembled.</p>\n<p><strong>That’s it!</strong></p>\n<hr>",
      "rawMarkdown": "Congrats to the winners and also to the host that create these annual competitions. 👌\n\n**Summary of the solution**\n\nInference with 12 models all together within the 2 hours CPU inference window.\n\n5 different Tensorflow CNN, SOTA techniques trained with previous competition data and finetuned with current data, post ONNX converted. Ensembled together with: 1. The latest BirdNet TFlite version with 124 of the 264 birds. 2. custom classification TF head trained with Birdnet embeddings on competition data. 3. XGB 5 fold trained with Birdnet embeddings on competition data. Also used the non-bird classes from Birdnet to reduce the probabilities with 50% over the birds if the non-birds classes had higher probability in 5 seconds window, nothing of use here but interesting to implement.\n\n**Training and data**\n\nAs starter code I used @awsaf49 https://www.kaggle.com/code/awsaf49/birdclef23-pretraining-is-all-you-need-train. Tensorflow based TPU training with W&B logging and latest SOTA audio techniques, SpecAug like Time Freq masking and Audio Augmentation like Gaussian Noise, Random CropPad, CutMix and MixUp.\n\n>Methodology 🎯\nIn this notebook, we will explore how to identify bird calls using TensorFlow. Specifically, this notebook will cover:\nHow to use tf.data for audio processing tasks and reading .ogg files in TensorFlow\nHow to extract spectrogram features from raw audio on TPU/GPU, which reduces CPU bottleneck significantly, speeding up the process by ~ 4×on P100 GPU compared to the previous notebook.\nUnlike the previous tutorial, this notebook will perform spectrogram augmentation such as TimeFreqMask and Normalization on GPU/TPU and perform CutMix and MixUp with audio data on CPU.\nThis notebook demonstrates how pre-training on the BirdCLEF - 2020, 2021, 2022 & Xeno-Canto Extend dataset can improve transfer learning performance. CNN backbones, like EfficientNet, struggle with spectrogram data even with ImageNet pre-trained weights as they are not fimilar with audio data. Pre-training on an audio dataset, like BirdCLEF, can mitigate this issue and can yield a ~ 5% improvement in local validation and ~ 2% improvement in leaderboard. This notebook is compatible with both GPU, TPU, and the newly launched TPU-VM device is automatically selected, so you won't have to do anything to allocate the device.\n\nCredit to @awsaf49 \n\n**Inference and submissions**\n\nTF CNN models trained and used: \nEfficientnetb1, Eficientnetb0, Efficientnetv1b1ns, Efficientnetv2m, Efficientnetv2s – some trained with all the data some in single fold, many also trained/saved with weighted average over 2-5 checkpoints-weights, during the pretraining phase for better generalization. All models converted to ONNX format in test mode. All models picked based on speed and performance, e.g. could it be onnx converted and in what cpu inference speed while in onnx format. \nBirdNet:\nUsed the code and models from https://github.com/kahst/BirdNET-Analyzer and used the latest V.2.3 tflite model for best test time speed. I could find 124 of the 264 competition birds in model and also some other interesting classes within the 3K BirdNet classes.\nI used the BirdNet to create and use 4 models to the CNN ensemble.\n1.\tClassify and extract the 124 birds and also ~100 non-bird classes for further ensemble and testing.\n2.\tUsed the same model’s embeddings to classify on a custom cls-head which I had pretrained on all the classes. Describe in the BirdNet code but I used another deeper architecture.\n3.\tUsed the same model’s embeddings to classify on 5-fold XGB models which I had pretrained on all the classes with multi:softprob and aucpr metric.\n4.\tI concatenated the ensembled classes together with the non-bird classes and extracted which 5 second windows that had highest probabilities within the non-bird classes and reduced the probability by 50% in the 264 bird classes as it was either noisy or other sounds that might would reduce the like hood of a birdcall. Now, this was of no use in this metric but still interesting testing for other purpose and metrics 😊\n\nThen all CNNs and BirdNet variants where power averaged and weighted ensembled.\nBelow is a progress for the competition metric with the different models/solutions. Not the same as the picked submissions but only another ensemble weight and also the best scored, so tested on that post deadline.\n\nPrivate – Public - Models\n\n.71621 – .81447 – Only CNNs\n.72391 – .81885 – With CNNs + BirdNet classifier and extract the 124 birds.\n.72250 – .81873 – With CNNs + BirdNet embeddings to classify on a custom cls-head which I had pretrained on all the classes.\n.72459 – .81996 – With CNNs + BirdNet embeddings to classify on 5-fold XGB which I had pretrained on all the classes.\n.73132 – .82337 – All above weighted ensembled.\n\n\n**That’s it!**\n\n------------------------------------------------",
      "votes": null
    },
    {
      "id": "2274068",
      "postDate": "05/25/2023 15:36:14",
      "content": "<p><a href=\"https://www.kaggle.com/kirderf\" target=\"_blank\">@kirderf</a> <br>\nThank you so much for sharing your 37th-place solution! It's great to see the collaborative spirit in the data science community</p>",
      "rawMarkdown": "kirderf \nThank you so much for sharing your 37th-place solution! It's great to see the collaborative spirit in the data science community",
      "votes": null
    },
    {
      "id": "2275043",
      "postDate": "05/26/2023 12:58:20",
      "content": "<p>Congrats. I could barely ensemble 2 TF CNN models (using onnx). If you don't mind asking what other trick did you use to ensemble 12 models? Converted them to TFlite?</p>",
      "rawMarkdown": "Congrats. I could barely ensemble 2 TF CNN models (using onnx). If you don't mind asking what other trick did you use to ensemble 12 models? Converted them to TFlite?",
      "votes": null
    },
    {
      "id": "2275081",
      "postDate": "05/26/2023 13:27:54",
      "content": "<p>It's 5 CNN Onnx rest is BirdNet TFlite but creates 7 models out of 1 BirdNet tflite output as I use the embeddings to the custom cls heads and the 5 XGB heads are fast. For the CNN I noticed that FSR made it less fast and different architectures are faster like Effv2 works perfect with ONNX in test time and for example Convnexts less faster and Nfnets I didn't manage to convert at all, but maybe it's different in Pytorch as this was in Tensorflow.</p>",
      "rawMarkdown": "It's 5 CNN Onnx rest is BirdNet TFlite but creates 7 models out of 1 BirdNet tflite output as I use the embeddings to the custom cls heads and the 5 XGB heads are fast. For the CNN I noticed that FSR made it less fast and different architectures are faster like Effv2 works perfect with ONNX in test time and for example Convnexts less faster and Nfnets I didn't manage to convert at all, but maybe it's different in Pytorch as this was in Tensorflow.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2274068,
      "author_name": "bilalwaseer",
      "author_url": "",
      "post_date": "05/25/2023 15:36:14",
      "content": "<p><a href=\"https://www.kaggle.com/kirderf\" target=\"_blank\">@kirderf</a> <br>\nThank you so much for sharing your 37th-place solution! It's great to see the collaborative spirit in the data science community</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 2275043,
      "author_name": "nymfree",
      "author_url": "",
      "post_date": "05/26/2023 12:58:20",
      "content": "<p>Congrats. I could barely ensemble 2 TF CNN models (using onnx). If you don't mind asking what other trick did you use to ensemble 12 models? Converted them to TFlite?</p>",
      "votes": null,
      "replies": [
        {
          "id": 2275081,
          "author_name": "kirderf",
          "author_url": "",
          "post_date": "05/26/2023 13:27:54",
          "content": "<p>It's 5 CNN Onnx rest is BirdNet TFlite but creates 7 models out of 1 BirdNet tflite output as I use the embeddings to the custom cls heads and the 5 XGB heads are fast. For the CNN I noticed that FSR made it less fast and different architectures are faster like Effv2 works perfect with ONNX in test time and for example Convnexts less faster and Nfnets I didn't manage to convert at all, but maybe it's different in Pytorch as this was in Tensorflow.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2274015": "Congrats to the winners and also to the host that create these annual competitions. 👌\n\n**Summary of the solution**\n\nInference with 12 models all together within the 2 hours CPU inference window.\n\n5 different Tensorflow CNN, SOTA techniques trained with previous competition data and finetuned with current data, post ONNX converted. Ensembled together with: 1. The latest BirdNet TFlite version with 124 of the 264 birds. 2. custom classification TF head trained with Birdnet embeddings on competition data. 3. XGB 5 fold trained with Birdnet embeddings on competition data. Also used the non-bird classes from Birdnet to reduce the probabilities with 50% over the birds if the non-birds classes had higher probability in 5 seconds window, nothing of use here but interesting to implement.\n\n**Training and data**\n\nAs starter code I used @awsaf49 https://www.kaggle.com/code/awsaf49/birdclef23-pretraining-is-all-you-need-train. Tensorflow based TPU training with W&B logging and latest SOTA audio techniques, SpecAug like Time Freq masking and Audio Augmentation like Gaussian Noise, Random CropPad, CutMix and MixUp.\n\n>Methodology 🎯\nIn this notebook, we will explore how to identify bird calls using TensorFlow. Specifically, this notebook will cover:\nHow to use tf.data for audio processing tasks and reading .ogg files in TensorFlow\nHow to extract spectrogram features from raw audio on TPU/GPU, which reduces CPU bottleneck significantly, speeding up the process by ~ 4×on P100 GPU compared to the previous notebook.\nUnlike the previous tutorial, this notebook will perform spectrogram augmentation such as TimeFreqMask and Normalization on GPU/TPU and perform CutMix and MixUp with audio data on CPU.\nThis notebook demonstrates how pre-training on the BirdCLEF - 2020, 2021, 2022 & Xeno-Canto Extend dataset can improve transfer learning performance. CNN backbones, like EfficientNet, struggle with spectrogram data even with ImageNet pre-trained weights as they are not fimilar with audio data. Pre-training on an audio dataset, like BirdCLEF, can mitigate this issue and can yield a ~ 5% improvement in local validation and ~ 2% improvement in leaderboard. This notebook is compatible with both GPU, TPU, and the newly launched TPU-VM device is automatically selected, so you won't have to do anything to allocate the device.\n\nCredit to @awsaf49 \n\n**Inference and submissions**\n\nTF CNN models trained and used: \nEfficientnetb1, Eficientnetb0, Efficientnetv1b1ns, Efficientnetv2m, Efficientnetv2s – some trained with all the data some in single fold, many also trained/saved with weighted average over 2-5 checkpoints-weights, during the pretraining phase for better generalization. All models converted to ONNX format in test mode. All models picked based on speed and performance, e.g. could it be onnx converted and in what cpu inference speed while in onnx format. \nBirdNet:\nUsed the code and models from https://github.com/kahst/BirdNET-Analyzer and used the latest V.2.3 tflite model for best test time speed. I could find 124 of the 264 competition birds in model and also some other interesting classes within the 3K BirdNet classes.\nI used the BirdNet to create and use 4 models to the CNN ensemble.\n1.\tClassify and extract the 124 birds and also ~100 non-bird classes for further ensemble and testing.\n2.\tUsed the same model’s embeddings to classify on a custom cls-head which I had pretrained on all the classes. Describe in the BirdNet code but I used another deeper architecture.\n3.\tUsed the same model’s embeddings to classify on 5-fold XGB models which I had pretrained on all the classes with multi:softprob and aucpr metric.\n4.\tI concatenated the ensembled classes together with the non-bird classes and extracted which 5 second windows that had highest probabilities within the non-bird classes and reduced the probability by 50% in the 264 bird classes as it was either noisy or other sounds that might would reduce the like hood of a birdcall. Now, this was of no use in this metric but still interesting testing for other purpose and metrics 😊\n\nThen all CNNs and BirdNet variants where power averaged and weighted ensembled.\nBelow is a progress for the competition metric with the different models/solutions. Not the same as the picked submissions but only another ensemble weight and also the best scored, so tested on that post deadline.\n\nPrivate – Public - Models\n\n.71621 – .81447 – Only CNNs\n.72391 – .81885 – With CNNs + BirdNet classifier and extract the 124 birds.\n.72250 – .81873 – With CNNs + BirdNet embeddings to classify on a custom cls-head which I had pretrained on all the classes.\n.72459 – .81996 – With CNNs + BirdNet embeddings to classify on 5-fold XGB which I had pretrained on all the classes.\n.73132 – .82337 – All above weighted ensembled.\n\n\n**That’s it!**\n\n------------------------------------------------",
    "2274068": "kirderf \nThank you so much for sharing your 37th-place solution! It's great to see the collaborative spirit in the data science community",
    "2275043": "Congrats. I could barely ensemble 2 TF CNN models (using onnx). If you don't mind asking what other trick did you use to ensemble 12 models? Converted them to TFlite?",
    "2275081": "It's 5 CNN Onnx rest is BirdNet TFlite but creates 7 models out of 1 BirdNet tflite output as I use the embeddings to the custom cls heads and the 5 XGB heads are fast. For the CNN I noticed that FSR made it less fast and different architectures are faster like Effv2 works perfect with ONNX in test time and for example Convnexts less faster and Nfnets I didn't manage to convert at all, but maybe it's different in Pytorch as this was in Tensorflow."
  },
  "source": "meta"
}