Pytorch数据加载程序转换张量错误

2024-06-08 18:26:43 发布

您现在位置:Python中文网/ 问答频道 /正文

[The dataset class][1]The transforms applied to the image无法访问pytorch数据加载器值以供使用 TypeError:default_collate:批处理必须包含张量、numpy数组、数字、dict或列表;已找到对象

在kaggle上运行https://jovian.ml/pravin-bnmit/cxr/可以重现错误 enter image description here


Tags: 数据对象httpsnumpydefault列表数字pytorch
1条回答
网友
1楼 · 发布于 2024-06-08 18:26:43

为什么不在getitem()方法中进行转换之前尝试一下img = img.resize((1024, 1024))

def __getitem__(self, idx):
    row = self.df.loc[idx]
    img_id, img_label = row['Image Index'], row['disease_vec']
    img_fname = row['path']
    img = Image.open(img_fname)
    img = img.resize((1024, 1024))
    if self.transform:
        img = self.transform(img)
    return img, img_label

相关问题 更多 >