_save_model
save_model
¶
Save model
weights to a specific directory.
This method can be used with TensorFlow models:
m = fe.build(fe.architecture.tensorflow.LeNet, optimizer_fn="adam")
fe.backend.save_model(m, save_dir="/tmp", model_name="test") # Generates 'test.h5' file inside /tmp directory
This method can be used with PyTorch models:
m = fe.build(fe.architecture.pytorch.LeNet, optimizer_fn="adam")
fe.backend.save_model(m, save_dir="/tmp", model_name="test") # Generates 'test.pt' file inside /tmp directory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Union[Model, Module]
|
A neural network instance to save. |
required |
save_dir |
str
|
Directory into which to write the |
required |
model_name |
Optional[str]
|
The name of the model (used for naming the weights file). If None, model.model_name will be used. |
None
|
save_optimizer |
bool
|
Whether to save optimizer. If True, optimizer will be saved in a separate file at same folder. |
False
|
save_architecture |
bool
|
Whether to also save the entire model architecture so that the model can be reloaded without needing access to the code which generated it. This option is only available for TensorFlow models. |
False
|
Returns:
Type | Description |
---|---|
str
|
The saved model path. |
Raises:
Type | Description |
---|---|
ValueError
|
If |