Data feeder

For most common applications in bioacoustics, SpectralDataFeeder offers a convenient way to convert prepared audio clips into spectrograms on-the-fly during training/validation. DataFeeder does not apply any transformations and feeds audio clips as-is. Both these classes may be extended to add additional functionalities, change or add new transformation functions, and to include on-the-fly data augmentations.

For processing prepared data generated by mechanisms outside of Koogu, extend koogu.data.feeder.BaseFeeder to implement custom logic to feed your data into the Koogu training pipeline.

class koogu.data.feeder.SpectralDataFeeder(data_dir, fs, spec_settings, **kwargs)

Bases: DataFeeder

A handy data feeder, which converts prepared audio clips into power spectral density spectrograms.

Parameters:
  • data_dir – Directory under which prepared data (.npz files) are available.

  • fs – Sampling frequency of the prepared data.

  • spec_settings – A Python dictionary. For a list of possible keys and values, see parameters to Audio2Spectral.

  • normalize_clips – (optional; boolean) If True (default), input clips will be normalized before applying transform (computing spectrograms).

Other parameters applicable to the parent DataFeeder class may also be specified.

class koogu.data.feeder.DataFeeder(data_dir, validation_split=None, min_clips_per_class=None, max_clips_per_class=None, random_state_seed=None, **kwargs)

Bases: BaseFeeder

A class for loading prepared data from numpy .npz files and feeding them untransformed into the training/evaluation pipeline.

Parameters:
  • data_dir – Directory under which prepared data (.npz files) are available.

  • validation_split – (default: None) Fraction of the available data that must be held out for validation. If None, all available data will be used as training samples.

  • min_clips_per_class – (default: None) The minimum number of per-class samples that must be available. If fewer samples are available for a class, the class will be omitted. If None, no classes will be omitted.

  • max_clips_per_class – (default: None) The maximum number of per-class samples to consider among what is available, for each class. If more samples are available for any class, the specified number of samples will be randomly selected. If None, no limits will be imposed.

  • random_state_seed – (default: None) A seed (integer) used to initialize the pseudo-random number generator that makes shuffling and other randomizing operations repeatable.

  • cache – (optional; boolean) If True (default), the logic to ‘queue & batch’ training/evaluation samples (loaded from disk) will also cache the samples. Helps speed up processing.

  • suppress_nonmax – (optional; boolean) If True, the class labels will be one-hot type arrays, useful for training single-class prediction models. Otherwise (default is False), they will be suitable for training multi-class prediction models, giving values in the range 0-1 for each class.