Input is taken from intermediate layer of the model:
model.fc3.register_forward_hook(get_activation('fc3'))
encoded = model(input)

and then passed to the new model:
new_model = nn.Sequential(*[Flatten(), *list(model.children())[3:]])
decoded = new_model(encoded)