Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
747 views
in Technique[技术] by (71.8m points)

iterator - TypeError: 'module' object is not callable self.transform

I'm trying to iterate on a custom dataset, and it's failed on image transform.

transform = transforms.Compose([
    transforms.ToPILImage(),
    transforms.Resize((255, 255)),
    # transforms.PILToTensor()])
    transforms.ToTensor(),
    transforms.Normalize(mean_img, std_img),
])

class img_dataset_fun(Dataset):
    def __init__(self, csv_file, transform):
        self.csv_file = pd.read_csv(csv_file)
        self.transform = transform

    def __len__(self):
        return len(self.csv_file)

    def __getitem__(self, index):
        if torch.is_tensor(index):
            index = index.tolist()
        img_path = self.csv_file.iloc[index, 1]
        image = io.imread(img_path)
        if self.transform is not None:
            image = self.transform(image)

        return image

train_img_dataset = img_dataset_fun(csv_file="data.csv", transform=transform)
train_img_loader = torch.utils.data.DataLoader(
    train_img_dataset,
    batch_size=1,
    num_workers=0,
    shuffle=False,
)
it = iter(train_img_loader)
images_iter = next(it)

images_iter fails with the error:

TypeError                                 Traceback (most recent call last)
<ipython-input-345-31cbe584d6de> in <module>()
      7                     shuffle=False,)
      8 it = iter(train_img_loader)
----> 9 images_iter =next(it)
   

4 frames
<ipython-input-335-55277e02141a> in __getitem__(self, index)
     17         if self.transform is not None:
---> 18           image=self.transform(image)
     19
     20

TypeError: 'module' object is not callable

Any idea what might be the problem?

question from:https://stackoverflow.com/questions/65645916/typeerror-module-object-is-not-callable-self-transform

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...