Model

Koogu supports a few ready-to-use architectures.

User-defined custom architectures can be created by implementing the abstract base class koogu.model.architectures.BaseArchitecture.


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.

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.

class koogu.model.architectures.BaseArchitecture(multilabel=True, dtype=None, name=None)

Base class for implementing custom user-defined architectures.

Parameters:
  • multilabel – (bool; default: True) Set appropriately so that the loss function and accuracy metrics can be chosen correctly. A multilabel model’s Logits (final) layer will have Sigmoid activation whereas a single-label model’s will have SoftMax activation.

  • dtype – Tensorflow data type of the model’s weights (default: tf.float32).

  • name – Name of the model.

abstract build_network(input_tensor, is_training, **kwargs)

This method must be implemented in the derived class.

It should contain logic to construct the desired sequential or functional model network starting from the input_tensor.

Note

Do not add the Logits layer in your implementation. It will be added by internal code.

Parameters:
  • input_tensor – The Keras tensor to use as the input placeholder in model that will be built.

  • is_training – (boolean) Indicates if operating in training mode. Certain elements of the network (e.g., dropout layers) may be excluded when not in training mode.

Returns:

Must return a Keras tensor corresponding to outputs of the architecture.