栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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/

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/326170.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号