MCPcopy Create free account
hub / github.com/JunlinHan/DCLGAN / ResnetDecoder

Class ResnetDecoder

models/networks.py:1041–1095  ·  view source on GitHub ↗

Resnet-based decoder that consists of a few Resnet blocks + a few upsampling operations.

Source from the content-addressed store, hash-verified

1039
1040
1041class ResnetDecoder(nn.Module):
1042 """Resnet-based decoder that consists of a few Resnet blocks + a few upsampling operations.
1043 """
1044
1045 def __init__(self, input_nc, output_nc, ngf=64, norm_layer=nn.BatchNorm2d, use_dropout=False, n_blocks=6, padding_type='reflect', no_antialias=False):
1046 """Construct a Resnet-based decoder
1047
1048 Parameters:
1049 input_nc (int) -- the number of channels in input images
1050 output_nc (int) -- the number of channels in output images
1051 ngf (int) -- the number of filters in the last conv layer
1052 norm_layer -- normalization layer
1053 use_dropout (bool) -- if use dropout layers
1054 n_blocks (int) -- the number of ResNet blocks
1055 padding_type (str) -- the name of padding layer in conv layers: reflect | replicate | zero
1056 """
1057 assert(n_blocks >= 0)
1058 super(ResnetDecoder, self).__init__()
1059 if type(norm_layer) == functools.partial:
1060 use_bias = norm_layer.func == nn.InstanceNorm2d
1061 else:
1062 use_bias = norm_layer == nn.InstanceNorm2d
1063 model = []
1064 n_downsampling = 2
1065 mult = 2 ** n_downsampling
1066 for i in range(n_blocks): # add ResNet blocks
1067
1068 model += [ResnetBlock(ngf * mult, padding_type=padding_type, norm_layer=norm_layer, use_dropout=use_dropout, use_bias=use_bias)]
1069
1070 for i in range(n_downsampling): # add upsampling layers
1071 mult = 2 ** (n_downsampling - i)
1072 if(no_antialias):
1073 model += [nn.ConvTranspose2d(ngf * mult, int(ngf * mult / 2),
1074 kernel_size=3, stride=2,
1075 padding=1, output_padding=1,
1076 bias=use_bias),
1077 norm_layer(int(ngf * mult / 2)),
1078 nn.ReLU(True)]
1079 else:
1080 model += [Upsample(ngf * mult),
1081 nn.Conv2d(ngf * mult, int(ngf * mult / 2),
1082 kernel_size=3, stride=1,
1083 padding=1,
1084 bias=use_bias),
1085 norm_layer(int(ngf * mult / 2)),
1086 nn.ReLU(True)]
1087 model += [nn.ReflectionPad2d(3)]
1088 model += [nn.Conv2d(ngf, output_nc, kernel_size=7, padding=0)]
1089 model += [nn.Tanh()]
1090
1091 self.model = nn.Sequential(*model)
1092
1093 def forward(self, input):
1094 """Standard forward"""
1095 return self.model(input)
1096
1097
1098class ResnetEncoder(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected