Skip to content

Commit

Permalink
added error messages in GUI for invalid class combinations (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mauermann authored Jun 17, 2024
1 parent 5c618fa commit e609e22
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ python3 analyze.py --classifier checkpoints/custom/Custom_Classifier.tflite
NOTE: Setting a custom classifier will also set the new labels file.
Due to these custom labels, the location filter and locale will be disabled.
+
. You can include negative samples for classes by prefixing the folder names with a '-' (e.g., `-Poecile atricapillus_Black-capped Chickadee`). Do this with samples that definitely do not contain the species. Negative samples will only be used for training and not for validation. Also keep in mind that negative samples will only be used when a corresponding folder with positive samples exists.
. You can include negative samples for classes by prefixing the folder names with a '-' (e.g., `-Poecile atricapillus_Black-capped Chickadee`). Do this with samples that definitely do not contain the species. Negative samples will only be used for training and not for validation. Also keep in mind that negative samples will only be used when a corresponding folder with positive samples exists. Negative samples cannot be used for binary classification, instead include these samples in the non-event folder.
+
. To train with multi-label data separate the class labels with commas in the folder names (e.g., `Poecile atricapillus_Black-capped Chickadee, Cardinalis cardinalis_Northern Cardinal`). This can also be combined with negative samples as described above. The validation split will be performed combination of classes, so you might want to ensure sufficient data for each combination of classes. When using multi-label data the upsampling mode will be limited to 'repeat'.

Expand Down
12 changes: 9 additions & 3 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,15 @@ def trialProgression(trial):
(trial, autotune_trials), total=autotune_trials, unit="trials", desc=loc.localize("progress-autotune")
)

history = trainModel(
on_epoch_end=epochProgression, on_trial_result=trialProgression, on_data_load_end=dataLoadProgression
)
try:
history = trainModel(
on_epoch_end=epochProgression, on_trial_result=trialProgression, on_data_load_end=dataLoadProgression
)
except Exception as e:
if e.args and len(e.args) > 1:
raise gr.Error(loc.localize(e.args[1]))
else:
raise gr.Error(f"{e}")

if len(history.epoch) < epochs:
gr.Info(loc.localize("training-tab-early-stoppage-msg"))
Expand Down
3 changes: 3 additions & 0 deletions lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@
"validation-no-valid-learning-rate": "Bitte geben Sie eine gültige Lernrate an.",
"validation-no-valid-frequency": "Bitte geben Sie eine gültige Frequenz an",
"validation-no-audio-directory-selected": "Kein Audioverzeichnis ausgewählt",
"validation-no-negative-samples-in-binary-classification": "Negativbeispiele können bei binärer Klassifikation nicht verwendet werden.",
"validation-non-event-samples-required-in-binary-classification": "Für binäre Klassifikation müssen Hintergrundsamples vorhanden sein.",
"validation-only-repeat-upsampling-for-multi-label": "Mit Multi-Label Beispielen kann nur 'wiederholen' als Upsampling-Modus verwendet werden.",
"progress-preparing": "Vorbereiten",
"progress-starting": "Starten",
"progress-build-classifier": "Daten laden & Klassifikator erstellen",
Expand Down
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@
"validation-no-valid-learning-rate": "Please enter a valid learning rate.",
"validation-no-valid-frequency": "Please enter a valid frequency in",
"validation-no-audio-directory-selected": "No audio directory selected",
"validation-no-negative-samples-in-binary-classification": "Negative labels can't be used with binary classification",
"validation-non-event-samples-required-in-binary-classification": "Non-event samples are required for binary classification",
"validation-only-repeat-upsampling-for-multi-label": "Only repeat-upsampling ist available for multi-label",
"progress-preparing": "Preparing",
"progress-starting": "Starting",
"progress-build-classifier": "Loading data & building classifier",
Expand Down
6 changes: 3 additions & 3 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def _loadTrainingData(cache_mode="none", cache_file="", progress_callback=None):
# Validate the classes for binary classification
if cfg.BINARY_CLASSIFICATION:
if len([l for l in folders if l.startswith("-")]) > 0:
raise Exception("Negative labels cant be used with binary classification")
raise Exception("Negative labels can't be used with binary classification", "validation-no-negative-samples-in-binary-classification")
if len([l for l in folders if l.lower() in cfg.NON_EVENT_CLASSES]) == 0:
raise Exception("Non-event samples are required for binary classification")
raise Exception("Non-event samples are required for binary classification", "validation-non-event-samples-required-in-binary-classification")

# Check if multi label
cfg.MULTI_LABEL = len(valid_labels) > 1 and any(',' in f for f in folders)
Expand All @@ -127,7 +127,7 @@ def _loadTrainingData(cache_mode="none", cache_file="", progress_callback=None):

# Only allow repeat upsampling for multi-label setting
if cfg.MULTI_LABEL and cfg.UPSAMPLING_RATIO > 0 and cfg.UPSAMPLING_MODE != 'repeat':
raise Exception("Only repeat-upsampling ist available for multi-label")
raise Exception("Only repeat-upsampling ist available for multi-label", "validation-only-repeat-upsampling-for-multi-label")

# Load training data
x_train = []
Expand Down

0 comments on commit e609e22

Please sign in to comment.