Create a generator Parameters: input_nc (int) -- the number of channels in input images output_nc (int) -- the number of channels in output images ngf (int) -- the number of filters in the last conv layer netG (str) -- the architecture's name: resnet_9blocks | re
(input_nc, output_nc, ngf, netG, norm='batch', use_dropout=False, init_type='normal', init_gain=0.02, gpu_ids=[])
| 117 | |
| 118 | |
| 119 | def define_G(input_nc, output_nc, ngf, netG, norm='batch', use_dropout=False, init_type='normal', init_gain=0.02, gpu_ids=[]): |
| 120 | """Create a generator |
| 121 | |
| 122 | Parameters: |
| 123 | input_nc (int) -- the number of channels in input images |
| 124 | output_nc (int) -- the number of channels in output images |
| 125 | ngf (int) -- the number of filters in the last conv layer |
| 126 | netG (str) -- the architecture's name: resnet_9blocks | resnet_6blocks | unet_256 | unet_128 |
| 127 | norm (str) -- the name of normalization layers used in the network: batch | instance | none |
| 128 | use_dropout (bool) -- if use dropout layers. |
| 129 | init_type (str) -- the name of our initialization method. |
| 130 | init_gain (float) -- scaling factor for normal, xavier and orthogonal. |
| 131 | gpu_ids (int list) -- which GPUs the network runs on: e.g., 0,1,2 |
| 132 | |
| 133 | Returns a generator |
| 134 | |
| 135 | Our current implementation provides two types of generators: |
| 136 | U-Net: [unet_128] (for 128x128 input images) and [unet_256] (for 256x256 input images) |
| 137 | The original U-Net paper: https://arxiv.org/abs/1505.04597 |
| 138 | |
| 139 | Resnet-based generator: [resnet_6blocks] (with 6 Resnet blocks) and [resnet_9blocks] (with 9 Resnet blocks) |
| 140 | Resnet-based generator consists of several Resnet blocks between a few downsampling/upsampling operations. |
| 141 | We adapt Torch code from Justin Johnson's neural style transfer project (https://github.com/jcjohnson/fast-neural-style). |
| 142 | |
| 143 | |
| 144 | The generator has been initialized by <init_net>. It uses RELU for non-linearity. |
| 145 | """ |
| 146 | net = None |
| 147 | norm_layer = get_norm_layer(norm_type=norm) |
| 148 | |
| 149 | if netG == 'resnet_9blocks': |
| 150 | net = ResnetGenerator(input_nc, output_nc, ngf, norm_layer=norm_layer, use_dropout=use_dropout, n_blocks=9) |
| 151 | elif netG == 'resnet_6blocks': |
| 152 | net = ResnetGenerator(input_nc, output_nc, ngf, norm_layer=norm_layer, use_dropout=use_dropout, n_blocks=6) |
| 153 | elif netG == 'resnet_12blocks': |
| 154 | net = ResnetGenerator(input_nc, output_nc, ngf, norm_layer=norm_layer, use_dropout=use_dropout, n_blocks=12) |
| 155 | elif netG == 'unet_128': |
| 156 | net = UnetGenerator(input_nc, output_nc, 7, ngf, norm_layer=norm_layer, use_dropout=use_dropout) |
| 157 | elif netG == 'unet_256': |
| 158 | net = UnetGenerator(input_nc, output_nc, 8, ngf, norm_layer=norm_layer, use_dropout=use_dropout) |
| 159 | elif netG == 'unet_672': |
| 160 | net = UnetGenerator(input_nc, output_nc, 5, ngf, norm_layer=norm_layer, use_dropout=use_dropout) |
| 161 | elif netG == 'unet_960': |
| 162 | net = UnetGenerator(input_nc, output_nc, 6, ngf, norm_layer=norm_layer, use_dropout=use_dropout) |
| 163 | elif netG == 'unet_1024': |
| 164 | net = UnetGenerator(input_nc, output_nc, 10, ngf, norm_layer=norm_layer, use_dropout=use_dropout) |
| 165 | else: |
| 166 | raise NotImplementedError('Generator model name [%s] is not recognized' % netG) |
| 167 | return init_net(net, init_type, init_gain, gpu_ids) |
| 168 | |
| 169 | |
| 170 | def define_D(input_nc, ndf, netD, n_layers_D=3, norm='batch', init_type='normal', init_gain=0.02, gpu_ids=[]): |
nothing calls this directly
no test coverage detected