How to split Autoencoder to two NNs?

I have an autoencoder with 2 submodules (trained and ready). How to split it to two separate NNs each with its own weights and forward method?

How did you define your current model?
If both submodules are instances of nn.Sequential, you could recreate them separately outside of your current model and just load the state_dicts into them.

If your modules and forward is more complicated, you could still redefine the submodules, but would most likely have to filter out unwanted keys from the state_dict of the complete model before loading it into the submodels.

1 Like

Thank you ptrblck . I figured if my ultimate goal is to split the AE, then the best thing is build two different NNs for encoder and decoder, and then combine them in a third one for training purpose.

1 Like

That sounds like the best idea! :slight_smile: