Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Update Biggan benchmark with biggan trained on imagenet of the best metrics #107

Merged
merged 11 commits into from
Sep 6, 2021
Prev Previous commit
Next Next commit
Modify benchmark and add more configs for users
  • Loading branch information
yangyifei authored and yangyifei committed Jul 30, 2021
commit 5a4686323fa28d7483dfdf6764f1caaa1436c15f
33 changes: 33 additions & 0 deletions configs/_base_/models/biggan-deep_128x128_cvt_hugging-face_rgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
model = dict(
type='BasiccGAN',
generator=dict(
type='BigGANDeepGenerator',
output_scale=128,
noise_size=128,
num_classes=1000,
base_channels=128,
shared_dim=128,
with_shared_embedding=True,
sn_eps=1e-6,
init_type='ortho',
act_cfg=dict(type='ReLU', inplace=True),
concat_noise=True,
auto_sync_bn=False,
rgb2bgr=True),
discriminator=dict(
type='BigGANDeepDiscriminator',
input_scale=128,
num_classes=1000,
base_channels=128,
sn_eps=1e-6,
init_type='ortho',
act_cfg=dict(type='ReLU', inplace=True),
with_spectral_norm=True),
gan_loss=dict(type='GANLoss', gan_type='hinge'))

train_cfg = dict(
disc_steps=8, gen_steps=1, batch_accumulation_steps=8, use_ema=True)
test_cfg = None
optimizer = dict(
generator=dict(type='Adam', lr=0.0001, betas=(0.0, 0.999), eps=1e-6),
discriminator=dict(type='Adam', lr=0.0004, betas=(0.0, 0.999), eps=1e-6))
33 changes: 33 additions & 0 deletions configs/_base_/models/biggan-deep_256x256_cvt_hugging-face_rgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
model = dict(
type='BasiccGAN',
generator=dict(
type='BigGANDeepGenerator',
output_scale=256,
noise_size=128,
num_classes=1000,
base_channels=128,
shared_dim=128,
with_shared_embedding=True,
sn_eps=1e-6,
init_type='ortho',
act_cfg=dict(type='ReLU', inplace=True),
concat_noise=True,
auto_sync_bn=False,
rgb2bgr=True),
discriminator=dict(
type='BigGANDeepDiscriminator',
input_scale=256,
num_classes=1000,
base_channels=128,
sn_eps=1e-6,
init_type='ortho',
act_cfg=dict(type='ReLU', inplace=True),
with_spectral_norm=True),
gan_loss=dict(type='GANLoss', gan_type='hinge'))

train_cfg = dict(
disc_steps=8, gen_steps=1, batch_accumulation_steps=8, use_ema=True)
test_cfg = None
optimizer = dict(
generator=dict(type='Adam', lr=0.0001, betas=(0.0, 0.999), eps=1e-6),
discriminator=dict(type='Adam', lr=0.0004, betas=(0.0, 0.999), eps=1e-6))
33 changes: 33 additions & 0 deletions configs/_base_/models/biggan-deep_512x512_cvt_hugging-face_rgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
model = dict(
type='BasiccGAN',
generator=dict(
type='BigGANDeepGenerator',
output_scale=512,
noise_size=128,
num_classes=1000,
base_channels=128,
shared_dim=128,
with_shared_embedding=True,
sn_eps=1e-6,
init_type='ortho',
act_cfg=dict(type='ReLU', inplace=True),
concat_noise=True,
auto_sync_bn=False,
rgb2bgr=True),
discriminator=dict(
type='BigGANDeepDiscriminator',
input_scale=512,
num_classes=1000,
base_channels=128,
sn_eps=1e-6,
init_type='ortho',
act_cfg=dict(type='ReLU', inplace=True),
with_spectral_norm=True),
gan_loss=dict(type='GANLoss', gan_type='hinge'))

