mirror of
https://github.com/macaodha/batdetect2.git
synced 2025-06-29 22:51:58 +02:00
Added test to validate that changing model loading behaviour did not change model predictions
This commit is contained in:
parent
d085b3212c
commit
394c66a2ee
@ -1,14 +1,13 @@
|
|||||||
"""Test bat detect module API."""
|
"""Test bat detect module API."""
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import soundfile as sf
|
||||||
import torch
|
import torch
|
||||||
from torch import nn
|
from torch import nn
|
||||||
import soundfile as sf
|
|
||||||
|
|
||||||
from batdetect2 import api
|
from batdetect2 import api
|
||||||
|
|
||||||
@ -267,7 +266,6 @@ def test_process_file_with_spec_slices():
|
|||||||
assert len(results["spec_slices"]) == len(detections)
|
assert len(results["spec_slices"]) == len(detections)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_process_file_with_empty_predictions_does_not_fail(
|
def test_process_file_with_empty_predictions_does_not_fail(
|
||||||
tmp_path: Path,
|
tmp_path: Path,
|
||||||
):
|
):
|
||||||
|
47
tests/test_model.py
Normal file
47
tests/test_model.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
"""Test suite for model functions."""
|
||||||
|
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from hypothesis import given, settings
|
||||||
|
from hypothesis import strategies as st
|
||||||
|
|
||||||
|
from batdetect2 import api
|
||||||
|
from batdetect2.detector import parameters
|
||||||
|
|
||||||
|
|
||||||
|
def test_can_import_model_without_warnings():
|
||||||
|
with warnings.catch_warnings():
|
||||||
|
warnings.simplefilter("error")
|
||||||
|
api.load_model()
|
||||||
|
|
||||||
|
|
||||||
|
@settings(deadline=None, max_examples=5)
|
||||||
|
@given(duration=st.floats(min_value=0.1, max_value=2))
|
||||||
|
def test_can_import_model_without_pickle(duration: float):
|
||||||
|
# NOTE: remove this test once no other issues are found This is a temporary
|
||||||
|
# test to check that change in model loading did not impact model behaviour
|
||||||
|
# in any way.
|
||||||
|
|
||||||
|
samplerate = parameters.TARGET_SAMPLERATE_HZ
|
||||||
|
audio = np.random.rand(int(duration * samplerate))
|
||||||
|
|
||||||
|
model_without_pickle, model_params_without_pickle = api.load_model(
|
||||||
|
weights_only=True
|
||||||
|
)
|
||||||
|
model_with_pickle, model_params_with_pickle = api.load_model(
|
||||||
|
weights_only=False
|
||||||
|
)
|
||||||
|
|
||||||
|
assert model_params_without_pickle == model_params_with_pickle
|
||||||
|
|
||||||
|
predictions_without_pickle, _, _ = api.process_audio(
|
||||||
|
audio,
|
||||||
|
model=model_without_pickle,
|
||||||
|
)
|
||||||
|
predictions_with_pickle, _, _ = api.process_audio(
|
||||||
|
audio,
|
||||||
|
model=model_with_pickle,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert predictions_without_pickle == predictions_with_pickle
|
Loading…
Reference in New Issue
Block a user