Skip to content

Commit cb38349

Browse files
authored
CLN: Fix dataset name -> CMACBench (#805)
* CLN: Fix dataset name -> CMACBench, add docstrings * TST: Fix test for renamed CMACBench dataset * Fix bug in CMACBench found with tests * TST: Fix tests/test_datasets/test_get.py * TST/CLN: Rename -> test_datasets/test_cmacbench.py
1 parent 311e904 commit cb38349

6 files changed

Lines changed: 47 additions & 36 deletions

File tree

src/vak/datasets/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from . import biosoundsegbench
2-
from .biosoundsegbench import BioSoundSegBench, SplitsMetadata
1+
from . import cmacbench
2+
from .cmacbench import CMACBench, SplitsMetadata
33
from .get import get
44

55
__all__ = [
6-
"biosoundsegbench",
7-
"BioSoundSegBench",
6+
"cmacbench",
7+
"CMACBench",
88
"get",
99
"SplitsMetadata",
1010
]
1111

1212
# TODO: make this a proper registry
13-
DATASETS = {"BioSoundSegBench": BioSoundSegBench}
13+
DATASETS = {"CMACBench": CMACBench}
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Class representing BioSoundSegBench dataset."""
1+
"""Class representing CMACBench dataset."""
22

33
from __future__ import annotations
44

@@ -35,13 +35,21 @@
3535

3636
@define
3737
class SampleIDVectorPaths:
38+
"""Class that represents paths
39+
to npy files containing sample ID vectors.
40+
"""
3841
train: pathlib.Path
3942
val: pathlib.Path
4043
test: pathlib.Path
4144

4245

4346
@define
4447
class IndsInSampleVectorPaths:
48+
"""Class that represents paths
49+
to npy files containing vectors of
50+
indices within each sample/item
51+
from the dataset.
52+
"""
4553
train: pathlib.Path
4654
val: pathlib.Path
4755
test: pathlib.Path
@@ -50,7 +58,7 @@ class IndsInSampleVectorPaths:
5058
@define
5159
class SplitsMetadata:
5260
"""Class that represents metadata about dataset splits
53-
in the BioSoundSegBench dataset, loaded from a json file"""
61+
in the CMACBench dataset, loaded from a json file"""
5462

5563
splits_csv_path: pathlib.Path
5664
sample_id_vector_paths: SampleIDVectorPaths
@@ -111,7 +119,7 @@ def from_paths(cls, json_path, dataset_path):
111119
class TrainingReplicateMetadata:
112120
"""Class representing metadata for a
113121
pre-defined training replicate
114-
in the BioSoundSegBench dataset.
122+
in the CMACBench dataset.
115123
"""
116124

117125
biosound_group: str
@@ -124,7 +132,7 @@ class TrainingReplicateMetadata:
124132

125133

126134
def metadata_from_splits_json_path(
127-
splits_json_path: pathlib.Path, datset_path: pathlib.Path
135+
splits_json_path: pathlib.Path
128136
) -> TrainingReplicateMetadata:
129137
name = splits_json_path.name
130138
try:
@@ -184,7 +192,7 @@ def metadata_from_splits_json_path(
184192

185193
class TrainItemTransform:
186194
"""Default transform used when training frame classification models
187-
with :class:`BioSoundSegBench` dataset."""
195+
with :class:`CMACBench` dataset."""
188196

189197
def __init__(
190198
self,
@@ -247,7 +255,7 @@ def __call__(
247255

248256
class InferItemTransform:
249257
"""Default transform used when running inference on classification models
250-
with :class:`BioSoundSegBench` dataset, for evaluation or to generate new predictions.
258+
with :class:`CMACBench` dataset, for evaluation or to generate new predictions.
251259
252260
Returned item includes frames reshaped into a stack of windows,
253261
with padded added to make reshaping possible.
@@ -369,8 +377,11 @@ def __call__(
369377
return item
370378

371379

372-
class BioSoundSegBench:
373-
"""Class representing BioSoundSegBench dataset."""
380+
class CMACBench:
381+
"""Class representing CMACBench dataset.
382+
383+
https://github.com/vocalpy/CMACBench
384+
"""
374385

375386
def __init__(
376387
self,
@@ -388,7 +399,7 @@ def __init__(
388399
return_frames_path: bool = False,
389400
item_transform: Callable | None = None,
390401
):
391-
"""BioSoundSegBench dataset."""
402+
"""CMACBench dataset."""
392403
# ---- validate args, roughly in order
393404
dataset_path = pathlib.Path(dataset_path)
394405
if not dataset_path.exists() or not dataset_path.is_dir():
@@ -459,7 +470,7 @@ def __init__(
459470
# this is a bit convoluted: we are setting metadata, to set frame dur,
460471
# to be able to compute duration in property below
461472
self.training_replicate_metadata = metadata_from_splits_json_path(
462-
self.splits_path, self.dataset_path
473+
self.splits_path
463474
)
464475
self.frame_dur = (
465476
self.training_replicate_metadata.frame_dur * 1e-3

src/vak/predict/frame_classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def predict_with_frame_classification_model(
200200
# we need "target_type" below when converting predictions to annotations,
201201
# but fail early here if we don't have it
202202
if "target_type" not in dataset_config["params"]:
203-
from ..datasets.biosoundsegbench import VALID_TARGET_TYPES
203+
from ..datasets.cmacbench import VALID_TARGET_TYPES
204204

205205
raise ValueError(
206206
"The dataset table in the configuration file requires a 'target_type' "

tests/test_datasets/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@
340340

341341

342342
@pytest.fixture
343-
def mock_biosoundsegbench_dataset(tmp_path):
343+
def mock_cmacbench_dataset(tmp_path):
344344
dataset_path = tmp_path / "BioSoundSegBench"
345345
dataset_path.mkdir()
346346
splits_dir = dataset_path / "splits"

tests/test_datasets/test_biosoundsegbench.py renamed to tests/test_datasets/test_cmacbench.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import vak.datasets
55

66

7-
class TestBioSoundSegBench:
7+
class TestCMACBench:
88
@pytest.mark.parametrize(
99
'split, window_size, target_type',
1010
[
@@ -30,16 +30,16 @@ class TestBioSoundSegBench:
3030
),
3131
]
3232
)
33-
def test_init(self, split, window_size, target_type, mock_biosoundsegbench_dataset):
34-
dataset_path, splits_path = mock_biosoundsegbench_dataset
35-
dataset = vak.datasets.BioSoundSegBench(
33+
def test_init(self, split, window_size, target_type, mock_cmacbench_dataset):
34+
dataset_path, splits_path = mock_cmacbench_dataset
35+
dataset = vak.datasets.CMACBench(
3636
dataset_path,
3737
splits_path,
3838
split,
3939
window_size,
4040
target_type,
4141
)
42-
assert isinstance(dataset, vak.datasets.BioSoundSegBench)
42+
assert isinstance(dataset, vak.datasets.CMACBench)
4343

4444
@pytest.mark.parametrize(
4545
'dataset_path, splits_path, split, window_size, target_type, expected_exception',
@@ -110,17 +110,17 @@ def test_init(self, split, window_size, target_type, mock_biosoundsegbench_datas
110110
]
111111
)
112112
def test_init_raises(
113-
self, dataset_path, splits_path, split, window_size, target_type, expected_exception, mock_biosoundsegbench_dataset
113+
self, dataset_path, splits_path, split, window_size, target_type, expected_exception, mock_cmacbench_dataset
114114
):
115115
if dataset_path is None and splits_path is not None:
116-
dataset_path, _ = mock_biosoundsegbench_dataset
116+
dataset_path, _ = mock_cmacbench_dataset
117117
elif dataset_path is not None and splits_path is None:
118-
_, splits_path = mock_biosoundsegbench_dataset
118+
_, splits_path = mock_cmacbench_dataset
119119
elif dataset_path is None and splits_path is None:
120-
dataset_path, splits_path = mock_biosoundsegbench_dataset
120+
dataset_path, splits_path = mock_cmacbench_dataset
121121

122122
with pytest.raises(expected_exception):
123-
dataset = vak.datasets.BioSoundSegBench(
123+
dataset = vak.datasets.CMACBench(
124124
dataset_path,
125125
splits_path,
126126
split,

tests/test_datasets/test_get.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[
1111
(
1212
{
13-
'name': 'BioSoundSegBench',
13+
'name': 'CMACBench',
1414
'params': {
1515
'window_size': 2000,
1616
'target_type': 'multi_frame_labels',
@@ -20,7 +20,7 @@
2020
),
2121
(
2222
{
23-
'name': 'BioSoundSegBench',
23+
'name': 'CMACBench',
2424
'params': {
2525
'window_size': 2000,
2626
'target_type': 'binary_frame_labels',
@@ -30,7 +30,7 @@
3030
),
3131
(
3232
{
33-
'name': 'BioSoundSegBench',
33+
'name': 'CMACBench',
3434
'params': {
3535
'window_size': 2000,
3636
'target_type': 'boundary_frame_labels',
@@ -40,7 +40,7 @@
4040
),
4141
(
4242
{
43-
'name': 'BioSoundSegBench',
43+
'name': 'CMACBench',
4444
'params': {
4545
'window_size': 2000,
4646
'target_type': 'boundary_frame_labels',
@@ -50,7 +50,7 @@
5050
),
5151
(
5252
{
53-
'name': 'BioSoundSegBench',
53+
'name': 'CMACBench',
5454
'params': {
5555
'window_size': 2000,
5656
'target_type': 'boundary_frame_labels',
@@ -60,7 +60,7 @@
6060
),
6161
(
6262
{
63-
'name': 'BioSoundSegBench',
63+
'name': 'CMACBench',
6464
'params': {
6565
'window_size': 2000,
6666
'target_type': 'boundary_frame_labels',
@@ -71,14 +71,14 @@
7171
7272
]
7373
)
74-
def test_get_biosoundsegbench(dataset_config, split, mock_biosoundsegbench_dataset):
75-
dataset_path, splits_path = mock_biosoundsegbench_dataset
74+
def test_get_cmacbench(dataset_config, split, mock_cmacbench_dataset):
75+
dataset_path, splits_path = mock_cmacbench_dataset
7676
dataset_config["path"] = dataset_path
7777
dataset_config["splits_path"] = splits_path
7878

7979
dataset = vak.datasets.get(dataset_config, split)
8080

81-
assert isinstance(dataset, vak.datasets.BioSoundSegBench)
81+
assert isinstance(dataset, vak.datasets.CMACBench)
8282
assert dataset.dataset_path == pathlib.Path(dataset_config["path"])
8383
assert dataset.splits_path == pathlib.Path(dataset_config["splits_path"])
8484
assert dataset.window_size == dataset_config["params"]["window_size"]

0 commit comments

Comments
 (0)