Serialisation Guide¶
Serialization¶
Sonosco provides it’s own serialization method. It allows to save complete state of your training. Including parameters and meta-parameters.
In order to enable the serialization follow those steps:
- add the
@sonosco.serialization.serializabledecorator all the classes you wish to serialize. - Instead of using
__init__()method put all the fields of your object on the class level (Type annotation are mandatory!) (Currently only primitives, lists of primitives, types, callables and other serializable objects are supported). If you wish to perform some custom initialization use__post_init__(self)method (__init__(self)is auto generated!)
@serializable
class Example:
arg: int = 0
def __post_init__(self):
pass
- Sonosco will generate
__serialize__method for you, however this should not be used directly. Instead usesonosco.serialization.Serializer.serializemethod:
Serializer().serialize(Example(), "/path/to/save/object")
Deserialization¶
In order to deserialize class use: sonosco.serialization.Deserializer.deserialize method.
ex = Deserializer.deserialize(Example, "/path/to/save/object")
Only object serialized with sonosco @serializable can be deserialized!
That’s it. To see a full example, check out this serialization example or check one of the models in the sonosco repository.
Check also inline docs for more details about different features of (de)serialization.