chainer.serializers.NpzDeserializer¶
-
class
chainer.serializers.NpzDeserializer(npz, path='', strict=True, ignore_names=None)[source]¶ Deserializer for NPZ format.
This is the standard deserializer in Chainer. This deserializer can be used to read an object serialized by
save_npz().- Parameters
npz – npz file object.
path – The base path that the deserialization starts from.
strict (bool) – If
True, the deserializer raises an error when an expected value is not found in the given NPZ file. Otherwise, it ignores the value and skip deserialization.ignore_names (string, callable or list of them) – If callable, it is a function that takes a name of a parameter and a persistent and returns
Truewhen it needs to be skipped. If string, this is a name of a parameter or persistent that are going to be skipped. This can also be a list of callables and strings that behave as described above.
Methods
-
__call__(key, value)[source]¶ Serializes or deserializes a value by given name.
This operator saves or loads a value by given name.
If this is a serializer, then the value is simply saved at the key. Note that some type information might be missed depending on the implementation (and the target file format).
If this is a deserializer, then the value is loaded by the key. The deserialization differently works on scalars and arrays. For scalars, the
valueargument is used just for determining the type of restored value to be converted, and the converted value is returned. For arrays, the restored elements are directly copied into thevalueargument. String values are treated like scalars.Note
Serializers and deserializers are required to correctly handle the
Nonevalue. WhenvalueisNone, serializers save it in format-dependent ways, and deserializers just return the loaded value. When the savedNonevalue is loaded by a deserializer, it should quietly return theNonevalue without modifying thevalueobject.- Parameters
key (str) – Name of the serialization entry.
value (scalar, numpy.ndarray, cupy.ndarray, None, or str) – Object to be (de)serialized.
Noneis only supported by deserializers.
- Returns
Serialized or deserialized value.