MCPcopy Create free account
hub / github.com/KeepTryingTo/Pytorch-GAN / main

Function main

ProGAN/demo.py:129–192  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127
128
129def main():
130 # initialize gen and disc, note: discriminator should be called critic,
131 # according to WGAN paper (since it no longer outputs between [0, 1])
132 # but really who cares..
133 gen = Generator(
134 Z_DIM, IN_CHANNELS, img_channels=CHANNELS_IMG
135 ).to(DEVICE)
136 critic = Discriminator(
137 Z_DIM, IN_CHANNELS, img_channels=CHANNELS_IMG
138 ).to(DEVICE)
139
140 # initialize optimizers and scalers for FP16 training
141 opt_gen = optim.Adam(gen.parameters(), lr=LEARNING_RATE, betas=(0.0, 0.99))
142 opt_critic = optim.Adam(
143 critic.parameters(), lr=LEARNING_RATE, betas=(0.0, 0.99)
144 )
145 scaler_critic = torch.cuda.amp.GradScaler()
146 scaler_gen = torch.cuda.amp.GradScaler()
147
148 # for tensorboard plotting
149 writer = SummaryWriter(f"logs/gan1")
150
151 if LOAD_MODEL:
152 load_checkpoint(
153 PRE_CHECKPOINT_GEN, gen, opt_gen, LEARNING_RATE,
154 )
155 load_checkpoint(
156 PRE_CHECKPOINT_CRITIC, critic, opt_critic, LEARNING_RATE,
157 )
158
159 gen.train()
160 critic.train()
161
162 tensorboard_step = 0
163 # start at step that corresponds to img size that we set in config
164 #step = 5
165 step = int(log2(START_TRAIN_AT_IMG_SIZE / 4))
166 for num_epochs in PROGRESSIVE_EPOCHS[step:]:
167 alpha = 1e-5 # start with very low alpha
168 loader, dataset = get_loader(4 * 2 ** step) # 4->0, 8->1, 16->2, 32->3, 64 -> 4
169 print(f"Current image size: {4 * 2 ** step}")
170
171 for epoch in range(num_epochs):
172 print(f"Epoch [{epoch+1}/{num_epochs}]")
173 tensorboard_step, alpha = train_fn(
174 critic,
175 gen,
176 loader,
177 dataset,
178 step,
179 alpha,
180 opt_critic,
181 opt_gen,
182 tensorboard_step,
183 writer,
184 scaler_gen,
185 scaler_critic,
186 )

Callers 1

demo.pyFile · 0.70

Calls 6

GeneratorClass · 0.70
DiscriminatorClass · 0.70
load_checkpointFunction · 0.70
get_loaderFunction · 0.70
train_fnFunction · 0.70
save_checkpointFunction · 0.70

Tested by

no test coverage detected