KeyError: ‘You have to pass data to augmentations as named arguments, for example: aug(image=image)‘

 在使用albumentations库进行数据增强时,调用torchvision.datasets.ImageNet()读取ImageNet数据集,在将albumentations方法作为transform参数传入时,运行报错。

  File "/Users/yi/miniforge3/envs/PyTorch_py39/lib/python3.9/site-packages/albumentations/core/composition.py", line 175, in __call__
    raise KeyError("You have to pass data to augmentations as named arguments, for example: aug(image=image)")
KeyError: 'You have to pass data to augmentations as named arguments, for example: aug(image=image)'

经过查询,在其官网发现解决方法,不能直接使用 torchvision.datasets来直接读取数据集

class ImageNetSearchDataset(torchvision.datasets.ImageNet):
    def __getitem__(self, index):
        path, label = self.samples[index]
        image = cv2.imread(path)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        if self.transform is not None:
            transformed = self.transform(image=image)
            image = transformed["image"]

        return image, label

Image classification on the ImageNet dataset - Albumentations Documentationhttps://albumentations.ai/docs/autoalbument/examples/imagenet/

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值