Skip to content

Commit fdf8540

Browse files
author
trevor.stout
committed
Merge branch 'main' of https://github.com/Kitware/batbot into tas/fast-spectrogram
2 parents 0d372bf + 0fdf8b9 commit fdf8540

5 files changed

Lines changed: 32 additions & 54 deletions

File tree

README.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Kitware BatBot
33
==============
44

5-
|Tests| |Codecov| |Wheel| |Docker| |ReadTheDocs| |Huggingface|
5+
|Tests| |Codecov| |Wheel| |Docker| |ReadTheDocs|
66

77
.. image:: https://github.com/Kitware/batbot/raw/main/assets/logo.png
88
:alt: Batbot
@@ -312,7 +312,3 @@ The code base has been formatted by `Black <https://black.readthedocs.io/en/stab
312312
.. |ReadTheDocs| image:: https://readthedocs.org/projects/batbot/badge/?version=latest
313313
:target: https://kitware-batbot.readthedocs.io/en/latest/?badge=latest
314314
:alt: ReadTheDocs
315-
316-
.. |Huggingface| image:: https://img.shields.io/badge/HuggingFace-running-success
317-
:target: https://huggingface.co/spaces/Kitware/batbot
318-
:alt: Huggingface

batbot/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import concurrent.futures
2121
from multiprocessing import Manager
22-
from os.path import exists, join, split, splitext
22+
from os.path import exists, join, split, splitext, basename
2323
from pathlib import Path
2424

2525
import pooch
@@ -301,8 +301,9 @@ def example():
301301

302302
import time
303303

304+
output_stem = join('output', splitext(basename(wav_filepath))[0])
304305
start_time = time.time()
305-
results = pipeline(wav_filepath, fast_mode=False, force_overwrite=True)
306+
results = pipeline(wav_filepath, out_file_stem=output_stem, fast_mode=False, force_overwrite=True)
306307
stop_time = time.time()
307308
print('Example pipeline completed in {} seconds.'.format(stop_time - start_time))
308309

batbot/batbot.py

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,17 @@ def fetch(config):
5656
type=str,
5757
callback=pipeline_filepath_validator,
5858
)
59-
@click.option(
60-
'--config',
61-
help='Which ML model to use for inference',
62-
default=None,
63-
type=click.Choice(['usgs']),
64-
)
59+
# @click.option(
60+
# '--config',
61+
# help='Which ML model to use for inference',
62+
# default=None,
63+
# type=click.Choice(['usgs']),
64+
# )
6565
@click.option(
6666
'--output',
67-
help='Path to output JSON (if unspecified, results are printed to screen)',
68-
default=None,
67+
'output_path',
68+
help='Path to output folder for the results',
69+
default='.',
6970
type=str,
7071
)
7172
# @click.option(
@@ -76,45 +77,21 @@ def fetch(config):
7677
# )
7778
def pipeline(
7879
filepath,
79-
config,
80-
output,
80+
# config,
81+
output_path,
8182
# classifier_thresh,
8283
):
83-
"""
84-
Run the BatBot pipeline on an input WAV filepath. An example output of the JSON
85-
can be seen below.
86-
87-
.. code-block:: javascript
8884

89-
{
90-
'/path/to/file.wav': {
91-
'classifier': 0.5,
92-
}
93-
}
94-
"""
95-
if config is not None:
96-
config = config.strip().lower()
97-
# classifier_thresh /= 100.0
85+
# define out file stem using given output folder
86+
out_file_stem = join(output_path, splitext(basename(filepath))[0])
9887

99-
score = batbot.pipeline(
88+
batbot.pipeline(
10089
filepath,
101-
config=config,
90+
# config=config,
10291
# classifier_thresh=classifier_thresh,
92+
out_file_stem=out_file_stem,
10393
)
10494

105-
data = {
106-
filepath: {
107-
'classifier': score,
108-
}
109-
}
110-
111-
log.debug('Outputting results...')
112-
if output:
113-
with open(output, 'w') as outfile:
114-
json.dump(data, outfile, indent=4)
115-
else:
116-
print(data)
117-
11895

11996
@click.command('preprocess')
12097
@click.argument(

batbot/spectrogram/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,12 @@ def compute_wrapper(
14321432

14331433
chunksize = int(50e3)
14341434

1435-
debug_path = get_debug_path(split(out_file_stem)[0], wav_filepath, enabled=debug)
1435+
output_folder = split(out_file_stem)[0]
1436+
debug_path = get_debug_path(output_folder, wav_filepath, enabled=debug)
1437+
# create output folder if it doesn't exist
1438+
if not os.path.exists(output_folder):
1439+
os.makedirs(output_folder)
1440+
assert exists(output_folder)
14361441

14371442
# Load the spectrogram from a WAV file on disk
14381443
with warnings.catch_warnings():
@@ -1867,12 +1872,10 @@ def compute_wrapper(
18671872
'segments': metas,
18681873
}
18691874
if 'stft_db' in segments:
1870-
metadata['size']['compressed'] = (
1871-
{
1872-
'width.px': segments['stft_db'].shape[1],
1873-
'height.px': segments['stft_db'].shape[0],
1874-
},
1875-
)
1875+
metadata['size']['compressed'] = {
1876+
'width.px': segments['stft_db'].shape[1],
1877+
'height.px': segments['stft_db'].shape[0],
1878+
}
18761879

18771880
metadata_path = f'{out_file_stem}.metadata.json'
18781881
with open(metadata_path, 'w') as metafile:

tests/test_spectrogram.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ def test_spectrogram_compute():
55
from batbot.spectrogram import compute
66

77
wav_filepath = abspath(join('examples', 'example2.wav'))
8-
output_paths, metadata_path, metadata = compute(wav_filepath)
8+
output_folder = './output'
9+
output_paths, metadata_path, metadata = compute(wav_filepath, output_folder=output_folder)

0 commit comments

Comments
 (0)