203 測定値

「Machine Learning for the Birds: Building Your Own Bird Vocalization Classifiers」

Picture in the Noise20m2025/06/09
Read on Terminal Reader

長すぎる; 読むには

BirdCLEF+ 2025 コンテストは、オーディオ レコーディングから鳥の種類を正確に予測できる分類モデルを設計することにユーザーに挑戦します。このガイドは、より幅広い種類の鳥を分類するために GBV 分類と一緒に使用できる独自の鳥の声の分類を構築する方法を詳細に説明します。
featured image - 「Machine Learning for the Birds: Building Your Own Bird Vocalization Classifiers」
Picture in the Noise HackerNoon profile picture
0-item

導入

科学者は、大規模な生態系を研究するために自動化されたシステムを使用しています。autonomous recording units (ARUs)この情報は、特定の環境内の種の分布をよりよく理解するために使用することができる動物や昆虫の異なる種の識別に役立つために使用できるオーディオを録音するために使用されます。Birdsong in the Wild for Classification(野生の鳥の歌)「生態学者は、鳥類を用いて食料システムや森林の健康を理解する――例えば、森林に木を採る人が多いということは、死んだ木がたくさんあることを意味する」さらに、彼らはオーディオベースの識別の価値を指摘する:「鳥類は、歌や呼びかけで領土を伝達し、識別するので、耳で識別することが最も効率的です。

Birdsong in the Wild for Classification(野生の鳥の歌)

最近、Theバードクリーフ+2025競争開始中Kaggle雨傘の下で、イラストImageCLEFは、さまざまな分野におけるクロス言語の注釈と画像の取得の調査を支援します。コンテストの目的は、オーディオ録音から鳥の種を正確に予測できる分類モデルを設計することです。

バードクリーフ+2025イラスト

最初に、このタスクは、その利用可能性を考慮して、微妙なもののように見えます。Google Bird Vocalization(GBV), also known asPerchGBV分類は約11000種の鳥類に訓練されており、分類モデルとして明らかな選択肢である。

Google Bird Vocalization(GBV)

しかし、コンテストには、GBV分類機の訓練セット以外の鳥種が含まれています. その結果、GBV分類機は、BirdCLEF+ 2025競技試験データセットで ~60%の精度しか達成できません. その結果、カスタムモデルを開発する必要があります.

このガイドでは、独自の鳥の声化分類機構を構築する方法を詳細に説明し、GBV分類機構と併用して、より幅広い種類の鳥を分類することができます。記事上記のデザインは、BirdCLEF+ 2025コンテストデータセットを活用してトレーニングを行っています。

トレーニングデータ

THEBirdCLEF+ 2025 トレーニングデータセットサポートファイルを含め、約12GBです。データセット構造を構成する主要なディレクトリとファイルは次のとおりです。

birdclef_2025
|__ train_audio
|__ train_soundscapes
|__ test_soundscapes
recording_location.txt
taxonomy.csv
train.csv

train_audio

THEtrain_audioディレクトリは、データセットの最大のコンポーネントで、28,564のトレーニングオーディオレコーディングレコーディングを含む。.oggオーディオレコーディングは、それぞれ特定の鳥種を表すサブディレクトリにグループ化されています。

train_audio
|__amakin1
   |__ [AUDIO FILES]
|__amekes
   |__ [AUDIO FILES]
...

THEtaxonomy.csvファイルは、サブディレクトリ名によって表される鳥種の実際の科学的および一般的な名前を検索するために使用できます。

SUB-DIRECTORY NAME          SCIENTIFIC NAME             COMMON NAME
amakin1                     Chloroceryle amazona        Amazon Kingfisher
amekes                      Falco sparverius            American Kestrel
...


Amazon Kingfisher


American Kestrel

コンテストのデータセットには、ユニークな鳥種206種類、すなわち206クラスが含まれています。Introduction63のクラスは、ノーcovered by theGBV ClassifierこれらNon-GBVクラスは通常、数値クラス識別子を使用してラベル化されます。


1139490, 1192948, 1194042, 126247, 1346504, 134933, 135045, 1462711, 1462737, 1564122, 21038, 21116, 21211, 22333, 22973, 22976, 24272, 24292, 24322, 41663, 41778, 41970, 42007, 42087, 42113, 46010, 47067, 476537, 476538, 48124, 50186, 517119, 523060, 528041, 52884, 548639, 555086, 555142, 566513, 64862, 65336, 65344, 65349, 65373, 65419, 65448, 65547, 65962, 66016, 66531, 66578, 66893, 67082, 67252, 714022, 715170, 787625, 81930, 868458, 963335, grasal4, verfly, y00678

