Skip to content
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

[♻️] Add tqdm for Progress Bars #176

Open
wants to merge 1 commit 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
9 changes: 4 additions & 5 deletions PyHa/birdnet_lite/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import librosa
import numpy as np
import math
import time
import pandas as pd
from sys import exit
import logging
from pathlib import Path
from tqdm import tqdm

def loadModel():

Expand Down Expand Up @@ -148,7 +148,6 @@ def predict(sample, interpreter, sensitivity, num_predictions):
def analyzeAudioData(chunks, lat, lon, week, sensitivity, overlap, interpreter, num_predictions):

detections = {}
start = time.time()
print('ANALYZING AUDIO...', end=' ', flush=True)

# Convert and prepare metadata
Expand All @@ -157,7 +156,9 @@ def analyzeAudioData(chunks, lat, lon, week, sensitivity, overlap, interpreter,

# Parse every chunk
pred_start = 0.0
for c in chunks:

# @todo maybe include a way to silence this?
for c in tqdm(chunks, desc="Analyzing chunks..."):

# Prepare as input signal
sig = np.expand_dims(c, 0)
Expand All @@ -170,8 +171,6 @@ def analyzeAudioData(chunks, lat, lon, week, sensitivity, overlap, interpreter,
detections[str(pred_start) + ';' + str(pred_end)] = p
pred_start = pred_end - overlap

print('DONE! Time', int((time.time() - start) * 10) / 10.0, 'SECONDS')

return detections

def writeResultsToDf(df, detections, min_conf, output_metadata):
Expand Down
11 changes: 3 additions & 8 deletions PyHa/statistics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
from scipy import stats
from tqdm import tqdm
import pandas as pd
import numpy as np
import time

# Function that takes in a pandas dataframe of annotations and outputs a
# dataframe of the mean, median, mode, quartiles, and standard deviation of
Expand Down Expand Up @@ -249,9 +249,8 @@ def automated_labeling_statistics(
num_errors = 0
num_processed = 0

start_time = time.time()
# Looping through each audio clip
for clip in clips:
for clip in tqdm(clips, desc="Processing clips...", disable=not verbose):
num_processed += 1
clip_automated_df = automated_df[automated_df["IN FILE"] == clip]
# In case the extension for manual_df is different from the clip extension, just check the name before the extension
Expand All @@ -274,12 +273,8 @@ def automated_labeling_statistics(
statistics_df = pd.concat([statistics_df, clip_stats_df])
except BaseException as e:
num_errors += 1
#print("Something went wrong with: " + clip)
print(e)
continue
if num_processed % 50 == 0:
print("Processed", num_processed, "clips in", int((time.time() - start_time) * 10) / 10.0, 'seconds')
start_time = time.time()
if num_errors > 0:
checkVerbose(f"Something went wrong with {num_errors} clips out of {len(clips)} clips", verbose)
statistics_df.reset_index(inplace=True, drop=True)
Expand Down
Loading