_save_model
pickle_mirroredstrategy
¶
A custom reduce function to use when Pickle encounters a tf MirroredStrategy.
This relies on the fact that the tf strategy will already be set before the System.load_state method gets called.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
MirroredStrategy
|
The MirroredStrategy instance. |
required |
Returns:
Type | Description |
---|---|
Tuple[Callable, Tuple]
|
The mechanism to construct a new instance of the MirroredStrategy. See Python docs on the reduce method. |
Source code in fastestimator/fastestimator/backend/_save_model.py
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 |