Skip to content

Commit

Permalink
Merge branch '0.1.X' of https://github.com/BirdVox/birdvoxdetect into…
Browse files Browse the repository at this point in the history
… 0.1.X
  • Loading branch information
lostanlen committed Jul 3, 2019
2 parents 1ae47ce + ce64287 commit afeeee5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
12 changes: 11 additions & 1 deletion birdvoxdetect/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def predict(pcen, detector, logger_level, padding=0):
def predict_with_context(pcen, context, detector, logger_level, padding=0):
# Truncate frequency spectrum (from 128 to 120 bins)
pcen = pcen[:120, :]
context = context[:120, :]
context = context[:, :120]

# Compute number of hops.
clip_length = 104
Expand Down Expand Up @@ -636,10 +636,20 @@ def map_confidence(y, model_name):
# Calibrated on BirdVox-300h.
# See repository: github.com/BirdVox/birdvox-full-season
# Notebook: detector/notebooks/BirdVoxDetect-v01_calibration.ipynb
# This model encodes "0" resp. "1" as "event" resp. "no event"
log1my = np.log1p(np.clip(-y, np.finfo(np.float32).eps - 1, None))
logy = np.log(np.clip(y, np.finfo(np.float32).tiny, None))
y_inverse_sigmoid = log1my - logy
y_out = 2.7 * y_inverse_sigmoid - 21
elif model_name == "birdvoxdetect_pcen_cnn":
# Calibrated on BirdVox-full-night_unit03_00-19-45_01min.
# See repository: github.com/BirdVox/birdvox-full-season
# Notebook: detector/notebooks/BirdVoxDetect-v01_calibration-nocontext.ipynb
# This model encodes "1" resp. "0" as "event" resp. "no event"
log1my = np.log1p(np.clip(-y, np.finfo(np.float32).eps - 1, None))
logy = np.log(np.clip(y, np.finfo(np.float32).tiny, None))
y_inverse_sigmoid = logy - log1my
y_out = 6 * y_inverse_sigmoid
else:
y_out = y
return y_out
2 changes: 1 addition & 1 deletion birdvoxdetect/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
short_version = '0.1'
version = '0.1b0-dev'
version = '0.1b5'
21 changes: 14 additions & 7 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def test_process_file():

# standard call
tempdir = tempfile.mkdtemp()
process_file(FG_10SEC_PATH, output_dir=os.path.join(tempdir, "subfolder"))
process_file(
FG_10SEC_PATH,
output_dir=os.path.join(tempdir, "subfolder"),
detector_name="pcen_snr")
csv_path = os.path.join(
tempdir, "subfolder",
'BirdVox-scaper_example_foreground_timestamps.csv')
Expand All @@ -60,20 +63,24 @@ def test_process_file():
assert df.columns[1] == "Time (s)"
assert df.columns[2] == "Confidence (%)"
assert np.allclose(
np.array(df["Time (s)"]), np.array([2.45, 5.2, 6.8]), atol=0.05)
np.array(df["Time (s)"]), np.array([2.4, 5.1, 6.7]), atol=0.1)
shutil.rmtree(tempdir)

# export clips
tempdir = tempfile.mkdtemp()
process_file(FG_10SEC_PATH, output_dir=tempdir, export_clips=True)
process_file(
FG_10SEC_PATH,
output_dir=tempdir,
export_clips=True,
detector_name="pcen_snr")
clips_dir = os.path.join(
tempdir, 'BirdVox-scaper_example_foreground_clips')
assert os.path.exists(clips_dir)
clips_list = sorted(os.listdir(clips_dir))
assert len(clips_list) == 3
assert clips_list[0].startswith('BirdVox-scaper_example_foreground_02')
assert clips_list[1].startswith('BirdVox-scaper_example_foreground_05')
assert clips_list[2].startswith('BirdVox-scaper_example_foreground_06')
assert clips_list[0].startswith('BirdVox-scaper_example_foreground_00002')
assert clips_list[1].startswith('BirdVox-scaper_example_foreground_00005')
assert clips_list[2].startswith('BirdVox-scaper_example_foreground_00006')
assert np.all([c.endswith(".wav") for c in clips_list])
shutil.rmtree(tempdir)

Expand All @@ -84,7 +91,7 @@ def test_process_file():
tempdir, 'BirdVox-scaper_example_foreground_confidence.hdf5')
with h5py.File(confidence_path, "r") as f:
confidence = f["confidence"].value
assert confidence.shape == (200,)
assert confidence.shape == (199,)
shutil.rmtree(tempdir)

# suffix
Expand Down

0 comments on commit afeeee5

Please sign in to comment.