Skip to content
Merged
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: 6 additions & 3 deletions batbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def pipeline(
config=None,
# classifier_thresh=classifier.CONFIGS[None]['thresh'],
clean=True,
output_folder='.',
):
"""
Run the ML pipeline on a given WAV filepath and return the classification results
Expand Down Expand Up @@ -93,7 +94,9 @@ def pipeline(
tuple ( float, list ( dict ) ): classifier score, list of time windows
"""
# Generate spectrogram
output_paths, metadata_path, metadata = spectrogram.compute(filepath)
output_paths, metadata_path, metadata = spectrogram.compute(
filepath, output_folder=output_folder
)

return output_paths, metadata_path

Expand Down Expand Up @@ -161,7 +164,7 @@ def example():
assert exists(wav_filepath)

log.debug(f'Running pipeline on WAV: {wav_filepath}')

results = pipeline(wav_filepath)
output = './output'
results = pipeline(wav_filepath, output_folder=output)

log.debug(results)
23 changes: 6 additions & 17 deletions batbot/batbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ def fetch(config):
)
@click.option(
'--output',
help='Path to output JSON (if unspecified, results are printed to screen)',
default=None,
'output_path',
help='Path to output folder for the results',
default='.',
type=str,
)
# @click.option(
Expand All @@ -60,7 +61,7 @@ def fetch(config):
def pipeline(
filepath,
config,
output,
output_path,
# classifier_thresh,
):
"""
Expand All @@ -79,25 +80,13 @@ def pipeline(
config = config.strip().lower()
# classifier_thresh /= 100.0

score = batbot.pipeline(
batbot.pipeline(
filepath,
config=config,
# classifier_thresh=classifier_thresh,
output_folder=output_path,
)

data = {
filepath: {
'classifier': score,
}
}

log.debug('Outputting results...')
if output:
with open(output, 'w') as outfile:
json.dump(data, outfile)
else:
print(data)


@click.command('batch')
@click.argument(
Expand Down
5 changes: 5 additions & 0 deletions batbot/spectrogram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,11 @@ def compute_wrapper(

chunksize = int(50e3)

# create output folder if it doesn't exist
if not os.path.exists(output_folder):
os.makedirs(output_folder)
assert exists(output_folder)

debug_path = get_debug_path(output_folder, wav_filepath, enabled=debug)

# Load the spectrogram from a WAV file on disk
Expand Down
3 changes: 2 additions & 1 deletion tests/test_spectrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ def test_spectrogram_compute():
from batbot.spectrogram import compute

wav_filepath = abspath(join('examples', 'example2.wav'))
output_paths, metadata_path, metadata = compute(wav_filepath)
output_folder = './output'
output_paths, metadata_path, metadata = compute(wav_filepath, output_folder=output_folder)