Skip to content

Commit

Permalink
fix(birdnet): Make location filter threshold as configurable value un…
Browse files Browse the repository at this point in the history
…der BirdNET node
  • Loading branch information
tphakala committed Apr 2, 2024
1 parent 2a19c6c commit 954c681
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
13 changes: 10 additions & 3 deletions internal/birdnet/rangefilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ func (a ByScore) Len() int { return len(a) }
func (a ByScore) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByScore) Less(i, j int) bool { return a[i].Score > a[j].Score } // For descending order

const locationFilterThreshold = 0.01

// GetProbableSpecies filters and sorts bird species based on their scores.
// It also updates the scores for species that have custom actions defined in the speciesConfigCSV.
func (bn *BirdNET) GetProbableSpecies() []string {
Expand All @@ -46,10 +44,19 @@ func (bn *BirdNET) GetProbableSpecies() []string {
// Apply prediction filter based on the context
filters, _ := bn.predictFilter()

// check bn.Settings.BirdNET.LocationFilterThreshold for valid value
if bn.Settings.BirdNET.LocationFilterThreshold < 0 ||
bn.Settings.BirdNET.LocationFilterThreshold > 1 {
fmt.Println("Invalid LocationFilterThreshold value, using default value of 0.01")
bn.Settings.BirdNET.LocationFilterThreshold = 0.01
}

// Collect species scores above a certain threshold
var speciesScores []SpeciesScore
for _, filter := range filters {
if filter.Score >= locationFilterThreshold {
if filter.Score >= bn.Settings.BirdNET.LocationFilterThreshold {
// DEBUG print species which pass location threshold filter
//fmt.Println("Filter: ", filter.Label, " Score: ", filter.Score)
speciesScores = append(speciesScores, SpeciesScore{Score: float64(filter.Score), Label: filter.Label})
}
}
Expand Down
31 changes: 17 additions & 14 deletions internal/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ type Settings struct {
}

BirdNET struct {
Sensitivity float64 // birdnet analysis sigmoid sensitivity
Threshold float64 // threshold for prediction confidence to report
Overlap float64 // birdnet analysis overlap between chunks
Longitude float64 // longitude of recording location for prediction filtering
Latitude float64 // latitude of recording location for prediction filtering
Threads int // number of CPU threads to use for analysis
Locale string // language to use for labels
Sensitivity float64 // birdnet analysis sigmoid sensitivity
Threshold float64 // threshold for prediction confidence to report
Overlap float64 // birdnet analysis overlap between chunks
Longitude float64 // longitude of recording location for prediction filtering
Latitude float64 // latitude of recording location for prediction filtering
Threads int // number of CPU threads to use for analysis
Locale string // language to use for labels
LocationFilterThreshold float32 // threshold for prediction confidence to report
}

Input struct {
Expand Down Expand Up @@ -205,13 +206,15 @@ main:
# BirdNET model specific settings
birdnet:
sensitivity: 1.0 # sigmoid sensitivity, 0.1 to 1.5
threshold: 0.8 # threshold for prediction confidence to report, 0.0 to 1.0
overlap: 0.0 # overlap between chunks, 0.0 to 2.9
latitude: 00.000 # latitude of recording location for prediction filtering
longitude: 00.000 # longitude of recording location for prediction filtering
threads: 0 # 0 to use all available CPU threads
locale: en # language to use for labels
sensitivity: 1.0 # sigmoid sensitivity, 0.1 to 1.5
threshold: 0.8 # threshold for prediction confidence to report, 0.0 to 1.0
overlap: 0.0 # overlap between chunks, 0.0 to 2.9
threads: 0 # 0 to use all available CPU threads
locale: en # language to use for labels
latitude: 00.000 # latitude of recording location for prediction filtering
longitude: 00.000 # longitude of recording location for prediction filtering
locationfilterthreshold: 0.01 # rangefilter species occurrence threshold, lower value
# increases number of species reported
# Realtime processing settings
realtime:
Expand Down

0 comments on commit 954c681

Please sign in to comment.