いくつかのTheNon-GBVクラスは特徴:

  1. Limited training data.
    • Class 1139490, for example, only contains 2 audio recordings. By contrast, class amakin1, which is a “known” GBV class, contains 89 recordings.
  2. Poor recording quality.
    • Highlighting class 1139490 again, both training recordings are of poor quality with one being particularly difficult to discern.

これらの2つの条件は、利用可能なオーディオおよびオーディオ品質の量に関してクラス間で大きな不均衡をもたらします。

オーディオレコーディングのレコーディングは両方GBVそしてNon-GBVクラスには人間の言葉も含まれ、スピーカーは録音を記録された鳥の種や録音の場所などの詳細で注釈します。しかし、すべてではない例では、注釈は記録された鳥の音声に従います。

階級の不均衡と人間の言語の注釈の存在に対処するための戦術は、Building the Classifierセクション

train_soundscapes

THEtrain_soundscapesディレクトリは約1万unlabeledオーディオ録音の鳥の歌. As will be discussed in theBuilding the Classifierセクションでは、これらのオーディオレコーディングは、トレーニングデータに組み込むことができます。pseudo-labeling.

test_soundscapes

The test_soundscapesDirectory is empty except for areadme.txtこのディレクトリは、BirdCLEF+ 2025 コンテストに予測結果を提出する際に隠されたテストオーディオのセットで満たされています。

CLASSIFIERの構築

基本的なアプローチと背景

使用する基本的なアプローチGoogle 調査鳥の声の分類を訓練するには、以下の通りです。

  1. 録音したオーディオを5秒のセグメントに分ける。
  2. オーディオセグメントをMELスペクトログラムに変換します。
  3. メルスペクトログラムの画像分類器を訓練する。

同じアプローチがこのガイドに従うでしょう. トレーニングされる画像分類器はGoogleの効率化B0モデル:もしあなたが知り合いだったらEfficientNetモデルのファミリー、あなたは彼らが効率的な画像処理のために設計されたことを知っています。

効率化B0

しかし、オーディオサンプルが分割され、メルスペクトログラムに変換される前に、我々はクラス不均衡と人間の注釈の問題に取り組む必要があります。Training Data幅広く、これらの問題は、データ拡張とオーディオサンプルの切断を通じてそれぞれ解決されます。

実際のデザインに潜入する前に、次のサブセクションは、いくつかの短い背景情報を提供します。

効率モデル

Google Researchが家族を紹介EfficientNet2019年のモデルは、SET OFconvolutional neural network当時、サイズとパフォーマンスの両方に関して、最先端のモデルを超えたモデル。


EfficientNet model family performance

効率22021年にリリースされたモデルは、パフォーマンスとパラメータ効率をさらに向上させます。

訓練されているにもかかわらず、イラストデータ、EfficientNetモデルは、他のデータセットに移行する際に有用性を示し、このプロジェクトの分類技術として魅力的な選択肢となっています。

メル・スペクトログラム

A mel spectrogram is a visual representation of an audio signal. It might best be analogized to a heatmap for sound. メルスペクトログラムは、オーディオ信号の視覚的表現であり、音のための熱地図に最もよく類似される可能性があります。


Sample mel spectrogram

メルスペクトログラムのx軸はオーディオ信号の時間次元を表し、y軸は信号内の音の周波数を表します。mel bandsこれらのバンドは、反対に、使用するスペースを外します。mel scaleメル・スケールはAlogarithmic人間の聴覚システムと、人間がどのように音を感知するかを比較するスケールです. ミルスペクトログラムの色は、帯域内の音の幅を表します. 明るい色は、より高い幅を表し、暗い色は、より低い幅を表します.

デザイン

デザインを論じる私の目標は、あまりにも細部に突入せずにアプローチの高レベルのレビューを提供することです。カグレノブ「トレーニングノート」は、以下の4つの主要セクションで構成されています。

  • セクション1:オーディオデータのロード
  • 第2章 オーディオデータの処理
  • セクション3:Melのスペクトログラム生成と入力準備。
  • 第4章 モデルトレーニング

各メインセクションの最初の 2 つのセルは (1)そのセクションで使用される輸入および (2) aConfigこのセクションおよびその後のセクションで使用される常数を定義するセル。

トレーニングノートは実際に始まります。Section 0ノートブック全体で使用される基本的な Python パッケージがインポートされる場所 このセクションには、ログインするための論理も含まれています。Weights & Biases("WandB") for tracking training runs. あなたは自分のWandBを付加する必要がありますAPI keyノートとしてAKaggle Secret using the name WANDB_API_KEY.

で議論されたように、Training Dataセクションでは、ラベルなしのトレーニングサウンドキャップは、偽のラベル化を介してトレーニングデータに組み込まれることができます。Section 3.5 - Pseudo-LabelingKaggle 非 GPU 環境は 30 GiB のメモリに制限されていることに留意してください。

次のサブセクションで説明された実験的な設定に従って訓練されたモデルがここにKaggleに投稿されました. 望むなら、あなたは自分の訓練なしでこのモデルを使用し、鳥の歌のオーディオで推論を実行するためにRunning Inferenceセクションに直接ジャンプすることができます。

次のサブセクションで説明された実験的な設定に従って訓練されたモデルがここにKaggleに投稿されました. 望むなら、あなたは自分の訓練なしでこのモデルを使用し、鳥の歌のオーディオで推論を実行するためにRunning Inferenceセクションに直接ジャンプすることができます。

セクション1 - オーディオデータのロード

THEAudio Data Loadingノートの部分:

  1. GBV分類に含まれていないBirdCLEF+ 2025コンテストデータセットのクラスを抽出します。
  2. load_training_audio メソッドでオーディオデータをロードします。
  3. processed_audio ディレクトリを作成し、ロードされたオーディオデータのコピーをそのディレクトリに .wav ファイルとして保存します。

THEConfigこのセクションのセクションはAMAX_FILESconstant. This constant specifies the maximum number of audio files to be loaded from a given class. この Constant は任意に大きな値に設定されます。1000すべてのオーディオファイルがインストールされていることを確認するためにnon-GBVクラス. この常数を自分の実験設定で調整する必要がある場合があります. たとえば、オーディオデータをallクラスでは、この常数を低い値に設定する必要がある場合がありますので、利用可能なメモリを枯渇させないようにします。

THEload_training_audio方法はAと呼ぶことができます。classesこのパラメータは、オーディオがロードされるクラスのリストです。non-GBVクラスはリストとして保存され、変数に割り当てられます。missing_classesその後、引き継がれるのは、load_training_audio方法を通してTheclassesパラメータ

# `missing_classes` list
['1139490', '1192948', '1194042', '126247', '1346504', '134933', '135045', '1462711', '1462737', '1564122', '21038', '21116', '21211', '22333', '22973', '22976', '24272', '24292', '24322', '41663', '41778', '41970', '42007', '42087', '42113', '46010', '47067', '476537', '476538', '48124', '50186', '517119', '523060', '528041', '52884', '548639', '555086', '555142', '566513', '64862', '65336', '65344', '65349', '65373', '65419', '65448', '65547', '65962', '66016', '66531', '66578', '66893', '67082', '67252', '714022', '715170', '787625', '81930', '868458', '963335', 'grasal4', 'verfly', 'y00678']

クラスパラメーターとして空のリストを渡すことで、すべての 206 BirdCLEF+ 2025 クラスをロードできます。

You can load all 206 BirdCLEF+ 2025 classes by passing an empty list as theclassesパラメータ


load_training_audio method also accepts an optional boolean use_slice parameter. This parameter works with the LOAD_SLICE constant defined in the Config cell. The use_slice parameter and LOAD_SLICE constant are not used with this implementation. However, they can be used to load a specific amount of audio from each file. For example, to load only 5 seconds of audio from each audio file, set LOAD_SLICE to 160000, which is calculated as 5 times the sampling rate of 32000; and pass True to the use_slice parameter. このパラメータは、Config セルで定義された LOAD_SLICE 常数で動作します。

THEload_training_audiomethod also accepts an optional booleanuse_sliceパラメータ: このパラメータは、LOAD_SLICE常に定義されている「theConfigセル・ザ・use_sliceパラメータおよびLOAD_SLICE絶え間なくnotただし、各ファイルから特定のオーディオの量をロードするために使用することができます. たとえば、各オーディオファイルからオーディオの5秒だけをロードするには、LOAD_SLICE2位160000, which is calculated as5times the sampling rate of サンプルレート32000; and passTrue2 THEuse_sliceパラメータ

