ImplicitModel
ImplicitModel()
Bases: Module
Base class of all neural models of the library.
Provides the utilities for saving/loading models onto/from the disk. Any subclass inheriting this one will automatically store the arguments given to its constructor, so that they can be saved alongside the model's parameters and reloaded in another session.
class ExampleNet(ImplicitModel):
def __init__(self, x:int = 2):
super().__init__()
self.x = x
ExampleNet(3).save("example_model.inr")
model = implicitlab.nn.load_model("example_model.inr") # an ExampleNet instance
print(model.x)
load(path, map_location='cpu')
classmethod
Loads an implicit model from a file on the disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
path to the saved file. |
required |
map_location
|
str
|
|
'cpu'
|
Raises:
| Type | Description |
|---|---|
Exception
|
Fails if the loaded file is not an implicitlab model file. |
Returns:
| Name | Type | Description |
|---|---|---|
ImplicitModel |
the loaded model with correct type, architecture and weights. |
save(path)
Saves the model to the disk in a file prescribed by path. This methods saves both the model's weights as well as its configuration, i.e. its type as a subclass of ImplicitModel and the arguments of its constructor. That way, the model can be re-instanciated automatically provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
path to the file into which the model will be saved. We use |
required |