通用思路:typeerror: __init__() got an unexpected keyword argument ‘XXX‘

我使用tiny-imagenet包出现问题。

typeerror: __init__() got an unexpected keyword argument 'urls'

步骤如下:

1、明确问题出现原因,根据报错定位到对应的包的报错位置

包可以从

Linux:
/home/<用户名>/anaconda3/envs/<虚拟环境名>/lib/python<版本号>/site-packages/
windows:
C:\Users\<用户名>\Anaconda3\envs\<虚拟环境名>\Lib\site-packages\

中去找。

我的报错位置如下: 

def _info(self):
        return tfds.core.DatasetInfo(
            builder=self,
            description=("""Tiny ImageNet Challenge is a similar challenge as ImageNet with a smaller dataset but
                         less image classes. It contains 200 image classes, a training
                         dataset of 100, 000 images, a validation dataset of 10, 000
                         images, and a test dataset of 10, 000 images. All images are
                         of size 64×64."""),
            features=tfds.features.FeaturesDict({
                "image": tfds.features.Image(shape=(64, 64, 3), encoding_format="jpeg"),
                "id": tfds.features.Text(),
                "label": tfds.features.ClassLabel(num_classes=200),
            }),
            supervised_keys=("image", "label"),
            urls=["https://tiny-imagenet.herokuapp.com/"],
            citation=r"""@article{tiny-imagenet,
                              author = {Li,Fei-Fei}, {Karpathy,Andrej} and {Johnson,Justin}"}""",
        )

问题出现在tfds.core.DatasetInfo这个类,其中使用了urls参数。

所以,可以合理推断是下载的tfds(tensorflow_datasets)的版本不对。

2、尝试不同的版本

到github看tiny-imagenet上传的大致时间,根据该时间推测作者最有可能使用的tensorflow_datasets的版本,然后我安装了tensorflow_datasets 2.0.0的版本,发现问题。

原来是自tensorflow_datasets 2.0.0起,urls被淘汰了,改用homepages。

修改tiny_imagenet的错误部分,结果如下:

    def _info(self):
        return tfds.core.DatasetInfo(
            builder=self,
            description=("""Tiny ImageNet Challenge is a similar challenge as ImageNet with a smaller dataset but
                         less image classes. It contains 200 image classes, a training
                         dataset of 100, 000 images, a validation dataset of 10, 000
                         images, and a test dataset of 10, 000 images. All images are
                         of size 64×64."""),
            features=tfds.features.FeaturesDict({
                "image": tfds.features.Image(shape=(64, 64, 3), encoding_format="jpeg"),
                "id": tfds.features.Text(),
                "label": tfds.features.ClassLabel(num_classes=200),
            }),
            supervised_keys=("image", "label"),
            homepage="https://tiny-imagenet.herokuapp.com/",
            citation=r"""@article{tiny-imagenet,
                              author = {Li,Fei-Fei}, {Karpathy,Andrej} and {Johnson,Justin}"}""",
        )

urls一行变成了 homepage="https://tiny-imagenet.herokuapp.com/"

问题解决啦~~~~~

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值