Kevin Li commited on
Upload folder using huggingface_hub
Browse filesFiles changed (6)
- __pycache__/models.cpython-310.pycAdded
- decoder.ptAdded+3
- decoder.pthAdded+3
- decoder_earlystop_55.ptAdded+3
- decoder_earlystop_82.ptAdded+3
- models.pyAdded+74
123version https://git-lfs.github.com/spec/v1oid sha256:73c42a41e9a9bf115ea236aa5dfe7690d07123270c362217d0adc4d18ce2a4e8size 802465833123version https://git-lfs.github.com/spec/v1oid sha256:dc47dc8c28c257501ee1e843d76772fca1b803c25d196b122d65b549967c22c9size 2406851328123version https://git-lfs.github.com/spec/v1oid sha256:db2cfe59b08c6b05178d213901e71c07e8d843318caaf198ccba1661283372f9size 802465833123version https://git-lfs.github.com/spec/v1oid sha256:9656b7cb181a8a6cc3af9fe9381a5137fe6249e2e03cf27abfce79bc7062db9csize 8024658331234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374import torchimport torch.nn as nn
class Decoder(nn.Module): def __init__(self, input_dim, hidden_dim, gamma=0.1): super().__init__() self.input_dim = input_dim self.hidden_dim = hidden_dim self.gamma = gamma self.float() #should be 512, 1024 self.fc = nn.Sequential( nn.Linear(input_dim, hidden_dim), nn.BatchNorm1d(hidden_dim), nn.ReLU(), nn.Linear(hidden_dim, hidden_dim * 2), nn.BatchNorm1d(hidden_dim * 2), nn.ReLU(), nn.Linear(hidden_dim * 2, hidden_dim * 4), nn.BatchNorm1d(hidden_dim * 4), nn.ReLU(), nn.Linear(hidden_dim * 4, hidden_dim * 8), nn.BatchNorm1d(hidden_dim * 8), nn.ReLU(), nn.Linear(hidden_dim * 8, hidden_dim * 4 * 4), nn.BatchNorm1d(hidden_dim * 4 * 4), nn.ReLU() )
self.decoder = nn.Sequential( nn.ConvTranspose2d(1024, 768, kernel_size=4, stride=2, padding=1), nn.BatchNorm2d(768), nn.ReLU(), nn.ConvTranspose2d(768, 512, kernel_size=4, stride=2, padding=1), nn.BatchNorm2d(512), nn.ReLU(), nn.ConvTranspose2d(512, 256, kernel_size=4, stride=2, padding=1), nn.BatchNorm2d(256), nn.ReLU(), nn.ConvTranspose2d(256, 128, kernel_size=4, stride=2, padding=1), nn.BatchNorm2d(128), nn.ReLU(), nn.ConvTranspose2d(128, 64, kernel_size=4, stride=2, padding=1), nn.BatchNorm2d(64), nn.ReLU(), nn.ConvTranspose2d(64, 32, kernel_size=4, stride=2, padding=1), nn.BatchNorm2d(32), nn.ReLU(), nn.Conv2d(32, 3, kernel_size=3, padding=1), nn.Sigmoid() ) def forward(self, z): batch_size = z.shape[0] # adding noise to inputs gamma = 0.05 z = z + self.gamma * torch.randn_like(z) z = self.fc(z) z = z.view(batch_size, 1024, 4, 4) return self.decoder(z) def get_loss(self, emb, x): x_hat = self.forward(emb) l = nn.MSELoss(reduction="mean") loss = l(x_hat, x) return loss @torch.no_grad() def sample(self, samples, device): samples = samples.to(device) x_hat = self.forward(samples)
return x_hat__pycache__/models.cpython-310.pycAdded
decoder.ptAdded+3
decoder.pthAdded+3
decoder_earlystop_55.ptAdded+3
decoder_earlystop_82.ptAdded+3
models.pyAdded+74