THEload_training_audioMethod Accepts a Boolean(ボーレアン)make_copyこのパラメーターがTrue論理は創造する aprocessed_audioディレクトリを保存し、各オーディオサンプルのコピーをA.wavfile to the directory. オーディオコピーは、それらが属するクラスを反映するサブディレクトリに保存されます。processed_audioディレクトリは次のセクションで、変更されたオーディオサンプルを BirdCLEF+ 2025 データセットディレクトリに影響を与えずにディスクに保存するために使用されます。


THEload_training_audioキーとしてクラス名を使用したロードされたオーディオデータの辞書を返します. each value in the dictionary is a list of tuples of the form(AUDIO_FILENAME, AUDIO_DATA):

{'1139490': [('CSA36389.ogg', tensor([[-7.3379e-06,  1.0008e-05, -8.9483e-06,  ...,  2.9978e-06,
3.4201e-06,  3.8700e-06]])), ('CSA36385.ogg', tensor([[-2.9545e-06,  2.9259e-05,  2.8138e-05,  ..., -5.8680e-09, -2.3467e-09, -2.6546e-10]]))], '1192948': [('CSA36388.ogg', tensor([[ 3.7417e-06, -5.4138e-06, -3.3517e-07,  ..., -2.4159e-05, -1.6547e-05, -1.8537e-05]])), ('CSA36366.ogg', tensor([[ 2.6916e-06, -1.5655e-06, -2.1533e-05,  ..., -2.0132e-05, -1.9063e-05, -2.4438e-05]])), ('CSA36373.ogg', tensor([[ 3.4144e-05, -8.0636e-06,  1.4903e-06,  ..., -3.8835e-05, -4.1840e-05, -4.0731e-05]])), ('CSA36358.ogg', tensor([[-1.6201e-06,  2.8240e-05,  2.9543e-05,  ..., -2.9203e-04, -3.1059e-04, -2.8100e-04]]))], '1194042': [('CSA18794.ogg', tensor([[ 3.0655e-05,  4.8817e-05,  6.2794e-05,  ..., -5.1450e-05,
-4.8535e-05, -4.2476e-05]])), ('CSA18802.ogg', tensor([[ 6.6640e-05,  8.8530e-05,  6.4143e-05,  ...,  5.3802e-07, -1.7509e-05, -4.8914e-06]])), ('CSA18783.ogg', tensor([[-8.6866e-06, -6.3421e-06, -3.1125e-05,  ..., -1.7946e-04, -1.6407e-04, -1.5334e-04]]))] ...}

The method also returns basic statistics describing the data loaded for each class as a comma-separated-value string. You can optionally export these statistics to inspect the data.

class,sampling_rate,num_files,num_secs_loaded,num_files_loaded
1139490,32000,2,194,2
1192948,32000,4,420,4
1194042,32000,3,91,3
...

Section 2 - Audio Data Processing

THEAudio Data Processingノートの部分:

  1. Optionally strips silent segments and slices audio to eliminate most human annotations from raw audio. Stripping silent segments eliminates irrelevant parts of the audio signal.
  2. Optionally augments audio for minority classes to help address the class imbalance. Audio augmentation consists of (1) adding a randomly generated noise signal, (2) changing the tempo of the raw audio, or (3) adding a randomly generated noise signal and changing the tempo of the raw audio.
セクション 2.1 - 静かなセグメントの検出

The detect_silence method is used to "slide" over each raw audio sample and identify silent segments by comparing the root-mean square (RMS) value of a given segment to a specified threshold. If the RMS is below the threshold, the segment is identified as a silent segment. The following constants specified in the Configこのセクションのセルは、このセクションの行動を制御します。detect_silence method:

SIL_FRAME_PCT_OF_SR = 0.25
SIL_FRAME = int(SR * SIL_FRAME_PCT_OF_SR)
SIL_HOP = int(1.0 * SIL_FRAME)
SIL_THRESHOLD = 5e-5
SIL_REPLACE_VAL = -1000 # Value used to replace audio signal values within silent segments

THESIL_FRAMEそしてSIL_HOP constants can be modified to adjust how the method "slides" over the raw audio. Similarly, the SIL_THRESHOLD value can be modified to make the method more aggressive or conservative with respect to identification of silent segments.

The method outputs a dictionary of silent segment markers for each file in each class. Audio files with no detected silent segments are identified by empty lists.

