-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
40 lines (30 loc) · 939 Bytes
/
main.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
import random
import numpy as np
import pytorch_lightning as pl
import torch
from absl import app, flags
from data_module import MNISTDataModule
from models import GAN
FLAGS = flags.FLAGS
flags.DEFINE_integer("n_batch", 256, "batch size")
flags.DEFINE_integer("seed", 7, "random seed")
flags.DEFINE_float("lr", 0.001, "learning rate")
DEVICE = torch.device(("cuda" if torch.cuda.is_available() else "cpu"))
if DEVICE == "cuda":
accelerator = "gpu"
GPUS = min(1, torch.cuda.device_count())
else:
accelerator = "cpu"
GPUS = None
def main(argv):
random.seed(FLAGS.seed)
np.random.seed(FLAGS.seed)
torch.manual_seed(FLAGS.seed)
data = MNISTDataModule(batch_size=FLAGS.n_batch)
model = GAN(lr=FLAGS.lr)
model.plot_imgs()
trainer = pl.Trainer(max_epochs=100, gpus=GPUS, accelerator=accelerator)
trainer.fit(model, data)
model.plot_imgs()
if __name__ == "__main__":
app.run(main)