Flux2Lux.FluxLayer
— TypeFluxLayer(layer)
Serves as a compatibility layer between Flux and Lux. This uses Optimisers.destructure
API internally.
Lux was written to overcome the limitations of destructure
+ Flux
. It is recommended to rewrite your l in Lux instead of using this layer.
Introducing this Layer in your model will lead to type instabilities, given the way Optimisers.destructure
works.
Arguments
layer
: Flux layer
Parameters
p
: Flattened parameters of thelayer
Flux2Lux.transform
— Methodtransform(l; preserve_ps_st::Bool=false, force_preserve::Bool=false)
Convert a Flux Model to Lux Model.
transform
always ingores the active
field of some of the Flux layers. This is almost never going to be supported on Flux2Lux.
Arguments
l
: Flux l or any generic Julia function / object.
Keyword Arguments
preserve_ps_st
: Set totrue
to preserve the states and parameters of the l. This attempts the best possible way to preserve the original model. But it might fail. If you need to override possible failures, setforce_preserve
totrue
.force_preserve
: Some of the transformations with state and parameters preservation haven't been implemented yet, in these cases, ifforce_transform
isfalse
a warning will be printed and a core Lux layer will be returned. Else, it will create aFluxLayer
.
Examples
using Flux2Lux, Lux, Metalhead, Random
m = ResNet(18)
m2 = transform(m.layers)
x = randn(Float32, 224, 224, 3, 1);
ps, st = Lux.setup(Random.default_rng(), m2);
m2(x, ps, st)