SN-GAN icon indicating copy to clipboard operation
SN-GAN copied to clipboard

small bug in snres_generator.py

Open xinario opened this issue 6 years ago • 2 comments

1 .For python3, tngf /= 2 gives float rather than int. This end up with a error: TypeError: torch.FloatTensor constructor received an invalid combination of arguments

It can be simply avoided by using // operator

  1. Currently res generator only works for nlayers=4. Can be corrected by replacing ngf * 16 with 2 ** nlayers * ngf

xinario avatar Apr 18 '18 23:04 xinario

Hi, @xinario @godisboy @Jiaming-Liu

I changed your fix suggestion, but I met this error:

oem@sgi:~/SN-GAN$ python3 train-res.py --cuda --dataPath celebJapan/ Namespace(batchsize=32, cuda=True, dataPath='celebJapan/', gpu_ids=[0, 1, 2, 3], manualSeed=None, n_dis=1, nz=128) /usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py:188: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead. "please use transforms.Resize instead.") Random Seed: 8018 Traceback (most recent call last): File "train-res.py", line 71, in G = SNResGenerator(64, nz, 4) File "/home/oem/SN-GAN/models/snres_generator.py", line 39, in init self.generator = self.make_model(ngf, nlayers) File "/home/oem/SN-GAN/models/snres_generator.py", line 46, in make_model model += [ResBlock(tngf, tngf/2, upsample=True)] File "/home/oem/SN-GAN/models/snres_generator.py", line 12, in init self.conv2 = nn.Conv2d(hidden_channels, out_channels, kernel_size=3, padding=1) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py", line 297, in init False, _pair(0), groups, bias) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py", line 33, in init out_channels, in_channels // groups, *kernel_size)) TypeError: new() received an invalid combination of arguments - got (float, int, int, int), but expected one of:

  • (torch.device device)
  • (torch.Storage storage)
  • (Tensor other)
  • (tuple of ints size, torch.device device)
  • (object data, torch.device device)

What's wrong with me??

Thanks in advance.

from @bemoregt.

bemoregt avatar Sep 21 '18 07:09 bemoregt

The make_model funtion of SNResGenerator should be changed as:

def make_model(self, ngf, nlayers):
        model = []
        tngf = ngf*16
        for i in range(nlayers):
            model += [ResBlock(int(tngf), int(tngf/2), upsample=True)]    # 8, 16, 32, 64
            tngf /= 2
        model += [nn.BatchNorm2d(ngf)]
        model += [nn.ReLU()]
        model += [nn.Conv2d(ngf, 3, kernel_size=3, stride=1, padding=1)]
        model += [nn.Tanh()]
        return nn.Sequential(*model)

csyuhao avatar May 07 '20 05:05 csyuhao