{'1139490': {'CSA36389.ogg': [0, 8000, 16000, 272000, 280000, 288000, 296000, 304000], 'CSA36385.ogg': [0, 8000, 16000, 24000, 240000, 248000, 256000]}, '1192948': {'CSA36388.ogg': [0, 8000, 16000, 24000, 256000, 264000, 272000, 288000], 'CSA36366.ogg': [0, 8000, 16000, 24000, 256000, 264000, 272000, 280000, 288000], 'CSA36373.ogg': [0, 8000, 16000, 24000, 256000, 264000, 272000, 288000], 'CSA36358.ogg': [8000]}, '1194042': {'CSA18794.ogg': [], 'CSA18802.ogg': [], 'CSA18783.ogg': [0, 8000, 16000, 24000, 600000, 608000, 616000]}, '126247': {'XC941297.ogg': [], 'iNat1109254.ogg': [], 'iNat888527.ogg': [], 'iNat320679.ogg': [0], 'iNat888729.ogg': [], 'iNat146584.ogg': []}, '1346504': {'CSA18803.ogg': [0, 8000, 16000, 24000, 3000000, 3008000, 3016000], 'CSA18791.ogg': [], 'CSA18792.ogg': [], 'CSA18784.ogg': [0, 8000, 16000, 1232000, 1240000, 1248000], 'CSA18793.ogg': [0, 8000, 16000, 24000, 888000]} ...}
Section 2.2 - Removing Silent Segments and Eliminating Human Annotations

The USE_REMOVE_SILENCE_AND_HUMAN_ANNOT常に定義されている「theConfig cell of this section specifies if audio should be stripped of silent segments そして sliced to remove トップ人間の注釈

USE_REMOVE_SILENCE_AND_HUMAN_ANNOT = True

THEremove_silence_and_human_annot method strips silent segments from audio samples using the output from the detect_silenceさらに、単純な観察に基づいて人間の注釈を処理するための論理を実装する:多くのオーディオサンプル、すなわち人間の注釈を持つサンプル、テント to have the following structure:

|  < 10s   |   ~1s   |                  |
| BIRDSONG | SILENCE | HUMAN ANNOTATION |

The birdsong and human annotation sections themselves may contain silent segments. However, as seen in the diagram above, the bird vocalization recordings often occur within the first few seconds of audio. Therefore, a simple, if imperfect, approach to deal with human annotations is to slice audio samples at the first silent segment marker that occurs outside of a specified window, under the assumption that a human annotation follows that silent segment. The remove_silence_and_human_annot logic uses the ANNOT_BREAKPOINT constant in the Config cell to check if a silent segment marker lies outside the window specified by ANNOT_BREAKPOINT, expressed in number of seconds. If it does, the logic slices the raw audio at that marker and only retains the data that occurs before it. A manual inspection of processed audio during experimentation revealed this approach to be satisfactory. However, as mentioned in the Training Dataセクション: There Aresomeオーディオ録音は、人間の注釈がprecedesオリジナルタイトル: The Logic Described Hereノーいくつかのオーディオサンプルには、記録された鳥の歌の長いシーケンスがあり、これらのサンプルはしばしば静かなセグメントを持っていない。

A second constant, SLICE_FRAME, can be optionally used in a final processing step to return an even more refined slice of the processed audio. Set SLICE_FRAME to the number of seconds of processed audio that you want to retain.

THEremove_silence_and_human_annotメソッドは、処理されたオーディオをディスクにディレクトリの下に保存します。processed_audio via the save_audioパラメーター: Passed asTrueThe method returns a dictionary of thetotal seconds of processed audio for each class.

{'1139490': 14, '1192948': 29, '1194042': 24, '126247': 48, '1346504': 40, '134933': 32, '135045': 77, ...}

The get_audio_stats method is used following remove_silence_and_human_annotすべてのクラスでオーディオの平均秒数を得るために。

Section 2.3 - Calculating Augmentation Turns for Minority Classes

で述べたように、TheTraining Data section, the classes are not balanced. Augmentation is used in this notebook section to help address the imbalance leveraging the average number of seconds of audio across all classes, as provided by the get_audio_statsmethod. Classes with total seconds of processed audio. 処理されたオーディオの合計秒数を含むクラスbelow平均値は増えていますが、get_augmentation_turns_per_class method determines the number of augmentation turns for each minority class using the average number of seconds per processed audio sample.

TURNS = (AVG_SECS_AUDIO_ACROSS_CLASSES - TOTAL_SECS_AUDIO_FOR_CLASS)/AVG_SECS_PER_AUDIO_SAMPLE

平均を下回る少数階級は、平均に近い少数階級に比べ、増加回数が少なくなる。

