Skip to content

Instantly share code, notes, and snippets.

@AFAgarap
Last active December 25, 2020 18:34
Show Gist options
  • Save AFAgarap/b513ab07ea78a2be7add3182f5ad5382 to your computer and use it in GitHub Desktop.
Save AFAgarap/b513ab07ea78a2be7add3182f5ad5382 to your computer and use it in GitHub Desktop.
PyTorch implementation of a vanilla autoencoder model.
class AE(nn.Module):
def __init__(self, **kwargs):
super().__init__()
self.encoder_hidden_layer = nn.Linear(
in_features=kwargs["input_shape"], out_features=128
)
self.encoder_output_layer = nn.Linear(
in_features=128, out_features=128
)
self.decoder_hidden_layer = nn.Linear(
in_features=128, out_features=128
)
self.decoder_output_layer = nn.Linear(
in_features=128, out_features=kwargs["input_shape"]
)
def forward(self, features):
activation = self.encoder_hidden_layer(features)
activation = torch.relu(activation)
code = self.encoder_output_layer(activation)
code = torch.relu(code)
activation = self.decoder_hidden_layer(code)
activation = torch.relu(activation)
activation = self.decoder_output_layer(activation)
reconstructed = torch.relu(activation)
return reconstructed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment