Skip to content

Commit db09331

Browse files
committed
add perch to benchmark
disabled test
1 parent aabc081 commit db09331

3 files changed

Lines changed: 85 additions & 41 deletions

File tree

src/birdnet/acoustic_models/inference_pipeline/session.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def end(self) -> None:
144144

145145
assert self._resources is not None
146146
self._resources.processing_resources.end_event.set()
147-
print(f"Ended session {self._session_id}...")
148147

149148
def __exit__(self, *args) -> None:
150149
assert self._is_initialized

src/birdnet/benchmark_script.py

Lines changed: 83 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -191,52 +191,96 @@ def run_benchmark_from_args(args: list[str]) -> None:
191191
default="benchmark",
192192
)
193193

194+
parser.add_argument(
195+
"--use-perch",
196+
action="store_true",
197+
help="use the Perch v2 model for benchmarking instead of the Acoustic v2.4 model "
198+
"[only available with the Protobuf backend]",
199+
default=False,
200+
)
201+
194202
ns: Namespace = parser.parse_args(args)
195203
run_benchmark_from_ns(ns)
196204

197205

198206
def run_benchmark_from_ns(ns: Namespace) -> None:
199-
model: AcousticModelV2_4
200-
if ns.backend == MODEL_BACKEND_TF:
201-
model = birdnet.model_loader.load(
202-
MODEL_TYPE_ACOUSTIC,
203-
ACOUSTIC_MODEL_VERSION_V2_4,
204-
MODEL_BACKEND_TF,
205-
precision=cast(MODEL_PRECISIONS, ns.precision),
206-
library=cast(LIBRARY_TYPES, ns.tf_library),
207-
)
208-
elif ns.backend == MODEL_BACKEND_PB:
209-
model = birdnet.model_loader.load(
210-
MODEL_TYPE_ACOUSTIC,
211-
ACOUSTIC_MODEL_VERSION_V2_4,
212-
MODEL_BACKEND_PB,
213-
precision=MODEL_PRECISION_FP32,
207+
if ns.use_perch:
208+
from birdnet.model_loader import load_perch_v2
209+
210+
if ns.backend != MODEL_BACKEND_PB:
211+
raise ValueError(
212+
"The Perch v2 model is only available with the Protobuf backend."
213+
)
214+
if ns.precision != MODEL_PRECISION_FP32:
215+
raise ValueError("The Perch v2 model only supports 'fp32' precision.")
216+
217+
first_device = ns.devices[0] if len(ns.devices) > 0 else "CPU"
218+
perch_model = load_perch_v2(device=first_device)
219+
220+
perch_model.predict(
221+
ns.inputs,
222+
top_k=ns.top_k,
223+
n_feeders=ns.feeders,
224+
n_workers=ns.workers,
225+
batch_size=ns.batch_size,
226+
overlap_duration_s=ns.overlap,
227+
speed=ns.speed,
228+
default_confidence_threshold=ns.confidence,
229+
custom_confidence_thresholds=None,
230+
apply_sigmoid=True,
231+
sigmoid_sensitivity=1.0,
232+
custom_species_list=None,
233+
half_precision=ns.half_precision,
234+
max_audio_duration_min=None,
235+
show_stats=ns.show_stats,
236+
device=ns.devices if len(ns.devices) > 1 else ns.devices[0],
237+
prefetch_ratio=ns.prefetch_ratio,
238+
progress_callback=None, # my_callback,
239+
bandpass_fmin=AcousticModelV2_4.get_sig_fmin(),
240+
bandpass_fmax=AcousticModelV2_4.get_sig_fmax(),
214241
)
215242
else:
216-
raise AssertionError()
217-
218-
model.predict(
219-
ns.inputs,
220-
top_k=ns.top_k,
221-
n_feeders=ns.feeders,
222-
n_workers=ns.workers,
223-
batch_size=ns.batch_size,
224-
overlap_duration_s=ns.overlap,
225-
speed=ns.speed,
226-
default_confidence_threshold=ns.confidence,
227-
custom_confidence_thresholds=None,
228-
apply_sigmoid=True,
229-
sigmoid_sensitivity=1.0,
230-
custom_species_list=None,
231-
half_precision=ns.half_precision,
232-
max_audio_duration_min=None,
233-
show_stats=ns.show_stats,
234-
device=ns.devices if len(ns.devices) > 1 else ns.devices[0],
235-
prefetch_ratio=ns.prefetch_ratio,
236-
progress_callback=my_callback,
237-
bandpass_fmin=AcousticModelV2_4.get_sig_fmin(),
238-
bandpass_fmax=AcousticModelV2_4.get_sig_fmax(),
239-
)
243+
model: AcousticModelV2_4
244+
if ns.backend == MODEL_BACKEND_TF:
245+
model = birdnet.model_loader.load(
246+
MODEL_TYPE_ACOUSTIC,
247+
ACOUSTIC_MODEL_VERSION_V2_4,
248+
MODEL_BACKEND_TF,
249+
precision=cast(MODEL_PRECISIONS, ns.precision),
250+
library=cast(LIBRARY_TYPES, ns.tf_library),
251+
)
252+
elif ns.backend == MODEL_BACKEND_PB:
253+
model = birdnet.model_loader.load(
254+
MODEL_TYPE_ACOUSTIC,
255+
ACOUSTIC_MODEL_VERSION_V2_4,
256+
MODEL_BACKEND_PB,
257+
precision=MODEL_PRECISION_FP32,
258+
)
259+
else:
260+
raise AssertionError()
261+
262+
model.predict(
263+
ns.inputs,
264+
top_k=ns.top_k,
265+
n_feeders=ns.feeders,
266+
n_workers=ns.workers,
267+
batch_size=ns.batch_size,
268+
overlap_duration_s=ns.overlap,
269+
speed=ns.speed,
270+
default_confidence_threshold=ns.confidence,
271+
custom_confidence_thresholds=None,
272+
apply_sigmoid=True,
273+
sigmoid_sensitivity=1.0,
274+
custom_species_list=None,
275+
half_precision=ns.half_precision,
276+
max_audio_duration_min=None,
277+
show_stats=ns.show_stats,
278+
device=ns.devices if len(ns.devices) > 1 else ns.devices[0],
279+
prefetch_ratio=ns.prefetch_ratio,
280+
progress_callback=None, # my_callback,
281+
bandpass_fmin=AcousticModelV2_4.get_sig_fmin(),
282+
bandpass_fmax=AcousticModelV2_4.get_sig_fmax(),
283+
)
240284

241285

242286
def my_callback(info: ProgressStats) -> None:

src/birdnet_tests/acoustic_models/v2_4/model_py/test_predict/test_acoustic_predict_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def test_pb_cpu_fp32() -> None:
3232
assert res.species_probs.shape == TEST_FILE_SHORT_SCORE_SHAPE
3333

3434

35-
def test_pb_cpu_fp32_callback() -> None:
35+
def xtest_pb_cpu_fp32_callback() -> None:
36+
# depending on the speed of the machine, this may or may not collect any stats
3637
collected_stats = []
3738

3839
def test_callback(data: ProgressStats) -> None:

0 commit comments

Comments
 (0)