get_augmentation_turns_per_class には、AVG_SECS_FACTOR 常数が含まれています。

average number of seconds of audio across all classes. The constant can be used to make the logic more conservative or aggressive when calculating the number of augmentation turns.

The get_augmentation_turns_per_class includes a AVG_SECS_FACTOR値を調整するために使用できる常数

average number of seconds of audio across all classes. The constant can be used to make the logic more conservative or aggressive when calculating the number of augmentation turns.

セクション 2.4 - Running Augmentations

The USE_AUGMENTATIONS常に定義されている「theConfigこのセクションのセルは、オーディオを拡大するかどうかを指定します。

USE_AUGMENTATIONS = True

前述したように、オーディオ増加は、(1)ランダムに生成されたノイズ信号を追加すること、(2)原音のテンポを変更すること、または(3)ランダムに生成されたノイズ信号を追加し、原音のテンポを変更することから構成されます。add_noise and change_tempo methods encapsulate the logic for adding a noise signal and changing the tempo respectively. The noise signal range and tempo change range can be adjusted via the following constants in the Config cell:

NOISE_RNG_LOW = 0.0001
NOISE_RNG_HIGH = 0.0009
TEMPO_RNG_LOW = 0.5
TEMPO_RNG_HIGH = 1.5

The run_augmentations method runs the augmentations using the output from the get_augmentations_turns_per_classmethod. For those classes that will be augmented, the logic: 拡大されるクラスのための論理:

  1. Randomly selects a processed audio sample (i.e. silent segments already removed) for augmentation.
  2. (1)ノイズを追加し、(2)ペースを変更し、または (3)ノイズを追加し、ペースを変更する。
  3. Saves the augmented audio to disk under the appropriate class within the processed_audio directory.

While the notebook logic augments minority classes with total seconds of audio below the average, it ignores those classes with total seconds of audio above the average. This approach was taken to manage available memory and with the understanding that the class imbalance is further addressed through choice of the loss function.

Section 3 - Mel Spectrogram Generation and Input Preparation

THEMel Spectrogram Generation and Input Preparationノートの部分:

  1. 処理されたオーディオデータをトレーニングと検証リストに分割します。
  2. オーディオを5秒のフレームに分ける。
  3. 毎秒5秒のオーディオフレームに対してメルスペクトログラムを生成します。
  4. Resizes mel spectrograms to a target size of (224, 224).
  5. 選択肢として、プセドラベル化されたデータサンプルをロードしてトレーニングデータを拡大します。
  6. One-hot encodes training data and validation data labels.
  7. Constructs TensorFlow Dataset objects from training and validation data lists.
  8. Optionally uses MixUp logic to augment training data.
セクション 3.1 - 処理されたオーディオデータの分割

Processed audio data is loaded from the processed_audio folder. The data is split into 4 lists:

training_audio
training_labels
validation_audio
validation_labels

ラベルは、もちろん、オーディオ例と関連するクラス名です。SPLIT constant defined in the Config cell controls the split ratio between the training and validation data lists. Processed audio data is shuffled before splitting.

Section 3.2 - オーディオをフレームに分割する

Audio is split into 5 second segments using the frame_audioTensorFlow を使用する方法signal.frameそれぞれの音声例を分割する方法. The following constants in theConfig細胞は、分割操作を制御します。

FRAME_LENGTH = 5
FRAME_STEP = 5
セクション3.3 - Mel Spectrogramsの生成

Mel spectrograms are generated for each 5 second audio frame generated in Section 3.2経由 Theaudio2melspec方法. The following constants in theConfig cell specify the parameters used when generating the mel spectrograms, such as the number of mel bands, minimum frequency, and maximum frequency:

# Mel spectrogram parameters
N_FFT = 1024  # FFT size
HOP_SIZE = 256
N_MELS = 256
FMIN = 50  # minimum frequency
FMAX = 14000 # maximum frequency

The frequency band was chosen to reflect the potential range of most bird vocalizations. However, some bird species can vocalize outside this range.

セクション 3.4 - メル・スペクトログラムの再構築

THEto_melspectrogram_image method is used to convert each mel spectrogram to a pillow Image対象:各Image object is subsequently resized to (224, 224)EfficientNet B0 モデルで期待される入力サイズです。

Section 3.5 - Loading Pseudo-Labeled Data

