das.utils#
General utilities
- class das.utils.QtProgressCallback(nb_epochs, comms)[source]#
Init the callback.
- Parameters
nb_epochs ([type]) – number of training epochs
comms (tuple) – tuple of (multiprocessing.Queue, threading.Event) The queue is used to transmit progress updates to the GUI, the event is set in the GUI to stop training.
- on_epoch_end(epoch, logs=None)[source]#
Called at the end of an epoch.
Subclasses should override for any actions to run. This function should only be called during TRAIN mode.
- Parameters
epoch – Integer, index of epoch.
logs – Dict, metric results for this training epoch, and for the validation epoch if validation is performed. Validation result keys are prefixed with
val_
. For training epoch, the values of theModel
’s metrics are returned. Example:{'loss': 0.2, 'accuracy': 0.7}
.
- on_predict_batch_end(batch, logs=None)[source]#
Called at the end of a batch in
predict
methods.Subclasses should override for any actions to run.
Note that if the
steps_per_execution
argument tocompile
intf.keras.Model
is set toN
, this method will only be called everyN
batches.- Parameters
batch – Integer, index of batch within the current epoch.
logs – Dict. Aggregated metric results up until this batch.
- on_test_batch_end(batch, logs=None)[source]#
Called at the end of a batch in
evaluate
methods.Also called at the end of a validation batch in the
fit
methods, if validation data is provided.Subclasses should override for any actions to run.
Note that if the
steps_per_execution
argument tocompile
intf.keras.Model
is set toN
, this method will only be called everyN
batches.- Parameters
batch – Integer, index of batch within the current epoch.
logs – Dict. Aggregated metric results up until this batch.
- on_train_batch_end(batch, logs=None)[source]#
Called at the end of a training batch in
fit
methods.Subclasses should override for any actions to run.
Note that if the
steps_per_execution
argument tocompile
intf.keras.Model
is set toN
, this method will only be called everyN
batches.- Parameters
batch – Integer, index of batch within the current epoch.
logs – Dict. Aggregated metric results up until this batch.
- on_train_begin(logs=None)[source]#
Called at the beginning of training.
Subclasses should override for any actions to run.
- Parameters
logs – Dict. Currently no data is passed to this argument for this method but that may change in the future.
- on_train_end(logs=None)[source]#
Called at the end of training.
Subclasses should override for any actions to run.
- Parameters
logs – Dict. Currently the output of the last call to
on_epoch_end()
is passed to this argument for this method but that may change in the future.
- das.utils.bandpass_filter_song(x: numpy.ndarray, sampling_rate_hz: float, f_low: Optional[float] = None, f_high: Optional[float] = None) numpy.ndarray [source]#
Band-pass filter channel data
- Parameters
x (np.ndarray) – Audio data[T,] or [T, nb_channels]
sampling_rate_hz (float) – Sampling rate in Hz
f_low (Optional[float], optional) – Lower cutoff in Hz. Defaults to 1.0 (None).
f_high (Optional[float], optional) – Upper cutoff in Hz. Defaults to sampling_rate_hz/2 (None).
- Returns
Sampled data
- Return type
np.ndarray
- das.utils.load_from(filename: str, datasets: List[str])[source]#
Load datasets from h5 file.
- Parameters
filename (str) –
datasets (List[str]) – Names of the datasets (=keys) to load
- Returns
[description]
- Return type
[type]
- das.utils.load_model(file_trunk: str, model_dict: Dict[str, Callable], model_ext: str = '_model.h5', params_ext: str = '_params.yaml', compile: bool = True, custom_objects: Optional[Dict[str, Callable]] = None)[source]#
Load model with weights.
First tries to load the full model directly using keras.models.load_model - this will likely fail for models with custom layers. Second, try to init model from parameters and then add weights…
- Parameters
file_trunk (str) – [description]
model_dict (Dict[str, Callable) – [description]
model_ext (str, optional) – [description]. Defaults to ‘_weights.h5’.
params_ext (str, optional) – [description]. Defaults to ‘_params.yaml’.
compile (bool, optional) – [description]. Defaults to True.
custom_objects (dict, optional) –
…
- Returns
keras.Model
- das.utils.load_model_and_params(model_save_name, model_dict={'stft_res_dense': <function stft_res_dense>, 'tcn': <function tcn>, 'tcn_stft': <function tcn_stft>, 'tcn_stft_morph': <function tcn_stft_morph>}, custom_objects=None) Tuple[keras.src.engine.training.Model, Dict[str, Any]] [source]#
[summary]
- Parameters
model_save_name ([type]) – [description]
model_dict ([type], optional) – [description]. Defaults to models.model_dict.
custom_objects –
- Returns
[description]
- Return type
keras.Model, Dict[str, Any]
- das.utils.load_model_from_params(file_trunk: str, model_dict: Dict[str, Callable], weights_ext: str = '_model.h5', params_ext: str = '_params.yaml', compile: bool = True)[source]#
Init architecture from code and load model weights into it. Helps with model loading issues across TF versions.
- Parameters
file_trunk (str) – [description]
models_dict ([type]) – [description]
weights_ext (str, optional) – [description]. Defaults to ‘_model.h5’ (use weights from model file).
params_ext (str, optional) – [description]. Defaults to ‘_params.yaml’.
compile (bool, optional) – [description]. Defaults to True.
- Returns
keras.Model
- das.utils.load_params(file_trunk: str, params_ext: str = '_params.yaml') Dict[str, Any] [source]#
Load model/training parameters from yaml
- Parameters
file_trunk (str) – [description]
params_ext (strs, optional) – [description]. Defaults to ‘_params.yaml’.
- Returns
Parameter dictionary
- Return type
Dict[str, Any]
- das.utils.resample(x: numpy.array, fs_audio: float, fs_model: float)[source]#
Resample audio to model rate.
Rounds rates to next even number for efficiency.
- Parameters
x (np.array) – _description_
fs_audio (float) – _description_
fs_model (float) – _description_
- Returns
Audio resample to fs_model.
- Return type
np.array