Closed Sleort closed 2 months ago
I agree this should be added. I personally prefer the .encoder
syntax. We can do it by overloading the getproperty in https://github.com/LuxDL/Lux.jl/blob/d94f947096e2062ba38004b836ef2c06bf64d504/src/layers/containers.jl#L504-L511.
The logic would be:
model.layers
always returns the named tuple.
Is there an easy / "canonical" / "non-hackish" way of extracting (and combining?) parts of a model and its parameters and states in Lux? If not, maybe it should be made?
For example, let's say I'd like to make a simple autoencoder, train it on some data, and then extract the encoder part for some downstream task. I could try to do it like this:
train
autoencoder
and then extract theencoder
part. But whileworks just fine, it is not possible to access the
encoder
directly fromautoencoder
usinggetproperty
:(Sure, in this example I do have access to
encoder
, but let's assume I don't / haven't passed it around...)What does work, is to use integer indexing instead,
but that feels less elegant. And can become cumbersome and error-prone in more complex settings. Furthermore,
and if I had made
autoencoder
as a "flattened"Chain
model instead,then indexing with a range does not work for
ps
andst
:although
works.
The above was done in
Julia v1.10.3
andLux v0.5.41
.