报错TypeError: MyData() takes no arguments

报错信息:

D:\Anaconda\anaconda\envs\pytorch310\python.exe E:\project\pythonProject\demo_bees\read_data.py 
Traceback (most recent call last):
  File "E:\project\pythonProject\demo_bees\read_data.py", line 34, in <module>
    ants_dataset = MyData(root_dir, ants_label_dir)
TypeError: MyData() takes no arguments

Process finished with exit code 1

解决

原代码:

class MyData(Dataset): # 继承Dataset
    def __int__(self, root_dir, label_dir):# 定义类中的全局变量
        self.root_dir = root_dir # 文件的根目录,/dataset/train

应该是init,写错成了int
把int改成init

你可能感兴趣的:(问题记录,python,开发语言)