mirror of
https://github.com/macaodha/batdetect2.git
synced 2026-04-04 23:30:21 +02:00
1.1 KiB
1.1 KiB
Tutorial: Integrate with a Python pipeline
This tutorial shows a minimal Python workflow for loading audio, running batdetect2, and collecting detections for downstream analysis.
Before you start
- BatDetect2 installed in your Python environment.
- A model checkpoint.
- At least one input audio file.
Tutorial steps
- Load BatDetect2 in Python.
- Create an API instance from a checkpoint.
- Run
process_fileon one audio file. - Read detection fields and class scores.
- Save or pass detections to your downstream pipeline.
Example code
from pathlib import Path
from batdetect2.api_v2 import BatDetect2API
api = BatDetect2API.from_checkpoint(Path("path/to/model.ckpt"))
prediction = api.process_file(Path("path/to/audio.wav"))
for detection in prediction.detections:
top_class = api.get_top_class_name(detection)
score = detection.detection_score
print(top_class, score)
What to do next
- See API/config references: {doc}
../reference/index - Learn practical CLI alternatives: {doc}
run-inference-on-folder
This page is a starter scaffold and will be expanded with a full worked example.