8000 Add verbose option to turn off logs for scripting by acmiyaguchi · Pull Request #124 · joeweiss/birdnetlib · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add verbose option to turn off logs for scripting #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/birdnetlib/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(
classifier_model_path=None,
classifier_labels_path=None,
version=None,
verbose=True,
):
self.name = "Analyzer"
self.model_name = "BirdNET-Analyzer"
Expand Down Expand Up @@ -101,6 +102,8 @@ def __init__(
# Download version dynamically if there's a match.
self.check_for_model_files()

self.verbose = verbose

self.classifier_model_path = classifier_model_path
self.classifier_labels_path = classifier_labels_path
self.use_custom_classifier = (
Expand Down Expand Up @@ -294,14 +297,16 @@ def return_predicted_species_list(
week_48=None,
filter_threshold=LOCATION_FILTER_THRESHOLD,
):
print("return_predicted_species_list")
if self.verbose:
print("return_predicted_species_list")

return self.species_class.return_list_for_analyzer(
lat=lat, lon=lon, week_48=week_48, threshold=filter_threshold
)

def set_predicted_species_list_from_position(self, recording):
print("set_predicted_species_list_from_position")
if self.verbose:
print("set_predicted_species_list_from_position")

# Check to see if this species list has been previously cached.
list_key = f"list-{recording.lon}-{recording.lat}-{recording.week_48}"
Expand All @@ -321,7 +326,8 @@ def set_predicted_species_list_from_position(self, recording):
self.cached_species_lists[list_key] = species_list

def analyze_recording(self, recording):
print("analyze_recording", recording.filename)
if self.verbose:
print("analyze_recording", recording.filename)

if self.has_custom_species_list and recording.lon and recording.lat:
raise ValueError(
Expand All @@ -330,7 +336,8 @@ def analyze_recording(self, recording):

# If recording has lon/lat, load cached list or predict a new species list.
if recording.lon and recording.lat and self.classifier_model_path == None:
print("recording has lon/lat")
if self.verbose:
print("recording has lon/lat")
self.set_predicted_species_list_from_position(recording)

start = 0
Expand Down Expand Up @@ -364,7 +371,8 @@ def analyze_recording(self, recording):
recording.detection_list = self.detections

def extract_embeddings_for_recording(self, recording):
print("extract_embeddings_for_recording", recording.filename)
if self.verbose:
print("extract_embeddings_for_recording", recording.filename)
start = 0
end = recording.sample_secs
results = []
Expand Down
14 changes: 12 additions & 2 deletions src/birdnetlib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(
min_conf=0.1,
overlap=0.0,
return_all_detections=False,
verbose=True,
):
self.analyzer = analyzer
self.detections_dict = {} # Old format
Expand All @@ -50,6 +51,7 @@ def __init__(
self.extracted_audio_paths = {}
self.extracted_spectrogram_paths = {}
self.return_all_detections = return_all_detections
self.verbose = verbose

def analyze(self):
# Check that analyzer is not LargeRecordingAnalyzer
Expand Down Expand Up @@ -169,8 +171,8 @@ def process_audio_data(self, rate):
chunks.append(split)

self.chunks = chunks

print("read_audio_data: complete, read ", str(len(self.chunks)), "chunks.")
if self.verbose:
print("read_audio_data: complete, read ", str(len(self.chunks)), "chunks.")

def get_extract_array(self, start_sec, end_sec):
# Returns ndarray trimmed for start_sec:end_sec
Expand Down Expand Up @@ -278,6 +280,7 @@ def __init__(
min_conf=0.1,
overlap=0.0,
return_all_detections=False,
**kwargs,
):
self.path = path
p = Path(self.path)
Expand All @@ -292,6 +295,7 @@ def __init__(
min_conf,
overlap,
return_all_detections,
**kwargs,
)

@property
Expand Down Expand Up @@ -333,6 +337,7 @@ def __init__(
min_conf=0.1,
overlap=0.0,
return_all_detections=False,
**kwargs,
):
self.buffer = buffer
self.rate = rate
Expand All @@ -346,6 +351,7 @@ def __init__(
min_conf,
overlap,
return_all_detections,
**kwargs,
)

@property
Expand All @@ -371,6 +377,7 @@ def __init__(
min_conf=0.1,
overlap=0.0,
return_all_detections=False,
**kwargs,
):
self.file_obj = file_obj
super().__init__(
Expand All @@ -383,6 +390,7 @@ def __init__(
min_conf,
overlap,
return_all_detections,
**kwargs,
)

@property
Expand Down Expand Up @@ -423,6 +431,7 @@ def __init__(
min_conf=0.1,
overlap=0,
return_all_detections=False,
**kwargs,
):
super().__init__(
analyzer,
Expand All @@ -435,6 +444,7 @@ def __init__(
min_conf,
overlap,
return_all_detections,
**kwargs,
)

def analyze(self):
Expand Down
0