Exemple #1
0
def test_cnn_preprocessor_augment_off(dataset_df):
    """should return same image each time"""
    dataset = CnnPreprocessor(dataset_df)
    dataset.augmentation_off()
    sample1 = dataset[0]["X"].numpy()
    sample2 = dataset[0]["X"].numpy()
    assert np.array_equal(sample1, sample2)
Exemple #2
0
def test_cnn_preprocessor(dataset_df):
    """should return tensor and labels"""
    dataset = CnnPreprocessor(dataset_df)
    dataset.augmentation_off()
    sample1 = dataset[0]["X"]
    assert sample1.numpy().shape == (3, 224, 224)
    assert dataset[0]["y"].numpy().shape == (2,)
Exemple #3
0
def train_dataset():
    df = pd.DataFrame(
        index=["tests/audio/great_plains_toad.wav", "tests/audio/1min.wav"],
        data=[[0, 1], [1, 0]],
        columns=["negative", "positive"],
    )
    return CnnPreprocessor(df, overlay_df=None)
Exemple #4
0
def test_overlay_update_labels(dataset_df, overlay_df):
    """should return different images each time"""
    dataset = CnnPreprocessor(dataset_df, overlay_df=overlay_df)
    dataset.actions.overlay.set(overlay_class="different")
    dataset.actions.overlay.set(update_labels=True)
    sample = dataset[0]
    assert np.array_equal(sample["y"].numpy(), [1, 1])
Exemple #5
0
def test_overlay_different_class_warning(dataset_df, overlay_df_all_positive):
    """if no samples work, should give preprocessing error"""
    dataset = CnnPreprocessor(dataset_df, overlay_df=overlay_df_all_positive)
    dataset.actions.overlay.set(overlay_class="different")
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")
        sample1 = dataset[0]["X"]  # raises a warning
        assert len(w) == 1
Exemple #6
0
def preprocessor():
    paths = ["tests/audio/veryshort.wav", "tests/audio/silence_10s.mp3"]
    labels = [[0, 1], [1, 0]]
    df = pd.DataFrame(index=paths, data=labels, columns=[0, 1])
    return CnnPreprocessor(df, audio_length=5.0)
Exemple #7
0
def test_dataset():
    df = pd.DataFrame(
        index=["tests/audio/great_plains_toad.wav", "tests/audio/1min.wav"])
    return CnnPreprocessor(df, overlay_df=None, return_labels=False)
Exemple #8
0
def test_overlay_different_class(dataset_df, overlay_df):
    """just make sure it runs and doesn't hang"""
    dataset = CnnPreprocessor(dataset_df, overlay_df=overlay_df)
    dataset.actions.overlay.set(overlay_class="different")
    sample1 = dataset[0]["X"]
Exemple #9
0
def test_cnn_preprocessor_overlay(dataset_df, overlay_df):
    dataset = CnnPreprocessor(dataset_df, overlay_df=overlay_df)
    sample1 = dataset[0]["X"]
    dataset.actions.overlay.off()
    sample2 = dataset[0]["X"]
    assert not np.array_equal(sample1, sample2)
Exemple #10
0
def test_cnn_preprocessor_augent_on(dataset_df):
    """should return different images each time"""
    dataset = CnnPreprocessor(dataset_df)
    sample1 = dataset[0]["X"]
    sample2 = dataset[0]["X"]
    assert not np.array_equal(sample1, sample2)
Exemple #11
0
def test_cnn_preprocessor_fails_on_short_file(dataset_df):
    """should fail on short file when audio duration is specified"""
    dataset = CnnPreprocessor(dataset_df, audio_length=5.0)
    with pytest.raises(PreprocessingError):
        sample = dataset[1]["X"]