model
Model
Bases: Named
, Protocol
Base class for models.
A model is used to predict outputs for given inputs.
preprocess(input_features)
Preprocess pipeline step.
Source code in src/flowcean/core/model.py
25 26 27 |
|
predict(input_features)
Predict outputs for given inputs, applying transforms and hooks.
Source code in src/flowcean/core/model.py
40 41 42 43 44 |
|
__call__(input_features)
Predict outputs for given inputs, applying transforms and hooks.
Source code in src/flowcean/core/model.py
46 47 48 49 |
|
postprocess(output)
Postprocess pipeline step.
Source code in src/flowcean/core/model.py
51 52 53 |
|
save(file)
Save the model to the file.
This method can be used to save a flowcean model to a file or a file-like object. To save a model to a file use
model.save("model.fml")
The resulting file will contain the model any any attached transforms.
It can be loaded again using the load
method from the Model
class.
This method uses pickle to serialize the model, so child classes should
ensure that all attributes are pickleable. If this is not the case, the
child class should override this method to implement custom
serialization logic, or use the __getstate__
and __setstate__
methods to control what is serialized (see https://docs.python.org/3/library/pickle.html#pickling-class-instances).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
Path | str | BinaryIO
|
The file like object to save the model to. |
required |
Source code in src/flowcean/core/model.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
load(file)
staticmethod
Load a model from file.
This method can be used to load a previously saved flowcean model from a file or a file-like object. To load a model from a file use
model = Model.load("model.fml")
The load
method will automatically determine the model type and and
any attached transforms and will load them into the correct model
class.
As this method uses the pickle
module to load the model, it is not
safe to load models from untrusted sources as this could lead to
arbitrary code execution!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
Path | str | BinaryIO
|
The file like object to load the model from. |
required |
Source code in src/flowcean/core/model.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|