Create a discriminator Parameters: input_nc (int) -- the number of channels in input images ndf (int) -- the number of filters in the first conv layer netD (str) -- the architecture's name: basic | n_layers | pixel n_layers_D (int) -- the n
(input_nc, ndf, netD, n_layers_D=3, norm='batch', init_type='normal', init_gain=0.02, 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=[]): |
| 171 | """Create a discriminator |
| 172 | |
| 173 | Parameters: |
| 174 | input_nc (int) -- the number of channels in input images |
| 175 | ndf (int) -- the number of filters in the first conv layer |
| 176 | netD (str) -- the architecture's name: basic | n_layers | pixel |
| 177 | n_layers_D (int) -- the number of conv layers in the discriminator; effective when netD=='n_layers' |
| 178 | norm (str) -- the type of normalization layers used in the network. |
| 179 | init_type (str) -- the name of the initialization method. |
| 180 | init_gain (float) -- scaling factor for normal, xavier and orthogonal. |
| 181 | gpu_ids (int list) -- which GPUs the network runs on: e.g., 0,1,2 |
| 182 | |
| 183 | Returns a discriminator |
| 184 | |
| 185 | Our current implementation provides three types of discriminators: |
| 186 | [basic]: 'PatchGAN' classifier described in the original pix2pix paper. |
| 187 | It can classify whether 70×70 overlapping patches are real or fake. |
| 188 | Such a patch-level discriminator architecture has fewer parameters |
| 189 | than a full-image discriminator and can work on arbitrarily-sized images |
| 190 | in a fully convolutional fashion. |
| 191 | |
| 192 | [n_layers]: With this mode, you can specify the number of conv layers in the discriminator |
| 193 | with the parameter <n_layers_D> (default=3 as used in [basic] (PatchGAN).) |
| 194 | |
| 195 | [pixel]: 1x1 PixelGAN discriminator can classify whether a pixel is real or not. |
| 196 | It encourages greater color diversity but has no effect on spatial statistics. |
| 197 | |
| 198 | The discriminator has been initialized by <init_net>. It uses Leakly RELU for non-linearity. |
| 199 | """ |
| 200 | net = None |
| 201 | norm_layer = get_norm_layer(norm_type=norm) |
| 202 | |
| 203 | if netD == 'basic': # default PatchGAN classifier |
| 204 | net = NLayerDiscriminator(input_nc, ndf, n_layers=3, norm_layer=norm_layer) |
| 205 | elif netD == 'n_layers': # more options |
| 206 | net = NLayerDiscriminator(input_nc, ndf, n_layers_D, norm_layer=norm_layer) |
| 207 | elif netD == 'pixel': # classify if each pixel is real or fake |
| 208 | net = PixelDiscriminator(input_nc, ndf, norm_layer=norm_layer) |
| 209 | else: |
| 210 | raise NotImplementedError('Discriminator model name [%s] is not recognized' % netD) |
| 211 | return init_net(net, init_type, init_gain, gpu_ids) |
| 212 | |
| 213 | |
| 214 | ############################################################################## |
nothing calls this directly
no test coverage detected