-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain_vqvae.py
41 lines (32 loc) · 1.18 KB
/
train_vqvae.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import torchvision
import torchvision.transforms as transforms
from torch.utils.data import DataLoader
from vqvae import VQVAE
import pytorch_lightning as pl
def main():
args = dict(
batch_size=32,
lr=0.000056,
epochs=10
)
transform = transforms.Compose([transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
train_set = torchvision.datasets.CIFAR10(root='./data', train=True,
download=True, transform=transform)
train_loader = DataLoader(train_set, batch_size=args.batch_size, shuffle=True)
test_set = torchvision.datasets.CIFAR10(root='./data', train=False,
download=True, transform=transform)
test_loader = DataLoader(test_set, batch_size=args.batch_size, shuffle=False)
model = VQVAE(
in_channel=3,
channel=128,
n_res_block=2,
n_res_channel=64,
embed_dim=64,
n_embed=512,
params=config
)
trainer = pl.Trainer(gpus=1, max_epochs=args.epochs)
trainer.fit(model, train_loader, test_loader)
if __name__ == '__main__':
main()