Construct a Resnet-based 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 nor
(self, input_nc, output_nc, ngf=64, norm_layer=nn.BatchNorm2d, use_dropout=False, n_blocks=6, padding_type='reflect', no_antialias=False, no_antialias_up=False, opt=None)
| 947 | """ |
| 948 | |
| 949 | 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, no_antialias_up=False, opt=None): |
| 950 | """Construct a Resnet-based generator |
| 951 | |
| 952 | Parameters: |
| 953 | input_nc (int) -- the number of channels in input images |
| 954 | output_nc (int) -- the number of channels in output images |
| 955 | ngf (int) -- the number of filters in the last conv layer |
| 956 | norm_layer -- normalization layer |
| 957 | use_dropout (bool) -- if use dropout layers |
| 958 | n_blocks (int) -- the number of ResNet blocks |
| 959 | padding_type (str) -- the name of padding layer in conv layers: reflect | replicate | zero |
| 960 | """ |
| 961 | assert(n_blocks >= 0) |
| 962 | super(ResnetGenerator, self).__init__() |
| 963 | self.opt = opt |
| 964 | if type(norm_layer) == functools.partial: |
| 965 | use_bias = norm_layer.func == nn.InstanceNorm2d |
| 966 | else: |
| 967 | use_bias = norm_layer == nn.InstanceNorm2d |
| 968 | |
| 969 | model = [nn.ReflectionPad2d(3), |
| 970 | nn.Conv2d(input_nc, ngf, kernel_size=7, padding=0, bias=use_bias), |
| 971 | norm_layer(ngf), |
| 972 | nn.ReLU(True)] |
| 973 | |
| 974 | n_downsampling = 2 |
| 975 | for i in range(n_downsampling): # add downsampling layers |
| 976 | mult = 2 ** i |
| 977 | if(no_antialias): |
| 978 | model += [nn.Conv2d(ngf * mult, ngf * mult * 2, kernel_size=3, stride=2, padding=1, bias=use_bias), |
| 979 | norm_layer(ngf * mult * 2), |
| 980 | nn.ReLU(True)] |
| 981 | else: |
| 982 | model += [nn.Conv2d(ngf * mult, ngf * mult * 2, kernel_size=3, stride=1, padding=1, bias=use_bias), |
| 983 | norm_layer(ngf * mult * 2), |
| 984 | nn.ReLU(True), |
| 985 | Downsample(ngf * mult * 2)] |
| 986 | |
| 987 | mult = 2 ** n_downsampling |
| 988 | for i in range(n_blocks): # add ResNet blocks |
| 989 | |
| 990 | model += [ResnetBlock(ngf * mult, padding_type=padding_type, norm_layer=norm_layer, use_dropout=use_dropout, use_bias=use_bias)] |
| 991 | |
| 992 | for i in range(n_downsampling): # add upsampling layers |
| 993 | mult = 2 ** (n_downsampling - i) |
| 994 | if no_antialias_up: |
| 995 | model += [nn.ConvTranspose2d(ngf * mult, int(ngf * mult / 2), |
| 996 | kernel_size=3, stride=2, |
| 997 | padding=1, output_padding=1, |
| 998 | bias=use_bias), |
| 999 | norm_layer(int(ngf * mult / 2)), |
| 1000 | nn.ReLU(True)] |
| 1001 | else: |
| 1002 | model += [Upsample(ngf * mult), |
| 1003 | nn.Conv2d(ngf * mult, int(ngf * mult / 2), |
| 1004 | kernel_size=3, stride=1, |
| 1005 | padding=1, # output_padding=1, |
| 1006 | bias=use_bias), |
nothing calls this directly
no test coverage detected