Skip to content

Commit feef4de

Browse files
committed
Add logs, update readme
1 parent e608a82 commit feef4de

12 files changed

+32
-1341
lines changed

README.md

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# BigGAN-PyTorch
2-
The author's authorized and officially unofficial PyTorch BigGAN implementation.
2+
The author's officially unofficial PyTorch BigGAN implementation.
33

44
![Dogball? Dogball!](imgs/header_image.jpg?raw=true "Dogball? Dogball!")
55

@@ -40,15 +40,20 @@ After training, one can use `sample.py` to produce additional samples and interp
4040
By default, everything is saved to weights/samples/logs/data folders which are assumed to be in the same folder as this repo.
4141
You can point all of these to a different base folder using the `--base_root` argument, or pick specific locations for each of these with their respective arguments (e.g. `--logs_root`).
4242

43-
Additionally, we include scripts to run a model on CIFAR, and to run BigGAN-deep, SA-GAN (with EMA) and SN-GAN on ImageNet. The SA-GAN code assumes you have 4xTitanX (or equivalent in terms of GPU RAM) and will run with a batch size of 128 and 2 gradient accumulations.
43+
We include scripts to run BigGAN-deep, but we have not fully trained a model using them, so consider them untested. Additionally, we include scripts to run a model on CIFAR, and to run SA-GAN (with EMA) and SN-GAN on ImageNet. The SA-GAN code assumes you have 4xTitanX (or equivalent in terms of GPU RAM) and will run with a batch size of 128 and 2 gradient accumulations.
4444

45+
## An Important Note on Inception Metrics
46+
This repo uses the PyTorch in-built inception network to calculate IS and FID.
47+
These scores are different from the scores you would get using the official TF inception code, and are only for monitoring purposes!
48+
Run sample.py on your model, with the `--sample_npz` argument, then run inception_tf13 to calculate the actual TensorFlow IS. Note that you will need to have TensorFlow 1.3 or earlier installed, as TF1.4+ breaks the original IS code.
4549