train_cfg = dict(
disc_steps=8, gen_steps=1, batch_accumulation_steps=8, use_ema=True)
test_cfg = None
optimizer = dict(
generator=dict(type='Adam', lr=0.0001, betas=(0.0, 0.999), eps=1e-6),
discriminator=dict(type='Adam', lr=0.0004, betas=(0.0, 0.999), eps=1e-6))
32 changes: 32 additions & 0 deletions configs/_base_/models/biggan_128x128.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
model = dict(
type='BasiccGAN',
generator=dict(
type='BigGANGenerator',
output_scale=128,
noise_size=120,
num_classes=1000,
base_channels=96,
shared_dim=128,
with_shared_embedding=True,
sn_eps=1e-6,
init_type='ortho',
act_cfg=dict(type='ReLU', inplace=True),
split_noise=True,
auto_sync_bn=False),
discriminator=dict(
type='BigGANDiscriminator',
input_scale=128,
num_classes=1000,
base_channels=96,
sn_eps=1e-6,
init_type='ortho',
act_cfg=dict(type='ReLU', inplace=True),
with_spectral_norm=True),
gan_loss=dict(type='GANLoss', gan_type='hinge'))

train_cfg = dict(
disc_steps=8, gen_steps=1, batch_accumulation_steps=8, use_ema=True)
test_cfg = None
optimizer = dict(
generator=dict(type='Adam', lr=0.0001, betas=(0.0, 0.999), eps=1e-6),
discriminator=dict(type='Adam', lr=0.0004, betas=(0.0, 0.999), eps=1e-6))
33 changes: 33 additions & 0 deletions configs/_base_/models/biggan_128x128_cvt_BigGAN-PyTorch_rgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
model = dict(
type='BasiccGAN',
generator=dict(
type='BigGANGenerator',
output_scale=128,
noise_size=120,
num_classes=1000,
base_channels=96,
shared_dim=128,
with_shared_embedding=True,
sn_eps=1e-6,
init_type='ortho',
act_cfg=dict(type='ReLU', inplace=True),
split_noise=True,
auto_sync_bn=False,
rgb2bgr=True),
discriminator=dict(
type='BigGANDiscriminator',
input_scale=128,
num_classes=1000,
base_channels=96,
sn_eps=1e-6,
init_type='ortho',
act_cfg=dict(type='ReLU', inplace=True),
with_spectral_norm=True),
gan_loss=dict(type='GANLoss', gan_type='hinge'))

