[pytorch] AttributeError: cannot assign module before Module.__init__() call


[pytorch] AttributeError: cannot assign module before Module.__init__() call

에러 : AttributeError: cannot assign module before Module.__init__() call 아래의 코드처럼 돌렸더니 에러가 발생했다. class CustomModule(nn.Module): def __init__(self): self.conv1 = nn.Conv2d(1, 20, 5) # Add key conv1 to self._modules self.conv2 = nn.Conv2d(20, 20, 5) 발생 원인 : Module을 만들고서 super class의 init을 호출하지 않아서 발생한다고 한다. 해결 방안 : super().__init__() 을 넣어준다. 아래와 같이 super(Module name, self).__init() 으로 하는 것도 좋다. class CustomModule(nn.Module): def __init__(self): super(CustomModule, self).__init__() # Initialize self...


#error #module #pytorch

원문링크 : [pytorch] AttributeError: cannot assign module before Module.__init__() call