Low-level inferencing interface

Low-level interface for implementing custom analysis pipelines. See an example psuedo-code.

class koogu.model.TrainedModel(saved_model_dir)

An interface for using a trained model for making inferences.

Parameters:

saved_model_dir – Path to the directory from which to load a trained model.

static finalize_and_save(classifier, output_dir, input_shape, transformation_info, classes_list, audio_settings, spec_settings=None)

Create a new model encompassing an already-trained ‘classifier’.

infer(inputs)

Process data using the trained model.

Parameters:

inputs – A 2D numpy array. The first dimension corresponds to the number of input waveform clips. The second dimension contains clips’ samples.

Returns:

An NxM numpy array of scores corresponding to the N input clips and M classes.

property audio_settings

Audio settings that were used for preparing model inputs.

property class_names

List of class names corresponding to the scores output by the model for each input.

property spec_settings

Spectrogram settings used for transforming waveforms into time-frequency representations. If no transformation was applied (during training), then this property will be None.

koogu.inference.analyze_clips(trained_model, clips, batch_size=1, audio_filepath=None)

Apply a trained model to one or more audio clips and obtain scores.

Parameters:
  • trained_model – A koogu.model.TrainedModel instance.

  • clips – An [N x ?] numpy array of N input waveforms.

  • batch_size – (default: 1) Control how many clips are processed in a single batch. Increasing this helps improve throughput, but requires more RAM.

  • audio_filepath – (default: None) If not None, will display a progress bar.

Returns:

A 2-element tuple consisting of -

  • detection/classification scores ([N x M] numpy array corresponding to the N clips and M target classes), and

  • the total time taken to process all the clips.