train_cfg = dict(
disc_steps=8, gen_steps=1, batch_accumulation_steps=8, use_ema=True)
test_cfg = None
optimizer = dict(
generator=dict(type='Adam', lr=0.0001, betas=(0.0, 0.999), eps=1e-6),
discriminator=dict(type='Adam', lr=0.0004, betas=(0.0, 0.999), eps=1e-6))
27 changes: 16 additions & 11 deletions configs/biggan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,28 @@ url={https://openreview.net/forum?id=B1xsqj09Fm},
}
```

The BigGAN/BigGAN-Deep is a conditional generation model that can generate both high-resolution and high-quality images by scaling up the batch size and number of model parameters.
The BigGAN/BigGAN-Deep is a conditional generation model that can generate both high-resolution and high-quality images by scaling up the batch size and number of model parameters.

We have conducted training BigGAN with CIFAR10(3x32x32) and ImageNet1k(3x128x128) dataset, and the sampling results are showed below
We have conducted training BigGAN with CIFAR10(3x32x32) and ImageNet1k(3x128x128) dataset, and the sampling results are showed below.
<div align="center">
<b> Results from our BigGAN trained in CIFAR10</b>
<br/>
<img src="https://user-images.githubusercontent.com/22982797/126476913-3ce8e2c8-f189-4caa-90ed-b44e279cb669.png" width="800"/>
</div>

<div align="center">
<b> Results from our BigGAN trained in ImageNet</b>
<br/>
<img src="https://user-images.githubusercontent.com/22982797/127615534-6278ce1b-5cff-4189-83c6-9ecc8de08dfc.png" width="800"/>
</div>

Evaluation of our trained BIgGAN.
| Models | Dataset | FID (Iter) | IS (Iter) | Config | Download |
|:------------:|:-------:|:--------------:|:---------------:|:------:|:----------:|
| BigGAN 32x32 | CIFAR10 | 9.78(390000) | 8.70(390000) | [config](https://github.com/open-mmlab/mmgeneration/blob/master/configs/biggan/biggan_cifar10_32x32_b25x2_500k.py) | [model](https://download.openmmlab.com/mmgen/biggan/biggan_cifar10_32x32_b25x2_500k_20210728_110906-08b61a44.pth)\|[log](https://download.openmmlab.com/mmgen/biggan/biggan_cifar10_32_b25x2_500k_20210706_171051.log.json) |
| BigGAN 128x128 | ImageNet1k | 12.32(1150000) | 72.7(1150000) | [config](https://github.com/open-mmlab/mmgeneration/blob/master/) | [model](https://download.openmmlab.com/mmgen/biggan/biggan_imagenet1k_128x128_b32x8_1150k_20210730_124753-b14026b7.pth)\|[log](https://download.openmmlab.com/mmgen/biggan/biggan_imagenet1k_128x128_b32x8_1500k_20210726_224316.log.json) |
| BigGAN 128x128 | ImageNet1k | 12.32(1150000) | 72.7(1150000) | [config](https://github.com/open-mmlab/mmgeneration/blob/master/configs/biggan/biggan_imagenet1k_128x128_b32x8_1500k.py) | [model](https://download.openmmlab.com/mmgen/biggan/biggan_imagenet1k_128x128_b32x8_1150k_20210730_124753-b14026b7.pth)\|[log](https://download.openmmlab.com/mmgen/biggan/biggan_imagenet1k_128x128_b32x8_1500k_20210726_224316.log.json) |

Note: This is an earlier version(1150k iter) of BigGAN trained on ImageNet1k, the model with best performance is still on the way.
Note: This is an earlier version(1150k iter) of BigGAN trained on `ImageNet1k`, the model with best performance is still on the way.

## converted weights
Since we havn't finished training our models, we provide you with several pre-trained weights which has already be evaluated. Here, we refer to [BigGAN-PyTorch](https://github.com/ajbrock/BigGAN-PyTorch) and [pytorch-pretrained-BigGAN](https://github.com/huggingface/pytorch-pretrained-BigGAN).
Expand All @@ -37,15 +43,14 @@ Evaluation results and download links are provided below.

| Models | Dataset | FID | IS | Config | Download | Original Download link |
|:-------------------:|:----------:|:--:|:---:|:------:|:--------:|:----------------------:|
| BigGAN 128x128 | ImageNet1k | 10.1414 | 96.728 | [config](https://github.com/open-mmlab/mmgeneration/blob/master/) | [model](
https://download.openmmlab.com/mmgen/biggan/biggan_imagenet1k_128x128_cvt_BigGAN-PyTorch_rgb_20210730_125223-3e353fef.pth) | [link](https://drive.google.com/open?id=1nAle7FCVFZdix2--ks0r5JBkFnKw8ctW) |
| BigGAN-Deep 128x128 | ImageNet1k | 5.9471 | 107.161 | [config](https://github.com/open-mmlab/mmgeneration/blob/master/) | [model](https://download.openmmlab.com/mmgen/biggan/biggan-deep_imagenet1k_128x128_cvt_hugging-face_rgb_20210728_111659-099e96f9.pth) | [link](https://s3.amazonaws.com/models.huggingface.co/biggan/biggan-deep-128-pytorch_model.bin) |
| BigGAN-Deep 256x256 | ImageNet1k | 11.3151 | 135.107 | [config](https://github.com/open-mmlab/mmgeneration/blob/master/) | [model](https://download.openmmlab.com/mmgen/biggan/biggan-deep_imagenet1k_256x256_cvt_hugging-face_rgb_20210728_111735-28651569.pth) | [link](https://s3.amazonaws.com/models.huggingface.co/biggan/biggan-deep-256-pytorch_model.bin) |
| BigGAN-Deep 512x512 | ImageNet1k | 16.8728 | 124.368 | [config]() | [model](https://download.openmmlab.com/mmgen/biggan/biggan-deep_imagenet1k_512x512_cvt_hugging-face_rgb_20210728_112346-a42585f2.pth) | [link](https://s3.amazonaws.com/models.huggingface.co/biggan/biggan-deep-512-pytorch_model.bin) |
| BigGAN 128x128 | ImageNet1k | 10.1414 | 96.728 | [config](https://github.com/open-mmlab/mmgeneration/blob/master/configs/_base_/models/biggan_128x128_cvt_BigGAN-PyTorch_rgb.py) | [model](https://download.openmmlab.com/mmgen/biggan/biggan_imagenet1k_128x128_cvt_BigGAN-PyTorch_rgb_20210730_125223-3e353fef.pth) | [link](https://drive.google.com/open?id=1nAle7FCVFZdix2--ks0r5JBkFnKw8ctW) |
| BigGAN-Deep 128x128 | ImageNet1k | 5.9471 | 107.161 | [config](https://github.com/open-mmlab/mmgeneration/blob/master/configs/_base_/models/biggan-deep_128x128_cvt_hugging-face_rgb.py) | [model](https://download.openmmlab.com/mmgen/biggan/biggan-deep_imagenet1k_128x128_cvt_hugging-face_rgb_20210728_111659-099e96f9.pth) | [link](https://s3.amazonaws.com/models.huggingface.co/biggan/biggan-deep-128-pytorch_model.bin) |
| BigGAN-Deep 256x256 | ImageNet1k | 11.3151 | 135.107 | [config](https://github.com/open-mmlab/mmgeneration/blob/master/configs/_base_/models/biggan-deep_256x256_cvt_hugging-face_rgb.py) | [model](https://download.openmmlab.com/mmgen/biggan/biggan-deep_imagenet1k_256x256_cvt_hugging-face_rgb_20210728_111735-28651569.pth) | [link](https://s3.amazonaws.com/models.huggingface.co/biggan/biggan-deep-256-pytorch_model.bin) |
| BigGAN-Deep 512x512 | ImageNet1k | 16.8728 | 124.368 | [config](https://github.com/open-mmlab/mmgeneration/blob/master/configs/_base_/models/biggan-deep_512x512_cvt_hugging-face_rgb.py) | [model](https://download.openmmlab.com/mmgen/biggan/biggan-deep_imagenet1k_512x512_cvt_hugging-face_rgb_20210728_112346-a42585f2.pth) | [link](https://s3.amazonaws.com/models.huggingface.co/biggan/biggan-deep-512-pytorch_model.bin) |

Sampling results are showed below.
<div align="center">
<b> Results from our BigGAN-Deep trained in ImageNet 128x128 with truncation factor 0.4</b>
<b> Results from our BigGAN-Deep with Pre-trained weights in ImageNet 128x128 with truncation factor 0.4</b>
<br/>
<img src="https://user-images.githubusercontent.com/22982797/126481730-8da7180b-7b1b-42f0-9bec-78d879b6265b.png" width="800"/>
</div>
Expand Down Expand Up @@ -74,4 +79,4 @@ We will also provide script for image interpolation of conditional models soon.
<b> Image interpolating Results of our BigGAN-Deep</b>
<br/>
<img src="https://user-images.githubusercontent.com/22982797/126580403-2baa987b-ff55-4fb5-a53a-b08e8a6a72a2.png" width="800"/>
</div>
</div>
62 changes: 62 additions & 0 deletions configs/biggan/biggan_imagenet1k_128x128_b32x8_1500k.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
_base_ = [
'../_base_/models/biggan_128x128.py',
'../_base_/datasets/imagenet_noaug_128.py', '../_base_/default_runtime.py'
]

# define dataset
# you must set `samples_per_gpu`
data = dict(samples_per_gpu=32, workers_per_gpu=8)

# adjust running config
lr_config = None
checkpoint_config = dict(interval=5000, by_epoch=False, max_keep_ckpts=10)
custom_hooks = [
dict(
type='VisualizeUnconditionalSamples',
output_dir='training_samples',
interval=10000),
dict(
type='ExponentialMovingAverageHook',
module_keys=('generator_ema', ),
interval=8,
start_iter=160000,
interp_cfg=dict(momentum=0.9999),
priority='VERY_HIGH')
]

# Traning sets' datasize 1,281,167
total_iters = 1500000

# use ddp wrapper for faster training
use_ddp_wrapper = True
find_unused_parameters = False

runner = dict(
type='DynamicIterBasedRunner',
is_dynamic_ddp=False, # Note that this flag should be False.
pass_training_status=True)

# Note set your inception_pkl's path
inception_pkl = "work_dirs/inception_pkl/imagenet.pkl"
evaluation = dict(
type='GenerativeEvalHook',
interval=10000,
metrics=[
dict(
type='FID',
num_images=50000,
inception_pkl=inception_pkl,
bgr2rgb=True),
dict(type='IS', num_images=50000)
],
sample_kwargs=dict(sample_model='ema'),
best_metric=['fid', 'is'])

metrics = dict(
fid50k=dict(
type='FID',
num_images=50000,
inception_pkl=inception_pkl,
bgr2rgb=True,
inception_args=dict(type='StyleGAN')),
is50k=dict(type='IS', num_images=50000))