4650
## Pretrained models
4751
We include two pretrained model checkpoints (with G, D, the EMA copy of G, the optimizers, and the state dict):
48-
- The main checkpoint is for a BigGAN trained on ImageNet at 128x128, using BS256 and 8 gradient accumulations, taken just before collapse: LINK
52+
- The main checkpoint is for a BigGAN trained on ImageNet at 128x128, using BS256 and 8 gradient accumulations, taken just before collapse, with a TF Inception Score of 97.35 +/- 1.79: [LINK](https://drive.google.com/open?id=1nAle7FCVFZdix2--ks0r5JBkFnKw8ctW)
4953
- An earlier checkpoint of the first model (100k G iters), at high performance but well before collapse, which may be easier to fine-tune: LINK
5054

51-
--graphic for main checkpoint--
55+
![PyTorch Inception Score](imgs/IS.svg)
56+
<img src="imgs/IS.svg">
5257

5358
Pretrained models for Places-365 coming soon.
5459

@@ -84,10 +89,6 @@ The two variants we tried (a custom, naive one and the one included in this repo
8489
- Gradient accumulation means that we update the SV estimates and the BN statistics 8 times more frequently. This means that the BN stats are much closer to standing stats, and that the singular value estimates tend to be more accurate.
8590
Because of this, we measure metrics by default with G in test mode (using the BatchNorm running stat estimates instead of computing standing stats as in the paper). We do still support standing stats (see the sample.sh scripts).
8691
This could also conceivably result in gradients from the earlier accumulations being stale, but in practice this does not appear to be a problem.
87-
- This repo uses the PyTorch in-built inception network to calculate IS and FID.
88-
These scores are different from the scores you would get using the official TF inception code, and are only for monitoring purposes!
89-
IS using the PyTorch net tends to be 5-10% lower than using the official TF net.
90-
Run sample.py on your model, with the `--sample_npz` argument, then run inception_tf13 to calculate the actual TF IS. Note that you will need to have TensorFlow 1.3 or earlier installed, as TF1.4+ breaks the original IS code.
9192
- The currently provided pretrained models were not trained with orthogonal regularization. Training without ortho reg seems to increase the probability that models will not be amenable to truncation,
9293
but it looks like this particular model got a winning ticket. Regardless, we provide two highly optimized (fast and minimal memory consumption) ortho reg implementations which directly compute the ortho reg. gradients.
9394

@@ -109,6 +110,17 @@ Want to work on or improve this code? There are a couple things this repo would
109110

110111
## Misc Notes
111112
See [This directory](https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a) for ImageNet labels.
113+
If you use this code, please cite
114+
```text
115+
@inproceedings{
116+
brock2018large,
117+
title={Large Scale {GAN} Training for High Fidelity Natural Image Synthesis},
118+
author={Andrew Brock and Jeff Donahue and Karen Simonyan},
119+
booktitle={International Conference on Learning Representations},
120+
year={2019},
121+
url={https://openreview.net/forum?id=B1xsqj09Fm},
122+
}
123+
```
112124

113125
## Acknowledgments
114126
Thanks to Google for the generous cloud credit donations.

animal_hash.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
'Cod', 'Collie', 'Coral', 'Cormorant', 'Cougar', 'Cow', 'Coyote',
1313
'Crab', 'Crane', 'Crocodile', 'Crow', 'Curlew', 'Cuscus', 'Cuttlefish',
1414
'Dachshund', 'Dalmatian', 'Deer', 'Dhole', 'Dingo', 'Dinosaur', 'Discus',
15-
'Dodo', 'Dog', 'Dogfish', 'Dolphin', 'Donkey', 'Dormouse', 'Dotterel',
15+
'Dodo', 'Dog', 'Dogball', 'Dogfish', 'Dolphin', 'Donkey', 'Dormouse',
1616
'Dove', 'Dragonfly', 'Drever', 'Duck', 'Dugong', 'Dunker', 'Dunlin',
17-
'Eagle', 'Earwig', 'Echidna', 'Eel', 'Eland', 'Elephant', 'ElephantSeal',
17+
'Eagle', 'Earwig', 'Echidna', 'Eel', 'Eland', 'Elephant', 'ElephantSeal',
1818
'Elk', 'Emu', 'Falcon', 'Ferret', 'Finch', 'Fish', 'Flamingo', 'Flounder',
1919
'Fly', 'Fossa', 'Fox', 'Frigatebird', 'Frog', 'Galago', 'Gar', 'Gaur',
2020
'Gazelle', 'Gecko', 'Gerbil', 'Gharial', 'GiantPanda', 'Gibbon', 'Giraffe',

imgs/D Singular Values.png

228 KB
Loading

imgs/G Singular Values.png

231 KB
Loading

imgs/Losses.png

108 KB
Loading

logs/compare_IS.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
d = dir();
1111
j = 1;
1212
for i = 1:length(d)
13-
if any(strfind(d(i).name,'.jsonl'))%any(strfind(d(i).name,'I128')) && %&& any(strfind(d(i).name,'LARS'))
13+
if any(strfind(d(i).name,'.jsonl'))
1414
s = [s; d(i).name];
1515
end
1616
end

logs/metalog.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
datetime: 2019-03-18 13:27:59.181225
2+
config: {'dataset': 'I128_hdf5', 'augment': False, 'num_workers': 8, 'pin_memory': True, 'shuffle': True, 'load_in_mem': True, 'use_multiepoch_sampler': True, 'model': 'model', 'G_param': 'SN', 'D_param': 'SN', 'G_ch': 96, 'D_ch': 96, 'G_depth': 1, 'D_depth': 1, 'D_wide': True, 'G_shared': True, 'shared_dim': 128, 'dim_z': 120, 'z_var': 1.0, 'hier': True, 'cross_replica': False, 'mybn': False, 'G_nl': 'inplace_relu', 'D_nl': 'inplace_relu', 'G_attn': '64', 'D_attn': '64', 'norm_style': 'bn', 'seed': 0, 'G_init': 'ortho', 'D_init': 'ortho', 'skip_init': True, 'G_lr': 0.0001, 'D_lr': 0.0004, 'G_B1': 0.0, 'D_B1': 0.0, 'G_B2': 0.999, 'D_B2': 0.999, 'batch_size': 256, 'G_batch_size': 0, 'num_G_accumulations': 8, 'num_D_steps': 1, 'num_D_accumulations': 8, 'split_D': False, 'num_epochs': 400, 'parallel': True, 'G_fp16': False, 'D_fp16': False, 'D_mixed_precision': False, 'G_mixed_precision': False, 'accumulate_stats': False, 'num_standing_accumulations': 16, 'G_eval_mode': True, 'save_every': 500, 'num_save_copies': 2, 'num_best_copies': 5, 'which_best': 'IS', 'no_fid': False, 'test_every': 2000, 'num_inception_images': 50000, 'hashname': False, 'base_root': '', 'dataset_root': 'data', 'weights_root': 'weights', 'logs_root': 'logs', 'samples_root': 'samples', 'pbar': 'mine', 'name_suffix': '', 'experiment_name': 'Jade_BigGAN_B1_bs256x8_fp32', 'config_from_name': False, 'ema': True, 'ema_decay': 0.9999, 'use_ema': True, 'ema_start': 20000, 'adam_eps': 1e-06, 'BN_eps': 1e-05, 'SN_eps': 1e-06, 'num_G_SVs': 1, 'num_D_SVs': 1, 'num_G_SV_itrs': 1, 'num_D_SV_itrs': 1, 'G_ortho': 0.0, 'D_ortho': 0.0, 'toggle_grads': True, 'which_train_fn': 'GAN', 'load_weights': '', 'resume': True, 'logstyle': '%3.3e', 'log_G_spectra': False, 'log_D_spectra': False, 'sv_log_interval': 10, 'resolution': 128, 'n_classes': 1000, 'G_activation': ReLU(inplace), 'D_activation': ReLU(inplace)}
3+
state: {'itr': 137500, 'epoch': 2, 'save_num': 0, 'save_best_num': 1, 'best_IS': 91.509384, 'best_FID': tensor(9.7711, 'config': {'dataset': 'I128_hdf5', 'augment': False, 'num_workers': 8, 'pin_memory': True, 'shuffle': True, 'load_in_mem': True, 'use_multiepoch_sampler': True, 'model': 'model', 'G_param': 'SN', 'D_param': 'SN', 'G_ch': 96, 'D_ch': 96, 'D_wide': True, 'G_shared': True, 'shared_dim': 128, 'dim_z': 120, 'hier': True, 'cross_replica': False, 'mybn': False, 'G_nl': 'inplace_relu', 'D_nl': 'inplace_relu', 'G_attn': '64', 'D_attn': '64', 'norm_style': 'bn', 'seed': 0, 'G_init': 'ortho', 'D_init': 'ortho', 'skip_init': False, 'G_lr': 0.0001, 'D_lr': 0.0004, 'G_B1': 0.0, 'D_B1': 0.0, 'G_B2': 0.999, 'D_B2': 0.999, 'batch_size': 256, 'G_batch_size': 0, 'num_G_accumulations': 8, 'num_D_steps': 1, 'num_D_accumulations': 8, 'split_D': False, 'num_epochs': 100, 'parallel': True, 'G_fp16': False, 'D_fp16': False, 'D_mixed_precision': False, 'G_mixed_precision': False, 'accumulate_stats': False, 'num_standing_accumulations': 16, 'BN_sync': False, 'G_eval_mode': True, 'save_every': 500, 'num_save_copies': 2, 'num_best_copies': 5, 'which_best': 'IS', 'no_fid': False, 'test_every': 2000, 'num_inception_images': 50000, 'hashname': False, 'base_root': '', 'dataset_root': 'data', 'weights_root': 'weights', 'logs_root': 'logs', 'samples_root': 'samples', 'pbar': 'mine', 'name_suffix': '', 'experiment_name': 'Jade_BigGAN_B1_bs256x8_fp32', 'ema': True, 'ema_decay': 0.9999, 'use_ema': True, 'ema_start': 20000, 'adam_eps': 1e-06, 'BN_eps': 1e-05, 'SN_eps': 1e-06, 'num_G_SVs': 1, 'num_D_SVs': 1, 'num_G_SV_itrs': 1, 'num_D_SV_itrs': 1, 'G_ortho': 0.0, 'D_ortho': 0.0, 'toggle_grads': True, 'which_train_fn': 'GAN', 'load_weights': '', 'resume': False, 'logstyle': '%3.3e', 'log_G_spectra': False, 'log_D_spectra': False, 'sv_log_interval': 10, 'resolution': 128, 'n_classes': 1000, 'G_activation': ReLU(inplace), 'D_activation': ReLU(inplace)}}

logs/process_training.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
%% Get all training logs for a given run
9-
target_dir = 'new\Jade_BigGAN_B1_bs256x8_fp32';
9+
target_dir = '.';
1010
s = {};
1111
nm = {};
1212
d = dir(target_dir);
@@ -103,7 +103,7 @@
103103
% plot(losses{i,1}, losses{i,2},'color', losses{i,4}, 'HandleVisibility','off');
104104
plot(losses{i,1},losses{i,3},'color',losses{i,5});
105105
end
106-
clickableLegend(legendL, 'Interpreter', 'none'); title('Losses'); xlabel('Generator itr'); ylabel('loss'); axis([0, max(s{end,2}), -1, 4]);
106+
legend(legendL, 'Interpreter', 'none'); title('Losses'); xlabel('Generator itr'); ylabel('loss'); axis([0, max(s{end,2}), -1, 4]);
107107

108-
figure(2); clickableLegend(legendG,'Interpreter','none'); title('Singular Values in G'); xlabel('Generator itr'); ylabel('SV0');
109-
figure(3); clickableLegend(legendD, 'Interpreter', 'none'); title('Singular Values in D'); xlabel('Generator itr'); ylabel('SV0');
108+
figure(2); legend(legendG,'Interpreter','none'); title('Singular Values in G'); xlabel('Generator itr'); ylabel('SV0');
109+
figure(3); legend(legendD, 'Interpreter', 'none'); title('Singular Values in D'); xlabel('Generator itr'); ylabel('SV0');

sample.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def get_metrics():
153153
outstring += 'with batch size %d, ' % G_batch_size
154154
if config['accumulate_stats']:
155155
outstring += 'using %d standing stat accumulations, ' % config['num_standing_accumulations']
156-
outstring += 'Itr %d: Inception Score is %3.3f +/- %3.3f, FID is %5.4f' % (state_dict['itr'], IS_mean, IS_std, FID)
156+
outstring += 'Itr %d: PYTORCH UNOFFICIAL Inception Score is %3.3f +/- %3.3f, PYTORCH UNOFFICIAL FID is %5.4f' % (state_dict['itr'], IS_mean, IS_std, FID)
157157
print(outstring)
158158
if config['sample_inception_metrics']:
159159
print('Calculating Inception metrics...')

0 commit comments

Comments
 (0)