Training Custom Models #330
Mattk70
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
With Chirpity 5, members can train and load custom models (classifiers). This post gives an end-to-end example of how to train, load and use a custom model.
For this example, we are going to train a model to recognise a variety of European amphibians (frogs and toads specifically) and combine this with BirdNET, so BirdNET predictions are aware of these amphibians.
Firstly, I have assembled a dataset of Frogs audio from Xeno-Canto, essentially this The files for each species are collected into a folder, so they can be analysed species by species.
To generate the audio used for training we need to create 3 second audio segments which contain the species' calls. To generate these segments, I ran a BirdNET analysis of these files, species by species, using the "Everything" list.
Since BirdNET does not "know" about these species, it gives a variety of incorrect IDs. Some are the frog calls, others are not: I filtered the analysis results by each species detected to establish if what BirdNET thought was a bird/frog/engine was in fact a Frog or Toad sound.
If the IDs appeared to be amphibian sounds, I'd export the audio from the summary of that species ID to a folder for the frog species I'd analysed, matching Chirpity's custom list format:
The eagle-eyed will have noticed there is a folder named "Background_Background". This contains a good selection of audio that is not a Frog/Toad call.
Tip
Whenever you train a model, having a good selection of background sounds is essential for decent performance. If you don't, every sound in the world presented to the model will be classified as one of the target species - in this case a Frog or Toad.
There are also a few bird species. These are included as species which regularly appear as false positives in BirdNET analyses where amphibians are calling. I include these so the new model will learn to distinguish between them better.
Important
These bird species have a '-' at the end of their common name so that name is different from the existing BirdNET label. All labels MUST be unique.
Note
The option to train a custom model is only active when you have selected the BirdNET model in Settings
Selecting this menu item will open the model training form:
Tip
Choose a location with lots of free space, and fast I/O (avoid network locations and USB devices if you can)
Note
"Replace labels" will give you a model that only knows about your saved species, "Append labels" will add your labels to those of BirdNET.
Now you've selected your training folder and cache location, you can use the default values so just hit "Start training"
Grab a coffee while the Chirpity prepares your data, and runs the training. It will take some time. For context my high end machine took c. 45 minutes to train this model with c. 6100 examples in the dataset.
Tip
Start small - because you are training on top of what BirdNET has already learned, only a few good examples are needed. Prefer quality over quantity for your training data (which is NOT what I did in this proof of concept). Try to include examples that reflect a variety of calls and vocalisations across recording conditions (e.g. weather, habitats, close/distant). Fundamentally, the quality of the data makes the difference between an average model and an excellent one.
Note
During training, the footer will show a progress bar, and at the end of each Epoch, the latest loss and accuracy figures are reported:
You are looking for accuracy to increase over time, and loss to decrease.
When the model has trained for the number of epochs you set, or if performance is not improving, training will end and the new model will be saved in your chosen location. You'll then see an interactive chart of the training history:
Tip
As you can see in this chart, most of the learning happened in the first 10 Epochs, with only very minor improvements after that. However the shape of the gradients show stable performance and a good result. Marked fluctuations would indicate instability. Worst of all, poor data or settings choices can lead to NaN values. If you see NaN for loss, just abort the training (hit Escape) and try different settings or refine your training data.
Loading your model
Once the model has been saved, you can go back the the Train menu and select "Import a Custom Model". Give it a name, and select the folder where it has been saved. Your new model will be added to the "Models" list in settings
Important
Relaunch Chirpity before using your new model.
Tip
New classes, regardless of what they represent, will appear in the "Birds" list as well as "Everything" lists. They will not appear in the Location or Nocturnal lists. If you want to filter the species in a model which has classes "appended" to BirdNET, use a custom list.
Beta Was this translation helpful? Give feedback.
All reactions