본문 바로가기

인공지능/Python

AttributeError: 'YourDataModule' object has no attribute '_has_prepared_data' 해결방법

Problem

LightningDataModule을 다루면서 나타난 에러인데, 처음엔 단순히 prepare_data 함수를 정의하지 않아서 발생한 문제인 줄 알았는데, 해당 함수를 정의했음에도 불구하고 다른 _has_~~~ 에러들이 발생했다.

AttributeError: 'YourDataModule' object has no attribute '_has_prepared_data'

Solution

해결방법은 굉장히 간단했는데, LightningDataModule의 init안에 super().__init__()를 작성하면 바로 해결이 된다.

def __init__(self, root, batchsize = 16,num_workers=24):
        super().__init__()
        self.root = root
        self.batchsize = batchsize
        self.num_workers = num_workers

 

- Reference

 

Warn when you forget to call super().__init__() in datamodule subclass · Issue #3175 · PyTorchLightning/pytorch-lightning

🚀 Feature If you forget to call super().__init__() in datamodule subclass, you end up getting confusing errors down the line. We should let the user know they've forgotten to do so and give the...

github.com