Skip to content

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

map_location parameter for torch.load. Defaults to "cpu".

'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 .inr extension as a convention.

required

ImplicitSequential(*models)

Bases: ImplicitModel

Chains several models, for instance an input encoding followed by a network:

model = ImplicitSequential(
    RandomFourierEncoding(3, 256), 
    SirenNet(256, 128, 4)
)

load_model(path, map_location='cpu')

Loads an implicit model. Alias for ImplicitModel.load

# The two lines below are equivalent:
model = IL.nn.load_model("path/to/model.inr")
model = IL.ImplicitModel.load("path/to/model.inr")