dacapo.store.weights_store
Classes
A class representing the weights of a model and optimizer. |
|
Base class for network weight stores. |
Module Contents
- class dacapo.store.weights_store.Weights(model_state_dict, optimizer_state_dict)
A class representing the weights of a model and optimizer.
- optimizer
The optimizer’s state dictionary.
- Type:
OrderedDict[str, torch.Tensor]
- model
The model’s state dictionary.
- Type:
OrderedDict[str, torch.Tensor]
- __init__(model_state_dict, optimizer_state_dict)
Initializes the Weights object with the given model and optimizer state dictionaries.
- optimizer: collections.OrderedDict[str, torch.Tensor]
- model: collections.OrderedDict[str, torch.Tensor]
- class dacapo.store.weights_store.WeightsStore
Base class for network weight stores.
- load_weights(run, iteration)
Load the weights of the given iteration into the given run.
- load_best(run, dataset, criterion)
Load the best weights for the given run, dataset, and criterion into the given run.
- latest_iteration(run)
Return the latest iteration for which weights are available for the given run.
- store_weights(run, iteration)
Store the network weights of the given run.
- retrieve_weights(run, iteration)
Retrieve the network weights of the given run.
- remove(run, iteration)
Delete the weights associated with a specific run/iteration.
- retrieve_best(run, dataset, criterion)
Retrieve the best weights for the given run, dataset, and criterion.
- load_weights(run: dacapo.experiments.run.Run, iteration: int) None
Load this iterations weights into the given run. :param run: The run to load the weights into. :type run: Run :param iteration: The iteration to load the weights from. :type iteration: int
- Raises:
ValueError – If the iteration is not available.
Examples
>>> store = WeightsStore() >>> run = Run() >>> iteration = 0 >>> store.load_weights(run, iteration)
- load_best(run: dacapo.experiments.run.Run, dataset: str, criterion: str) None
Load the best weights for this Run,dataset,criterion into Run.model
- Parameters:
run (Run) – The run to load the weights into.
dataset (str) – The dataset to load the weights from.
criterion (str) – The criterion to load the weights from.
- Raises:
ValueError – If the best iteration is not available.
Examples
>>> store = WeightsStore() >>> run = Run() >>> dataset = 'mnist' >>> criterion = 'accuracy' >>> store.load_best(run, dataset, criterion)
- abstract latest_iteration(run: str) int | None
Return the latest iteration for which weights are available for the given run.
- Parameters:
run (str) – The name of the run.
- Returns:
The latest iteration for which weights are available.
- Return type:
int
- Raises:
ValueError – If no weights are available for the given run.
Examples
>>> store = WeightsStore() >>> run = 'run_0' >>> store.latest_iteration(run)
- abstract store_weights(run: dacapo.experiments.run.Run, iteration: int) None
Store the network weights of the given run.
- Parameters:
run (Run) – The run to store the weights of.
iteration (int) – The iteration to store the weights for.
- Raises:
ValueError – If the iteration is already stored.
Examples
>>> store = WeightsStore() >>> run = Run() >>> iteration = 0 >>> store.store_weights(run, iteration)
- abstract retrieve_weights(run: str, iteration: int) Weights
Retrieve the network weights of the given run.
- Parameters:
run (str) – The name of the run.
iteration (int) – The iteration to retrieve the weights for.
- Returns:
The weights of the given run and iteration.
- Return type:
- Raises:
ValueError – If the weights are not available.
Examples
>>> store = WeightsStore() >>> run = 'run_0' >>> iteration = 0 >>> store.retrieve_weights(run, iteration)
- abstract remove(run: str, iteration: int) None
Delete the weights associated with a specific run/iteration
- Parameters:
run (str) – The name of the run.
iteration (int) – The iteration to delete the weights for.
- Raises:
ValueError – If the weights are not available.
Examples
>>> store = WeightsStore() >>> run = 'run_0' >>> iteration = 0 >>> store.remove(run, iteration)
- abstract retrieve_best(run: str, dataset: str, criterion: str) int
Retrieve the best weights for this run/dataset/criterion
- Parameters:
run (str) – The name of the run.
dataset (str) – The dataset to retrieve the best weights for.
criterion (str) – The criterion to retrieve the best weights for.
- Returns:
The iteration of the best weights.
- Return type:
int
- Raises:
ValueError – If the best weights are not available.
Examples
>>> store = WeightsStore() >>> run = 'run_0' >>> dataset = 'mnist' >>> criterion = 'accuracy' >>> store.retrieve_best(run, dataset, criterion)