birdnet-analyzer 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. birdnet_analyzer/__init__.py +8 -0
  2. birdnet_analyzer/analyze/__init__.py +5 -0
  3. birdnet_analyzer/analyze/__main__.py +4 -0
  4. birdnet_analyzer/analyze/cli.py +25 -0
  5. birdnet_analyzer/analyze/core.py +245 -0
  6. birdnet_analyzer/analyze/utils.py +701 -0
  7. birdnet_analyzer/audio.py +372 -0
  8. birdnet_analyzer/cli.py +707 -0
  9. birdnet_analyzer/config.py +242 -0
  10. birdnet_analyzer/eBird_taxonomy_codes_2021E.json +25280 -0
  11. birdnet_analyzer/embeddings/__init__.py +4 -0
  12. birdnet_analyzer/embeddings/__main__.py +3 -0
  13. birdnet_analyzer/embeddings/cli.py +13 -0
  14. birdnet_analyzer/embeddings/core.py +70 -0
  15. birdnet_analyzer/embeddings/utils.py +193 -0
  16. birdnet_analyzer/evaluation/__init__.py +195 -0
  17. birdnet_analyzer/evaluation/__main__.py +3 -0
  18. birdnet_analyzer/gui/__init__.py +23 -0
  19. birdnet_analyzer/gui/__main__.py +3 -0
  20. birdnet_analyzer/gui/analysis.py +174 -0
  21. birdnet_analyzer/gui/assets/arrow_down.svg +4 -0
  22. birdnet_analyzer/gui/assets/arrow_left.svg +4 -0
  23. birdnet_analyzer/gui/assets/arrow_right.svg +4 -0
  24. birdnet_analyzer/gui/assets/arrow_up.svg +4 -0
  25. birdnet_analyzer/gui/assets/gui.css +29 -0
  26. birdnet_analyzer/gui/assets/gui.js +94 -0
  27. birdnet_analyzer/gui/assets/img/birdnet-icon.ico +0 -0
  28. birdnet_analyzer/gui/assets/img/birdnet_logo.png +0 -0
  29. birdnet_analyzer/gui/assets/img/birdnet_logo_no_transparent.png +0 -0
  30. birdnet_analyzer/gui/assets/img/clo-logo-bird.svg +1 -0
  31. birdnet_analyzer/gui/embeddings.py +620 -0
  32. birdnet_analyzer/gui/evaluation.py +813 -0
  33. birdnet_analyzer/gui/localization.py +68 -0
  34. birdnet_analyzer/gui/multi_file.py +246 -0
  35. birdnet_analyzer/gui/review.py +527 -0
  36. birdnet_analyzer/gui/segments.py +191 -0
  37. birdnet_analyzer/gui/settings.py +129 -0
  38. birdnet_analyzer/gui/single_file.py +269 -0
  39. birdnet_analyzer/gui/species.py +95 -0
  40. birdnet_analyzer/gui/train.py +698 -0
  41. birdnet_analyzer/gui/utils.py +808 -0
  42. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_af.txt +6522 -0
  43. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ar.txt +6522 -0
  44. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_bg.txt +6522 -0
  45. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ca.txt +6522 -0
  46. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_cs.txt +6522 -0
  47. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_da.txt +6522 -0
  48. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_de.txt +6522 -0
  49. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_el.txt +6522 -0
  50. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_en_uk.txt +6522 -0
  51. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_es.txt +6522 -0
  52. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_fi.txt +6522 -0
  53. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_fr.txt +6522 -0
  54. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_he.txt +6522 -0
  55. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_hr.txt +6522 -0
  56. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_hu.txt +6522 -0
  57. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_in.txt +6522 -0
  58. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_is.txt +6522 -0
  59. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_it.txt +6522 -0
  60. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ja.txt +6522 -0
  61. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ko.txt +6522 -0
  62. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_lt.txt +6522 -0
  63. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ml.txt +6522 -0
  64. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_nl.txt +6522 -0
  65. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_no.txt +6522 -0
  66. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_pl.txt +6522 -0
  67. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_pt_BR.txt +6522 -0
  68. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_pt_PT.txt +6522 -0
  69. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ro.txt +6522 -0
  70. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ru.txt +6522 -0
  71. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_sk.txt +6522 -0
  72. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_sl.txt +6522 -0
  73. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_sr.txt +6522 -0
  74. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_sv.txt +6522 -0
  75. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_th.txt +6522 -0
  76. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_tr.txt +6522 -0
  77. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_uk.txt +6522 -0
  78. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_zh.txt +6522 -0
  79. birdnet_analyzer/lang/de.json +335 -0
  80. birdnet_analyzer/lang/en.json +335 -0
  81. birdnet_analyzer/lang/fi.json +335 -0
  82. birdnet_analyzer/lang/fr.json +335 -0
  83. birdnet_analyzer/lang/id.json +335 -0
  84. birdnet_analyzer/lang/pt-br.json +335 -0
  85. birdnet_analyzer/lang/ru.json +335 -0
  86. birdnet_analyzer/lang/se.json +335 -0
  87. birdnet_analyzer/lang/tlh.json +335 -0
  88. birdnet_analyzer/lang/zh_TW.json +335 -0
  89. birdnet_analyzer/model.py +1243 -0
  90. birdnet_analyzer/search/__init__.py +3 -0
  91. birdnet_analyzer/search/__main__.py +3 -0
  92. birdnet_analyzer/search/cli.py +12 -0
  93. birdnet_analyzer/search/core.py +78 -0
  94. birdnet_analyzer/search/utils.py +111 -0
  95. birdnet_analyzer/segments/__init__.py +3 -0
  96. birdnet_analyzer/segments/__main__.py +3 -0
  97. birdnet_analyzer/segments/cli.py +14 -0
  98. birdnet_analyzer/segments/core.py +78 -0
  99. birdnet_analyzer/segments/utils.py +394 -0
  100. birdnet_analyzer/species/__init__.py +3 -0
  101. birdnet_analyzer/species/__main__.py +3 -0
  102. birdnet_analyzer/species/cli.py +14 -0
  103. birdnet_analyzer/species/core.py +35 -0
  104. birdnet_analyzer/species/utils.py +75 -0
  105. birdnet_analyzer/train/__init__.py +3 -0
  106. birdnet_analyzer/train/__main__.py +3 -0
  107. birdnet_analyzer/train/cli.py +14 -0
  108. birdnet_analyzer/train/core.py +113 -0
  109. birdnet_analyzer/train/utils.py +847 -0
  110. birdnet_analyzer/translate.py +104 -0
  111. birdnet_analyzer/utils.py +419 -0
  112. birdnet_analyzer-2.0.0.dist-info/METADATA +129 -0
  113. birdnet_analyzer-2.0.0.dist-info/RECORD +117 -0
  114. birdnet_analyzer-2.0.0.dist-info/WHEEL +5 -0
  115. birdnet_analyzer-2.0.0.dist-info/entry_points.txt +11 -0
  116. birdnet_analyzer-2.0.0.dist-info/licenses/LICENSE +19 -0
  117. birdnet_analyzer-2.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,242 @@
