0

我正在尝试迭代自定义数据集,但图像转换失败。

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失败并出现错误:

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

知道可能是什么问题吗?

4

0 回答 0