Test a trained model

Apply a trained model on test dataset, and save raw detection scores for subsequent performance assessment(s). The below functions pre-process the test dataset recordings with the same parameters (obtained from trained model’s metadata) that were used while preparing the training dataset.

koogu.test.from_annotations(model_dir, audio_annot_list, audio_root, annots_root, output_root, annotation_reader=None, remap_labels_dict=None, negative_class_label=None, **kwargs)

Apply a trained model on a test dataset with audio-annotation mappings.

Parameters:
  • model_dir – Path to directory where the trained model is available.

  • audio_annot_list – A list containing pairs (list-like) of relative paths to audio files and the corresponding annotation file(s). The latter can be a single path string or a nested list of path strings. Alternatively, you could also specify (path to) a csv file containing these pairs of entries (in the same order; include 3rd, 4th, … columns if you need to specify additional annotation files corresponding to an audio path). Only use the csv option if the paths are simple (i.e., the filenames do not contain commas or other special characters).

  • audio_root – The full paths of audio files listed in audio_annot_list are resolved using this as the base directory.

  • annots_root – The full paths of annotations files listed in audio_annot_list are resolved using this as the base directory.

  • output_root – Raw detection scores will be written to this directory.

Optional parameters

Parameters:
  • annotation_reader – If not None, must be an annotation reader instance from the annotations module. Defaults to Raven Reader.

  • remap_labels_dict

    If not None, must be a Python dictionary describing mapping of class labels. For details, see similarly named parameter to the constructor of koogu.utils.detections.LabelHelper.

    Note

    Mappings for which targets are not among the model’s classes will be ignored.

  • negative_class_label – Specify the same string (e.g. ‘Other’, ‘Noise’) that was used as a label to identify negative class clips (those that did not match any annotations) when pre-processing the training dataset using koogu.prepare.from_annotations(). Set to None (default), if training did not consider auto-extracted negative class samples.

  • clip_advance – The value defines the amount of clip advance when pre-processing audio. If specified, overrides the value that was read from the model’s metadata.

  • filetypes – Audio file types to restrict processing to. Option is ignored if processing a single file. Can specify multiple types, as a list. Defaults to [‘.wav’, ‘.WAV’, ‘.flac’, ‘.aif’, ‘.mp3’].

  • channels – (int or list of ints) When audio files have multiple channels, set which channels to restrict processing to. If unspecified, all available channels will be processed. E.g., setting to 0 saves the first channel, setting to [0, 2] saves the first and third channels.

  • batch_size – (int; default: 1) Size to batch audio file’s clips into. Increasing this may improve speed on computers with high RAM.

  • num_fetch_threads – (int; default: 1) Number of background threads that will fetch audio from files in parallel.

  • show_progress – (bool) If enabled, messages indicating progress of processing will be shown on console output.

koogu.test.from_top_level_dirs(model_dir, audio_root, output_root, **kwargs)

Apply a trained model on a test dataset with classes defined by top-level folders’ names.

Parameters:
  • model_dir – Path to directory where the trained model is available.

  • audio_root – Full path to the base directory containing the audio files of the test dataset.

  • output_root – Raw detection scores will be written to this directory.

Optional parameters

Parameters:
  • clip_advance – The value defines the amount of clip advance when pre-processing audio. If specified, overrides the value that was read from the model’s metadata.

  • filetypes – Audio file types to restrict processing to. Option is ignored if processing a single file. Can specify multiple types, as a list. Defaults to [‘.wav’, ‘.WAV’, ‘.flac’, ‘.aif’, ‘.mp3’].

  • channels – (int or list of ints) When audio files have multiple channels, set which channels to restrict processing to. If unspecified, all available channels will be processed. E.g., setting to 0 saves the first channel, setting to [0, 2] saves the first and third channels.

  • batch_size – (int; default: 1) Size to batch audio file’s clips into. Increasing this may improve speed on computers with high RAM.

  • num_fetch_threads – (int; default: 1) Number of background threads that will fetch audio from files in parallel.

  • show_progress – (bool) If enabled, messages indicating progress of processing will be shown on console output.