utils
Model utilities API
This module provides utility functions to work with Keras models.
Functions:
-
make_divisible
–Ensure layer has # channels divisble by divisor
-
load_model
–Loads a Keras model stored either remotely or locally
-
append_layers
–Appends layers to a model by cloning it and adding the layers
Functions
make_divisible
Ensure layer has # channels divisble by divisor https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py
Parameters:
-
v
(int
) –Number of channels
-
divisor
(int
, default:4
) –Divisor. Defaults to 4.
-
min_value
(int | None
, default:None
) –Min # channels. Defaults to None.
Returns:
-
int
(int
) –Number of channels
Source code in neuralspot_edge/models/utils.py
load_model
Loads a Keras model stored either remotely or locally. NOTE: Currently supports wandb, s3, and https for remote.
Parameters:
-
model_path
(str
) –Source path WANDB: wandb:[[entity/]project/]collectionName:[alias] FILE: file:/path/to/model.tf S3: s3:bucket/prefix/model.tf https: https://path/to/model.tf
Returns:
-
Model
–keras.Model: Model
Source code in neuralspot_edge/models/utils.py
append_layers
append_layers(model: keras.Model, layers: list[keras.Layer], copy_weights: bool = True) -> keras.Model
Appends layers to a model by cloning it and adding the layers.
Parameters:
-
model
(Model
) –Model
-
layers
(list[Layer]
) –Layers to append
-
copy_weights
(bool
, default:True
) –Copy weights. Defaults to True.
Returns:
-
Model
–keras.Model: Model