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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…