Keras:更改的ImageDataGenerator给出了错误"__init __()得到了意外的关键字参数". [英] Keras: Altered ImageDataGenerator gives error "__init__() got an unexpected keyword argument"

查看:177
本文介绍了Keras:更改的ImageDataGenerator给出了错误"__init __()得到了意外的关键字参数".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用keras=2.3.1,我想使用自己的zca_whitening版本.为此,我直接对keras文件/home/user/.local/lib/python3.6/site-packages/keras_preprocessing/image/image_data_generator.py中的ImageDataGenerator类进行了更改.该文件(包括我的更改)是一个.可以看到这里.没有问题,只要nn_script.py使用默认的keras增强,例如:

I am using keras=2.3.1 and I wanted to use my own version of zca_whitening. For that, I made changes directly into the ImageDataGenerator class in the keras file /home/user/.local/lib/python3.6/site-packages/keras_preprocessing/image/image_data_generator.py. The file, including my changes is this one. My neural network file nn_script.py that uses this altered image_data_generator.py can be seen here. There are no problems, as long as nn_script.py uses the default keras augmentaions like:

train_datagen = ImageDataGenerator(
    rotation_range=30,
    shear_range=0.2,
    samplewise_center=True, samplewise_std_normalization=True) 

但是,如果我决定以这种方式打开名为zca_whitening_fast的自定义版本的zca_whitening

But if I decide to switch on my custom version of zca_whitening called zca_whitening_fast in this way

train_datagen = ImageDataGenerator(
    rotation_range=30,
    shear_range=0.2,
    samplewise_center=True, samplewise_std_normalization=True,
    zca_whitening_fast=True) 

我收到错误消息

Traceback (most recent call last):
  File "nn_script.py", line 55
TypeError: __init__() got an unexpected keyword argument 'zca_whitening_fast'

您可以通过将您的image_data_generator.py文件替换为我上面发布的文件,并尝试使用选项zca_whitening_fast=True创建一个生成器来重现我的错误消息.

You can reproduce my error message by substituting your image_data_generator.py file with the one I posted above and trying to create a generator with the option zca_whitening_fast=True.

首先,我认为问题是,我忘记了在文件image_data_generator.py中的def __init__()中包含zca_whitening_fast,但是它存在,可以检查.我还尝试删除__pycache__文件夹,因为我认为此文件夹中正在执行一些较旧的文件,但是出现了相同的错误.现在,我想知道错误消息是否来自不同文件中的__init__(),而不是image_data_generator.py中的.我认为解决方案很明显,我可能需要在keras预处理文件夹中的另一个文件中进行更改,但我不知道该更改.我认为问题不在于我的keras版本太旧,而且由于与我的显卡兼容的原因,我无法升级keras.

First I thought the problem is, that I have forgotten to include zca_whitening_fast in def __init__() in the file image_data_generator.py, but it is there, as you can check. I also tried deleting the __pycache__ folder, because I thought, that some older files are getting executed in this folder, but the same error appeared. Now I wonder if the error message comes from an __init__() that is in a different file, not in image_data_generator.py. I think the solution is something obvious, I probably need to make a change in another file in the keras preprocessing folder, but I don't know which. I don't think the problem is because my keras version is old and because of compatibility reasons with my graphic card I can't upgrade keras.

我为什么收到此错误消息的任何想法?谢谢

Any ideas why I get this error message? Thanks

推荐答案

您修改了keras_preprocessing程序包中的文件,但是您可能正在导入keras.preprocessing,这是一个不同的程序包.很好,keras.preprocessing会将所有呼叫转发到keras_preprocessing.

You modified the files in the keras_preprocessing package, but you are probably importing keras.preprocessing, which is a different package. This is fine, keras.preprocessing just forwards all calls to keras_preprocessing.

因此,您需要对keras包中的keras/preprocessing/image.py文件进行修改,如下所示:

So what you need to do is to also make your modifications to the keras/preprocessing/image.py files inside the keras package, as shown here.

这篇关于Keras:更改的ImageDataGenerator给出了错误"__init __()得到了意外的关键字参数".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