Flux.state
— Functionstate(x)
Return an object with the same nested structure as x
according to Functors.children
, but made only of basic containers (e.g. named tuples, tuples, arrays, and dictionaries).
Besides trainable and non-trainable arrays, the state will contain leaf nodes that are not arrays, such as numbers, symbols, strings, and nothing values. The leaf types that end up in the state could increase in the future.
This method is particularly useful for saving and loading models, since the state contain only simple data types that can be easily serialized.
The state can be passed to loadmodel!
to restore the model.
Examples
Copy the state into another model
julia> m1 = Chain(Dense(1, 2, tanh; init=ones), Dense(2, 1; init=ones));
+true