Skip to content

Commit

Permalink
added maximum value to training crop-length (#373)
Browse files Browse the repository at this point in the history
added some additional checks to keep the crop-length in a valid range
  • Loading branch information
max-mauermann committed Jul 2, 2024
1 parent a1628a4 commit 63d53a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 5 additions & 1 deletion audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,14 @@ def splitSignal(sig, rate, seconds, overlap, minlen):
rate = cfg.SAMPLE_RATE
if seconds is None or seconds <= 0:
seconds = cfg.SIG_LENGTH
if overlap is None or overlap < 0 or overlap >= seconds:
if overlap is None or overlap < 0:
overlap = cfg.SIG_OVERLAP
if minlen is None or minlen <= 0 or minlen > seconds:
minlen = cfg.SIG_MINLEN

# Make sure overlap is smaller then signal duration
if overlap >= seconds:
overlap = seconds - 0.01

# Number of frames per chunk, per step and per minimum signal
chunksize = int(rate * seconds)
Expand Down
13 changes: 8 additions & 5 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def runAnalysis(
cfg.SIGMOID_SENSITIVITY = max(0.5, min(1.0 - (float(sensitivity) - 1.0), 1.5))

# Set overlap
cfg.SIG_OVERLAP = overlap
cfg.SIG_OVERLAP = max(0.0, min(2.9, float(overlap)))

# Set frequency range
cfg.BANDPASS_FMIN = max(0, min(cfg.SIG_FMAX, int(fmin)))
Expand Down Expand Up @@ -596,7 +596,7 @@ def start_training(

cfg.TRAIN_DATA_PATH = data_dir
cfg.SAMPLE_CROP_MODE = crop_mode
cfg.SIG_OVERLAP = crop_overlap
cfg.SIG_OVERLAP = max(0.0, min(2.9, float(crop_overlap)))
cfg.CUSTOM_CLASSIFIER = str(Path(output_dir) / classifier_name)
cfg.TRAIN_EPOCHS = int(epochs)
cfg.TRAIN_BATCH_SIZE = int(batch_size)
Expand Down Expand Up @@ -1342,9 +1342,12 @@ def on_autotune_change(value):
label=loc.localize("training-tab-crop-mode-radio-label"),
info=loc.localize("training-tab-crop-mode-radio-info"),
)
crop_overlap = gr.Number(
0.0,
minimum=0.0,

crop_overlap = gr.Slider(
minimum=0,
maximum=2.99,
value=0,
step=0.01,
label=loc.localize("training-tab-crop-overlap-number-label"),
info=loc.localize("training-tab-crop-overlap-number-info"),
visible=False,
Expand Down
2 changes: 1 addition & 1 deletion train.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def run_trial(self, trial, *args, **kwargs):
# Config
cfg.TRAIN_DATA_PATH = args.i
cfg.SAMPLE_CROP_MODE = args.crop_mode
cfg.SIG_OVERLAP = args.crop_overlap
cfg.SIG_OVERLAP = max(0.0, min(2.9, float(args.crop_overlap)))
cfg.CUSTOM_CLASSIFIER = args.o
cfg.TRAIN_EPOCHS = args.epochs
cfg.TRAIN_BATCH_SIZE = args.batch_size
Expand Down

0 comments on commit 63d53a7

Please sign in to comment.