TypeError: module() takes at most 2 arguments (3 given) when inheriting torch.utils.data.dataset
Help! I have just installed pytorch1.1 and tested my codes.
When I define a class inheriting torch.utils.data.dataset, something goes wrong.
My codes are here:
import os
from PIL import Image
import torch.utils.data as data
from torchvision import transforms, utils
import pandas as pd
transformer = transforms.Compose([
transforms.CenterCrop((590,730)),
transforms.Resize(448),
transforms.Grayscale(3),
transforms.ToTensor(), #Convert a PIL image or numpy.array to tensor and normalize in range[0.0, 1.0]
transforms.Normalize(mean = (0.5, 0.5, 0.5), std = (0.5, 0.5, 0.5))
class MixDataset(data.dataset):
def __init__(self,image_root,image_attribute,TrainOrValid='Train'):
# imgs = os.listdir(root)
# imgs_id = [os.path.splitext(i)[0] for i in imgs]
imgs = [i+'.jpg' for i in image_attribute['UltrasoundImageID']]
self.labels = [i for i in image_attribute[['TypeOfPlaque_1', 'TypeOfPlaque_2', 'TypeOfPlaque_3', 'TypeOfPlaque_4']]]
self.imgs_fullpath = [os.path.join(image_root,i) for i in imgs]
self.transforms = transformer
self.image_attributes = image_attribute
def __getitem__(self, index):
img_fullpath = self.imgs_fullpath[index]
pil_img = Image.open(img_fullpath)
img = self.transforms(pil_img)
label = self.labels[index]
return img, label
def __len__(self):
return len(self.imgs_fullpath)
Traceback (most recent call last):
File "D:\Coding\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3296, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-2e9363f1d3d6>", line 1, in <module>
runfile('D:/Workspace/TNInet/Data/DataLoader.py', wdir='D:/Workspace/TNInet/Data')
File "D:\Coding\Jet Pycharm\PyCharm 2019.1.3\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "D:\Coding\Jet Pycharm\PyCharm 2019.1.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:/Workspace/TNInet/Data/DataLoader.py", line 66, in <module>
class MixDataset(data.dataset):
TypeError: module() takes at most 2 arguments (3 given)
I have reinstalled anaconda and run the command “conda install pytorch-cpu torchvision-cpu -c pytorch” . I can print “print(torch.version)” and get “1.1.0”. So I think my environment looks well. Howerver, nothing changed. Maybe I need to reinstall again to fix it? Or what should I do?
Thank you for your reading. I would be happy if you could give me some comments.