で述べたように、TheTraining Dataセクション、Thetrain_soundscapesディレクトリは約1万unlabeled鳥の歌の音声レコーディング これらの音声レコーディングは、トレーニングデータに組み込むことができます。pseudo-labeling. A simple process to create pseudo-labeled data is as follows:

  • Train a classifier without pseudo-labeled data.
  • Load training soundscape audio files.
  • Segment each audio soundscape into 5 second frames.
  • 毎回5秒のフレームでミルスペクトログラムを生成し、サイズを変更する(224、224)。
  • あなたが最初のステップで訓練した分類器を使用して、それぞれのリメイクされたミルスペクトログラムで予測を実行します。
  • 予測を望ましい信頼レベル以上に保ち、予測されたクラスラベルの下でディスクにそれらの予測のためのメルスペクトログラムを保存します。
  • Psuedo-labeled データを使用して再度分類をトレーニングします。

Pseudo-labeled data can improve the performance of your classifier. If you want to generate your own pseudo-labeled data, you should continue with the remaining sections to train a classifier. Pseudo-labeled data can improve the performance of your classifier. あなたが自分の Pseudo-labeled dataを生成したい場合は、残りのセクションでトレーニングする必要があります。なしpseudo-labeled data. Then, use your classifier to create your own set of pseudo-labeled data using the process outlined above. 最後に、あなたの pseudo-labeled data を使用してあなたの classifier を再トレーニングします。

この実装では、偽のラベル化されたデータは使用されていません。しかし、参考にした推測ノートを変更できます。Running Inference section to generate pseudo-labeled data.

Set theUSE_PSEUDO_LABELSconstant in theConfig cell to False to skip the use of pseudo-labeled data.

セクション 3.6 - コードラベル

The process_labelsOne-hot coded labels are returned as NumPy array and added to the training label and validation label lists. One-hot coded labels are returned as NumPy array and added to the training label and validation label lists. One-hot coded labels are returned as NumPy array and added to the training label and validation label lists.

セクション 3.7 - トレーニングおよび検証データリストをTensorFlowに変換するDataset物体
Dataset

TensorFlowについてdata.Dataset.from_tensor_slicesTensorFlow を作成する方法Datasetトレーニングおよび検証データリストからのオブジェクト。Theshuffleトレーニングに呼ばれる方法Datasetshuffle training data before batching. トレーニングデータをバッチする前に shufflebatch method is called on both Dataset objects to batch the training and validation datasets. The BATCH_SIZEconstant in theConfigcell は batch サイズを制御します。

セクション 3.8 - MixUp を使用してトレーニングデータを増やす

あなたがすでに知っているように、MixUpは、2つの画像を効果的に混合して新しいデータサンプルを作成するデータ拡張技術です。mix_up method, along with the sample_beta_distribution method, encapsulates the optional MixUp logic.

この実装では、MixUp を使用してトレーニングデータを拡張します。USE_MIXUP constant in the Configセル2True.

Section 4 - Model Training

The Model Trainingノートの部分:

  1. WandB プロジェクトを初期化および構成し、トレーニング実行データをキャプチャします。
  2. EfficientNet B0 モデルを構築し、コンパイルします。
  3. Trains the model.
  4. Saves the trained model to disk.
セクション 4.1 - Initializing and Configuring WandB Project

ノートブックに独自の WandB API キーを Kaggle Secret として付属し、ノートブックのセクション 0 の WandB ログイン方法が True を返したことを確認します。

自分のWandB API キーを A として付属していることを確認します。Kaggle Secret to the notebook and that the WandB login method in Section 0ノートが戻ってきました♪True.

The Configこのセクションのセルには、トレーニング実行データをキャプチャする新しい WandB プロジェクト(プロジェクトが既に存在しない場合)を初期化および構成するための論理が含まれています。

wandb.init(project="my-bird-vocalization-classifier")
config = wandb.config
config.batch_size = BATCH_SIZE
config.epochs = 30
config.image_size = IMG_SIZE
config.num_classes = len(LABELS)

Obviously, you can change the project name my-bird-vocalization-classifier to your desired WandB project name.

セクション 4.2 - EfficientNet B0 モデルの構築と構築

THEbuild_model method is used to load the pre-trained EfficientNet B0 model with ImageNet weights and without the top layer:

model = EfficientNetB0(include_top=False, input_tensor=inputs, weights="imagenet")

The model is frozen to leverage the pre-trained ImageNet weights with the objective to only unfreeze(i.e. train) layers in the final stage of the model: (i.e. train) layers in the final stage of the model:

