mmagic.models.editors.dcgan.dcgan_generator
¶
Module Contents¶
Classes¶
Generator for DCGAN. |
- class mmagic.models.editors.dcgan.dcgan_generator.DCGANGenerator(output_scale, out_channels=3, base_channels=1024, input_scale=4, noise_size=100, default_norm_cfg=dict(type='BN'), default_act_cfg=dict(type='ReLU'), out_act_cfg=dict(type='Tanh'), init_cfg=None)[源代码]¶
Bases:
mmengine.model.BaseModule
Generator for DCGAN.
Implementation Details for DCGAN architecture:
Adopt transposed convolution in the generator;
Use batchnorm in the generator except for the final output layer;
Use ReLU in the generator in addition to the final output layer.
More details can be found in the original paper: Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks http://arxiv.org/abs/1511.06434
- 参数
output_scale (int | tuple[int]) – Output scale for the generated image. If only a integer is provided, the output image will be a square shape. The tuple of two integers will set the height and width for the output image, respectively.
out_channels (int, optional) – The channel number of the output feature. Default to 3.
base_channels (int, optional) – The basic channel number of the generator. The other layers contains channels based on this number. Default to 1024.
input_scale (int | tuple[int], optional) – Output scale for the generated image. If only a integer is provided, the input feature ahead of the convolutional generator will be a square shape. The tuple of two integers will set the height and width for the input convolutional feature, respectively. Defaults to 4.
noise_size (int, optional) – Size of the input noise vector. Defaults to 100.
default_norm_cfg (dict, optional) – Norm config for all of layers except for the final output layer. Defaults to
dict(type='BN')
.default_act_cfg (dict, optional) – Activation config for all of layers except for the final output layer. Defaults to
dict(type='ReLU')
.out_act_cfg (dict, optional) – Activation config for the final output layer. Defaults to
dict(type='Tanh')
.init_cfg (dict, optional) – Initialization config dict. Default: None.
- forward(noise, num_batches=0, return_noise=False)[源代码]¶
Forward function.
- 参数
noise (torch.Tensor | callable | None) – You can directly give a batch of noise through a
torch.Tensor
or offer a callable function to sample a batch of noise data. Otherwise, theNone
indicates to use the default noise sampler.num_batches (int, optional) – The number of batch size. Defaults to 0.
return_noise (bool, optional) – If True,
noise_batch
will be returned in a dict withfake_img
. Defaults to False.
- 返回
- If not
return_noise
, only the output image will be returned. Otherwise, a dict contains
fake_img
andnoise_batch
will be returned.
- If not
- 返回类型
torch.Tensor | dict