| 9 | from torchinfo import summary |
| 10 | |
| 11 | class AE(torch.nn.Module): |
| 12 | def __init__(self,in_feautres = 784,out_features = 128): |
| 13 | super(AE, self).__init__() |
| 14 | self.encoder = torch.nn.Sequential( |
| 15 | torch.nn.Linear(in_features=in_feautres,out_features=512), |
| 16 | torch.nn.Dropout(p = 0.5), |
| 17 | torch.nn.ReLU(), |
| 18 | |
| 19 | torch.nn.Linear(in_features=512,out_features=256), |
| 20 | torch.nn.Dropout(p=0.5), |
| 21 | torch.nn.ReLU(), |
| 22 | |
| 23 | torch.nn.Linear(in_features=256,out_features=out_features), |
| 24 | ) |
| 25 | self.decoder = torch.nn.Sequential( |
| 26 | torch.nn.Linear(in_features=out_features, out_features=256), |
| 27 | torch.nn.Dropout(p=0.5), |
| 28 | torch.nn.ReLU(), |
| 29 | |
| 30 | torch.nn.Linear(in_features=256, out_features=512), |
| 31 | torch.nn.Dropout(p=0.5), |
| 32 | torch.nn.ReLU(), |
| 33 | |
| 34 | torch.nn.Linear(in_features=512, out_features=in_feautres) |
| 35 | ) |
| 36 | def forward(self,x): |
| 37 | x = x.view(-1,784) |
| 38 | e_x = self.encoder(x) |
| 39 | d_x = self.decoder(e_x) |
| 40 | img = d_x.view(-1,28,28) |
| 41 | return img |
| 42 | |
| 43 | if __name__ == '__main__': |
| 44 | x= torch.randn(size = (1,28,28),device='cpu') |