2

I'm getting the following error:

AttributeError: cannot assign module before Module.init() call

I'm trying to create an instance of my class :

class ResNetGenerator(nn.Module):
    def __init__(self, input_nc=3, output_nc=3, n_residual_blocks=9, use_dropout=False):
        # super(ResNetGenerator, self).__init__()
        super().__init__()

I'm calling super().__init__() but in vain.

What I am doing wrong here?

Complete Traceback:

File "train.py", line 40, in <module>
    model = ColorizationCycleGAN(args)
File "/path/cycle_gan.py", line 27, in __init__
    self.G_A2B = ResNetGenerator(input_nc=self.input_nc, output_nc=self.output_nc, n_residual_blocks=9, use_dropout=False)
File "/path/.local/lib/python3.6/site packages/torch/nn/modules/module.py", line 544, in __setattr__
    "cannot assign module before Module.__init__() call")
AttributeError: cannot assign module before Module.__init__() call
0

1 Answer 1

4

In fact, I realized that i wasn't calling super().__init__() in the main class ColorizationCycleGAN. Adding this solved the problem.

I hope that this answer will have the effect of reminding you to check to call the super().__init__() function in all classes that inherits from nn.Module.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.