trying to train a VAE network, and the use the encoder part later on for other things.
I have:
class Encoder(nn.Module):
    def __init__(self):
    ...
    def init_weights(self,m):
        #print(m)
        for name, param in m.named_parameters():
        if 'bias' in name:
          nn.init.constant_(param, 0.0)
        elif 'weight' in name:
          nn.init.normal_(param, mean=0.0, std=0.001)
    ....


class Decoder(nn.Module):
    def __init__(self):
        ...
    def init_weights(self,m):
        #print(m)
        for name, param in m.named_parameters():
        if 'bias' in name:
          nn.init.constant_(param, 0.0)
        elif 'weight' in name:
          nn.init.normal_(param, mean=0.0, std=0.001)

as for now they both are separate classes.
I do want to train them together meaning, (Encoder ->Decoder) as a big network, with 1 loss function.
but after the training is done, i want to use only the trained encoder part.
I am not sure of how to do that.
if i keep the two network separated, i will need two criterion & optimizer, but i want them to be the same thing. and i am not sure how can I use the same loss to train both together.
and if i combined those to one class , i may be able to train, but how to save and use only the trained encoder later on?