1
+ import os
2
+
3
+ SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
4
+
5
+ #################
6
+ # Misc settings #
7
+ #################
8
+
9
+ # Random seed for gaussian noise
10
+ RANDOM_SEED: int = 42
11
+
12
+ ##########################
13
+ # Model paths and config #
14
+ ##########################
15
+
16
+ MODEL_VERSION: str = "V2.4"
17
+ PB_MODEL: str = os.path.join(SCRIPT_DIR, "checkpoints/V2.4/BirdNET_GLOBAL_6K_V2.4_Model")
18
+ # MODEL_PATH = PB_MODEL # This will load the protobuf model
19
+ MODEL_PATH: str = os.path.join(SCRIPT_DIR, "checkpoints/V2.4/BirdNET_GLOBAL_6K_V2.4_Model_FP32.tflite")
20
+ MDATA_MODEL_PATH: str = os.path.join(SCRIPT_DIR, "checkpoints/V2.4/BirdNET_GLOBAL_6K_V2.4_MData_Model_V2_FP16.tflite")
21
+ LABELS_FILE: str = os.path.join(SCRIPT_DIR, "checkpoints/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels.txt")
22
+ TRANSLATED_LABELS_PATH: str = os.path.join(SCRIPT_DIR, "labels/V2.4")
23
+
24
+ ##################
25
+ # Audio settings #
26
+ ##################
27
+
28
+ # We use a sample rate of 48kHz, so the model input size is
29
+ # (batch size, 48000 kHz * 3 seconds) = (1, 144000)
30
+ # Recordings will be resampled automatically.
31
+ SAMPLE_RATE: int = 48000
32
+
33
+ # We're using 3-second chunks
34
+ SIG_LENGTH: float = 3.0
35
+
36
+ # Define overlap between consecutive chunks <3.0; 0 = no overlap
37
+ SIG_OVERLAP: float = 0
38
+
39
+ # Define minimum length of audio chunk for prediction,
40
+ # chunks shorter than 3 seconds will be padded with zeros
41
+ SIG_MINLEN: float = 1.0
42
+
43
+ # Frequency range. This is model specific and should not be changed.
44
+ SIG_FMIN: int = 0
45
+ SIG_FMAX: int = 15000
46
+
47
+ # Settings for bandpass filter
48
+ BANDPASS_FMIN: int = 0
49
+ BANDPASS_FMAX: int = 15000
50
+
51
+ # Top N species to display in selection table, ignored if set to None
52
+ TOP_N = None
53
+
54
+ # Audio speed
55
+ AUDIO_SPEED: float = 1.0
56
+
57
+ #####################
58
+ # Metadata settings #
59
+ #####################
60
+
61
+ LATITUDE: float = -1
62
+ LONGITUDE: float = -1
63
+ WEEK: int = -1
64
+ LOCATION_FILTER_THRESHOLD: float = 0.03
65
+
66
+ ######################
67
+ # Inference settings #
68
+ ######################
69
+
70
+ # If None or empty file, no custom species list will be used
71
+ # Note: Entries in this list have to match entries from the LABELS_FILE
72
+ # We use the 2021 eBird taxonomy for species names (Clements list)
73
+ CODES_FILE: str = os.path.join(SCRIPT_DIR, "eBird_taxonomy_codes_2021E.json")
74
+ SPECIES_LIST_FILE: str = os.path.join(SCRIPT_DIR, "example/species_list.txt")
75
+
76
+ # Supported file types
77
+ ALLOWED_FILETYPES: list[str] = ["wav", "flac", "mp3", "ogg", "m4a", "wma", "aiff", "aif"]
78
+
79
+ # Number of threads to use for inference.
80
+ # Can be as high as number of CPUs in your system
81
+ CPU_THREADS: int = 8
82
+ TFLITE_THREADS: int = 1
83
+
84
+ # False will output logits, True will convert to sigmoid activations
85
+ APPLY_SIGMOID: bool = True
86
+ SIGMOID_SENSITIVITY: float = 1.0
87
+
88
+ # Minimum confidence score to include in selection table
89
+ # (be aware: if APPLY_SIGMOID = False, this no longer represents
90
+ # probabilities and needs to be adjusted)
91
+ MIN_CONFIDENCE: float = 0.25
92
+
93
+ # Number of consecutive detections for one species to merge into one
94
+ # If set to 1 or 0, no merging will be done
95
+ # If set to None, all detections will be included
96
+ MERGE_CONSECUTIVE: int = 1
97
+
98
+ # Number of samples to process at the same time. Higher values can increase
99
+ # processing speed, but will also increase memory usage.
100
+ # Might only be useful for GPU inference.
101
+ BATCH_SIZE: int = 1
102
+
103
+
104
+ # Number of seconds to load from a file at a time
105
+ # Files will be loaded into memory in segments that are only as long as this value
106
+ # Lowering this value results in lower memory usage
107
+ FILE_SPLITTING_DURATION: int = 600
108
+
109
+ # Whether to use noise to pad the signal
110
+ # If set to False, the signal will be padded with zeros
111
+ USE_NOISE: bool = False
112
+
113
+ # Specifies the output format. 'table' denotes a Raven selection table,
114
+ # 'audacity' denotes a TXT file with the same format as Audacity timeline labels
115
+ # 'csv' denotes a generic CSV file with start, end, species and confidence.
116
+ RESULT_TYPES: set[str] | list[str] = {"table"}
117
+ OUTPUT_RAVEN_FILENAME: str = "BirdNET_SelectionTable.txt" # this is for combined Raven selection tables only
118
+ # OUTPUT_RTABLE_FILENAME: str = "BirdNET_RTable.csv"
119
+ OUTPUT_KALEIDOSCOPE_FILENAME: str = "BirdNET_Kaleidoscope.csv"
120
+ OUTPUT_CSV_FILENAME: str = "BirdNET_CombinedTable.csv"
121
+
122
+ # File name of the settings csv for batch analysis
123
+ ANALYSIS_PARAMS_FILENAME: str = "BirdNET_analysis_params.csv"
124
+
125
+ # Whether to skip existing results in the output path
126
+ # If set to False, existing files will not be overwritten
127
+ SKIP_EXISTING_RESULTS: bool = False
128
+
129
+ COMBINE_RESULTS: bool = False
130
+ #####################
131
+ # Training settings #
132
+ #####################
133
+
134
+ # Sample crop mode
135
+ SAMPLE_CROP_MODE: str = "center"
136
+
137
+ # List of non-event classes
138
+ NON_EVENT_CLASSES: list[str] = ["noise", "other", "background", "silence"]
139
+
140
+ # Upsampling settings
141
+ UPSAMPLING_RATIO: float = 0.0
142
+ UPSAMPLING_MODE = "repeat"
143
+
144
+ # Number of epochs to train for
145
+ TRAIN_EPOCHS: int = 50
146
+
147
+ # Batch size for training
148
+ TRAIN_BATCH_SIZE: int = 32
149
+
150
+ # Validation split (percentage)
151
+ TRAIN_VAL_SPLIT: float = 0.2
152
+
153
+ # Learning rate for training
154
+ TRAIN_LEARNING_RATE: float = 0.0001
155
+
156
+ # Number of hidden units in custom classifier
157
+ # If >0, a two-layer classifier will be trained
158
+ TRAIN_HIDDEN_UNITS: int = 0
159
+
160
+ # Dropout rate for training
161
+ TRAIN_DROPOUT: float = 0.0
162
+
163
+ # Whether to use mixup for training
164
+ TRAIN_WITH_MIXUP: bool = False
165
+
166
+ # Whether to apply label smoothing for training
167
+ TRAIN_WITH_LABEL_SMOOTHING: bool = False
168
+
169
+ # Whether to use focal loss for training
170
+ TRAIN_WITH_FOCAL_LOSS: bool = False
171
+
172
+ # Focal loss gamma parameter
173
+ FOCAL_LOSS_GAMMA: float = 2.0
174
+
175
+ # Focal loss alpha parameter
176
+ FOCAL_LOSS_ALPHA: float = 0.25
177
+
178
+ # Model output format
179
+ TRAINED_MODEL_OUTPUT_FORMAT: str = "tflite"
180
+
181
+ # Model save mode (replace or append new classifier)
182
+ TRAINED_MODEL_SAVE_MODE: str = "replace"
183
+
184
+ # Cache settings
185
+ TRAIN_CACHE_MODE: str | None = None
186
+ TRAIN_CACHE_FILE: str = "train_cache.npz"
187
+
188
+ # Use automatic Hyperparameter tuning
189
+ AUTOTUNE: bool = False
190
+
191
+ # How many trials are done for the hyperparameter tuning
192
+ AUTOTUNE_TRIALS: int = 50
193
+
194
+ # How many executions per trial are done for the hyperparameter tuning
195
+ # Mutliple executions will be averaged, so the evaluation is more consistent
196
+ AUTOTUNE_EXECUTIONS_PER_TRIAL: int = 1
197
+
198
+ # If a binary classification model is trained.
199
+ # This value will be detected automatically in the training script, if only one class and a non-event class is used.
200
+ BINARY_CLASSIFICATION: bool = False
201
+
202
+ # If a model for a multi-label setting is trained.
203
+ # This value will automatically be set, if subfolders in the input direcotry are named with multiple classes separated by commas.
204
+ MULTI_LABEL: bool = False
205
+
206
+ ################
207
+ # Runtime vars #
208
+ ################
209
+
210
+ # File input path and output path for selection tables
211
+ INPUT_PATH: str = ""
212
+ OUTPUT_PATH: str = ""
213
+
214
+ # Training data path
215
+ TRAIN_DATA_PATH: str = ""
216
+ TEST_DATA_PATH: str = ""
217
+
218
+ CODES = {}
219
+ LABELS: list[str] = []
220
+ TRANSLATED_LABELS: list[str] = []
221
+ SPECIES_LIST: list[str] = []
222
+ ERROR_LOG_FILE: str = os.path.join(SCRIPT_DIR, "error_log.txt")
223
+ FILE_LIST = []
224
+ FILE_STORAGE_PATH: str = ""
225
+
226
+ # Path to custom trained classifier
227
+ # If None, no custom classifier will be used
228
+ # Make sure to set the LABELS_FILE above accordingly
229
+ CUSTOM_CLASSIFIER = None
230
+
231
+ ######################
232
+ # Get and set config #
233
+ ######################
234
+
235
+
236
+ def get_config():
237
+ return {k: v for k, v in globals().items() if k.isupper()}
238
+
239
+
240
+ def set_config(c: dict):
241
+ for k, v in c.items():
242
+ globals()[k] = v