AttributeError: 'int' object has no attribute '_forward_pre_hooks'

905 Views Asked by At
def define_module(self):
    ndf, nef = self.df_dim, self.ef_dim
    self.encode_img = nn.Sequential(
        nn.Conv2d(3, ndf, 4, 2, 1, bias=False),
        nn.LeakyReLU(0.2, inplace=True),
        # state size. (ndf) x 32 x 32
        nn.Conv2d(ndf, ndf * 2, 4, 2, 1, bias=False),
        #nn.BatchNorm2d(ndf * 2),
        nn.utils.spectral_norm(ndf * 2),
        nn.LeakyReLU(0.2, inplace=True),
        # state size (ndf*2) x 16 x 16
        nn.Conv2d(ndf*2, ndf * 4, 4, 2, 1, bias=False),
        #nn.BatchNorm2d(ndf * 4),
        nn.utils.spectral_norm(ndf * 4),
        nn.LeakyReLU(0.2, inplace=True),
        # state size (ndf*4) x 8 x 8
        nn.Conv2d(ndf*4, ndf * 8, 4, 2, 1, bias=False),
        #nn.BatchNorm2d(ndf * 8),
        nn.utils.spectral_norm(ndf * 8),
        # state size (ndf * 8) x 4 x 4)
        nn.LeakyReLU(0.2, inplace=True)
    )

Error:

Traceback (most recent call last): File "main.py", line 77, in algo.train(dataloader, cfg.STAGE) File "/home/ml1/PycharmProjects/StackGAN-Pytorch_coco/code/trainer.py", line 118, in train netG, netD = self.load_network_stageI() File "/home/ml1/PycharmProjects/StackGAN-Pytorch_coco/code/trainer.py", line 56, in load_network_stageI netD = STAGE1_D() File "/home/ml1/PycharmProjects/StackGAN-Pytorch_coco/code/model.py", line 160, in init self.define_module() File "/home/ml1/PycharmProjects/StackGAN-Pytorch_coco/code/model.py", line 170, in define_module nn.utils.spectral_norm(ndf * 2), File "/home/ml1/anaconda3/envs/StackGAN/lib/python2.7/site-packages/torch/nn/utils/spectral_norm.py", line 254, in spectral_norm SpectralNorm.apply(module, name, n_power_iterations, dim, eps) File "/home/ml1/anaconda3/envs/StackGAN/lib/python2.7/site-packages/torch/nn/utils/spectral_norm.py", line 110, in apply for k, hook in module._forward_pre_hooks.items(): AttributeError: 'int' object has no attribute '_forward_pre_hooks'

0

There are 0 best solutions below