mmagic.models.editors.biggan.biggan_deep_discriminator
¶
Module Contents¶
Classes¶
BigGAN-Deep Discriminator. The implementation refers to |
- class mmagic.models.editors.biggan.biggan_deep_discriminator.BigGANDeepDiscriminator(input_scale, num_classes=0, in_channels=3, out_channels=1, base_channels=96, block_depth=2, sn_eps=1e-06, sn_style='ajbrock', init_type='ortho', act_cfg=dict(type='ReLU', inplace=False), with_spectral_norm=True, blocks_cfg=dict(type='BigGANDeepDiscResBlock'), arch_cfg=None, pretrained=None)[source]¶
Bases:
torch.nn.Module
BigGAN-Deep Discriminator. The implementation refers to https://github.com/ajbrock/BigGAN-PyTorch/blob/master/BigGANdeep.py # noqa.
The overall structure of BigGAN’s discriminator is the same with the projection discriminator.
The main difference between BigGAN and BigGAN-deep is that BigGAN-deep use more deeper residual blocks to construct the whole model.
More details can be found in: Large Scale GAN Training for High Fidelity Natural Image Synthesis (ICLR2019).
The design of the model structure is highly corresponding to the output resolution. For origin BigGAN-Deep’s generator, you can set
output_scale
as you need and use the default value ofarch_cfg
andblocks_cfg
. If you want to customize the model, you can set the arguments in this way:arch_cfg
: Config for the architecture of this generator. You can refer the_default_arch_cfgs
in the_get_default_arch_cfg
function to see the format of thearch_cfg
. Basically, you need to provide information of each block such as the numbers of input and output channels, whether to perform upsampling etc.blocks_cfg
: Config for the convolution block. You can adjust block params likechannel_ratio
here. You can also replace the block type to your registered customized block. However, you should notice that some params are shared between these blocks likeact_cfg
,with_spectral_norm
,sn_eps
etc.- Parameters
input_scale (int) – The scale of the input image.
num_classes (int, optional) – The number of conditional classes. Defaults to 0.
in_channels (int, optional) – The channel number of the input image. Defaults to 3.
out_channels (int, optional) – The channel number of the final output. Defaults to 1.
base_channels (int, optional) – The basic channel number of the discriminator. The other layers contains channels based on this number. Defaults to 96.
block_depth (int, optional) – The repeat times of Residual Blocks in each level of architecture. Defaults to 2.
sn_eps (float, optional) – Epsilon value for spectral normalization. Defaults to 1e-6.
sn_style (str, optional) – The style of spectral normalization. If set to ajbrock, implementation by ajbrock(https://github.com/ajbrock/BigGAN-PyTorch/blob/master/layers.py) will be adopted. If set to torch, implementation by PyTorch will be adopted. Defaults to ajbrock.
init_type (str, optional) – The name of an initialization method: ortho | N02 | xavier. Defaults to ‘ortho’.
act_cfg (dict, optional) – Config for the activation layer. Defaults to dict(type=’ReLU’).
with_spectral_norm (bool, optional) – Whether to use spectral normalization. Defaults to True.
blocks_cfg (dict, optional) – Config for the convolution block. Defaults to dict(type=’BigGANDiscResBlock’).
arch_cfg (dict, optional) – Config for the architecture of this discriminator. Defaults to None.
pretrained (str | dict, optional) – Path for the pretrained model or dict containing information for pretrained models whose necessary key is ‘ckpt_path’. Besides, you can also provide ‘prefix’ to load the generator part from the whole state dict. Defaults to None.
- forward(x, label=None)[source]¶
Forward function.
- Parameters
x (torch.Tensor) – Fake or real image tensor.
label (torch.Tensor | None) – Label Tensor. Defaults to None.
- Returns
- Prediction for the reality of the input image with
given label.
- Return type
torch.Tensor
- init_weights(pretrained=None, init_type='ortho')[source]¶
Init weights for models.
- Parameters
pretrained (str | dict, optional) – Path for the pretrained model or dict containing information for pretrained models whose necessary key is ‘ckpt_path’. Besides, you can also provide ‘prefix’ to load the generator part from the whole state dict. Defaults to None.
init_type (str, optional) – The name of an initialization method: ortho | N02 | xavier. Defaults to ‘ortho’.