# Unfreeze last `unfreeze_layers` layers and add regularization
for layer in model.layers[-unfreeze_layers:]:
   if not isinstance(layer, layers.BatchNormalization):
      layer.trainable = True
      layer.kernel_regularizer = tf.keras.regularizers.l2(L2_RATE)

コンスタントUNFREEZE_LAYERSIN THEConfig cell specifies the number of layers to unfreeze.

モデルのトップは、最終的なものと再構築されています。Dense鳥類の種類を表すカテゴリ。Categorical focal cross-entropy損失機能として選択され、クラスの不均衡に対処するのに役立ちます。LOSS_ALPHAそしてLOSS_GAMMAconstants in theConfigセルは、損失関数を使用します。

セクション 4.3 - モデルトレーニング

THEfitMethod is called on the compiledmodelからSection 4.2トレーニングを進めば、Alearning rate schedulerコールバック、lr_scheduler, is used instead of a constant learning rate. 初期の学習率は、4.0e-4 is hardcoded into the callback. The learning rate is decreased in 2 stages based on the epoch count. The number of training epochs is controlled by the EPOCHSconstant in theConfig cell.

Section 4.4 - Model Saving

The saveMethod is called on the compiledmodelトレーニング後、モデルをディスクに保存します。

model.save("bird-vocalization-classifier.keras")

トレーニング結果

ノートブックを実行するには、以下のトレーニング結果を生成する必要がありますが、このノートブックで説明された実験設定を使用したと仮定します。Building the Classifierセクション:

Training results

見たように、精度はわずか90%を超え、検証精度は30の時代のトレーニング後に約70%です。しかし、見たように、検証精度は大幅に変動します。この変異は部分的にクラスの不均衡に起因し、利用可能なメモリは、不均衡を完全に解決するために追加の増加の使用を制限します。結果は、モデルがトレーニングデータの過剰装備に苦しんでおり、期待されるように一般化しません。

INFERENCE 走る

This カグレノブ("inference notebook") は推論を実行するために使用できます。 推論ノートロジックは、GBV 分類モデルと、前のセクションでトレーニングしたモデルを両方使用します。train_soundscapesディレクトリ. 各 soundcapes オーディオ ファイルは 5 秒のフレームに分かれています。MAX_FILES常に定義されている「theConfig細胞Section 0of the notebook は、推論のためにロードされている soundcapes オーディオファイルの数を制御します。

推測ノートはまずGBV分類器を使用して予測を生成します。GBV分類器に知られている143のBirdCLEF+ 2025競争データセットクラスの予測は分離されます。GBV_CLASSIFIER_THRESHOLD, GBV 予測クラスが真のクラスとして選択される場合、143 つの「知られている」クラスの中の最大確率が以下である場合GBV_CLASSIFIER_THRESHOLD, it is assumed that the true class is among the 63 classes "unknown" to the GBV classifier - i.e. the classes used to train the model in the preceding section. The logic then runs predictions using the finetuned model. The predicted class from that prediction set is subsequently selected as the true class. つまり、以前のセクションでモデルを訓練するために使用されたクラスであると仮定されます。

THEGBV_CLASSIFIER_THRESHOLDconstant が定義されています。Config細胞Section 5予測は2ファイルの出力です:

  1. preds.csv ファイルは、あらゆる 5 秒間のサウンド スクエップの予測と予測の確率をキャプチャします。
  2. submission.csv ファイルは、BirdCLEF+ 2025 コンテストの形式でクラスのすべての確率をキャプチャします。

推測ノートのセクション 4 の最初のセクションの細かいモデルへのパスを設定します。

推測ノートのセクション 4 の最初のセクションの細かいモデルへのパスを設定します。

将来の仕事

トレーニングノートは、すべての206 BirdCLEF+ 2025クラスのモデルをトレーニングするために使用することができ、少なくとも競争データセットに関して、GBV分類器の必要性を排除します。[], to theload_training_audioメソッドは、すべてのクラスのオーディオデータをロードします。MAX_FILESそしてLOAD_SLICE常数は、充電されたオーディオの量を制限して、Kaggle ノートブック環境の限界内で動作するために使用できます。

Of course, a more accurate model can be trained using a larger amount of training data. Ideally, a greater number of augmentations would be used to address the class imbalance. Additionally, other augmentation techniques, such as CutMix, could be implemented to further augment the training data. However, these strategies demand a more robust development environment.

Trending Topics

blockchaincryptocurrencyhackernoon-top-storyprogrammingsoftware-developmenttechnologystartuphackernoon-booksBitcoinbooks