Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
After finishing training, a net has many attributes that are not needed anymore when only inference is performed. A user might want to get rid of these attributes to keep the size of the net small. E.g., depending on the chosen optimizer, it can be quite big. (In addition, there is the advantage that the less attributes exist, the more likely a net can be unpickled that used a different version of skorch, PyTorch, etc.). This commit adds a convenience method, trim_for_prediction, that takes care of removing all attributes that are no longer required. Implementation In addition to removing unneeded attributes, make sure to clear callbacks (which, at least at the moment, are used exclusively during training), the history, the train_split, and the iterator_train. The training state is set to False. Also, set an attribute after trimming. When the net is initialized/fitted, check if the net is trimmed and raise a useful error message for the user. This check does not require the attribute to be set, to prevent possible compatibility issues. For this, a new training readiness check and exception are introduced.
- Loading branch information
1 parent
f99eea9
commit b1cacb1
Showing
4 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters