TypeError :(“关键字参数无法理解:",“输入") [英] TypeError: ('Keyword argument not understood:', 'input')

查看:34
本文介绍了TypeError :(“关键字参数无法理解:",“输入")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我对此程序的代码.它工作正常,但突然不起作用,请任何人都可以解决此问题

This is my code for this program. it is working correctly but suddenly not work please anyone can solve this problem

model = Sequential()
print(nb_filters[0], 'filters')
print('input shape', img_rows, 'rows', img_cols, 'cols', patch_size, 'patchsize')

model.add(Convolution3D(
    nb_filters[0],
    kernel_dim1=1, # depth
    kernel_dim2=nb_conv[0], # rows
    kernel_dim3=nb_conv[1], # cols
    input_shape=(1, img_rows, img_cols, patch_size),
    activation='relu'
))

model.add(MaxPooling3D(pool_size=(1, nb_pool[0], nb_pool[0])))

model.add(Dropout(0.2))

model.add(Flatten())

model.add(Dense(128, init='normal', activation='relu'))

model.add(Dropout(0.2))

model.add(Dense(nb_classes,init='normal'))

model.add(Activation('softmax'))
#optimizer adam,sgd,RMSprop,Adagrad,Adadelta,Nadam,
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

此错误在我的程序中创建.解决我多次搜索却无法解决的问题时,我不知道要解决什么问题?

This error creates in my program. what is the problem I don't understand to solve this I search many times but not solve this problem?

--------------------------------------------------------
TypeError              Traceback (most recent call last)
<ipython-input-112-671e85975992> in <module>
     13 x = Dense(nb_classes, activation='softmax')(x)
     14 
---> 15 custom_model = Model(input=resnet_model.input, output=x)
     16 
     17 for layer in custom_model.layers[:7]:

/usr/local/lib/python3.8/dist-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
    455     self._self_setattr_tracking = False  # pylint: disable=protected-access
    456     try:
--> 457       result = method(self, *args, **kwargs)
    458     finally:
    459       self._self_setattr_tracking = previous_value  # pylint: disable=protected-access

/usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/training.py in __init__(self, *args, **kwargs)
    259     # self.trainable_weights
    260     # self.non_trainable_weights
--> 261     generic_utils.validate_kwargs(kwargs, {'trainable', 'dtype', 'dynamic',
    262                                            'name', 'autocast'})
    263     super(Model, self).__init__(**kwargs)

/usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/utils/generic_utils.py in validate_kwargs(kwargs, allowed_kwargs, error_message)
    776   for kwarg in kwargs:
    777     if kwarg not in allowed_kwargs:
--> 778       raise TypeError(error_message, kwarg)
    779 
    780 

TypeError: ('Keyword argument not understood:', 'input')

推荐答案

博士的建议.史努比 tf.keras.Model 的参数是 inputs outputs ,但是您将其作为 input传递 output 分别位于 custom_model = Model(input = resnet_model.input,output = x)中.

As suggested by Dr. Snoopy, the arguments to the tf.keras.Model are inputs and outputs but you are passing it as input and output respectively in custom_model = Model(input=resnet_model.input, output=x).

重现该错误的代码-

import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

X1 = tf.constant([2, 3, 4, 5, 6, 7])
X2 = tf.constant([2, 3, 4, 5, 6, 7])
yTrain = tf.constant([4, 6, 8, 10, 12, 14])

input1 = keras.Input(shape=(1,))
input2 = keras.Input(shape=(1,))

x = layers.concatenate([input1, input2])
x = layers.Dense(8, activation='relu')(x)
outputs = layers.Dense(2)(x)
mlp = keras.Model(input = [input1, input2], output = outputs)

mlp.summary()

mlp.compile(loss='mean_squared_error',
            optimizer='adam', metrics=['accuracy'])

mlp.fit([X1, X2], yTrain, batch_size=1, epochs=10, validation_split=0.2,
        shuffle=True)

mlp.evaluate([X1, X2], yTrain)

输出-

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-bec9ebbd1faf> in <module>()
     14 x = layers.Dense(8, activation='relu')(x)
     15 outputs = layers.Dense(2)(x)
---> 16 mlp = keras.Model(input = [input1, input2], output = outputs)
     17 
     18 mlp.summary()

2 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/generic_utils.py in validate_kwargs(kwargs, allowed_kwargs, error_message)
    776   for kwarg in kwargs:
    777     if kwarg not in allowed_kwargs:
--> 778       raise TypeError(error_message, kwarg)
    779 
    780 

TypeError: ('Keyword argument not understood:', 'input')

要解决该错误,请将参数更改为 inputs outputs .

To fix the error, change the arguments as inputs and outputs.

固定代码-

import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

X1 = tf.constant([2, 3, 4, 5, 6, 7])
X2 = tf.constant([2, 3, 4, 5, 6, 7])
yTrain = tf.constant([4, 6, 8, 10, 12, 14])

input1 = keras.Input(shape=(1,))
input2 = keras.Input(shape=(1,))

x = layers.concatenate([input1, input2])
x = layers.Dense(8, activation='relu')(x)
outputs = layers.Dense(2)(x)
mlp = keras.Model(inputs = [input1, input2], outputs = outputs)

mlp.summary()

mlp.compile(loss='mean_squared_error',
            optimizer='adam', metrics=['accuracy'])

mlp.fit([X1, X2], yTrain, batch_size=1, epochs=10, validation_split=0.2,
        shuffle=True)

mlp.evaluate([X1, X2], yTrain)

输出-

Model: "functional_5"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_6 (InputLayer)            [(None, 1)]          0                                            
__________________________________________________________________________________________________
input_7 (InputLayer)            [(None, 1)]          0                                            
__________________________________________________________________________________________________
concatenate_34 (Concatenate)    (None, 2)            0           input_6[0][0]                    
                                                                 input_7[0][0]                    
__________________________________________________________________________________________________
dense_4 (Dense)                 (None, 8)            24          concatenate_34[0][0]             
__________________________________________________________________________________________________
dense_5 (Dense)                 (None, 2)            18          dense_4[0][0]                    
==================================================================================================
Total params: 42
Trainable params: 42
Non-trainable params: 0
__________________________________________________________________________________________________
Epoch 1/10
4/4 [==============================] - 0s 32ms/step - loss: 54.3236 - accuracy: 0.0000e+00 - val_loss: 169.3114 - val_accuracy: 0.0000e+00
Epoch 2/10
4/4 [==============================] - 0s 6ms/step - loss: 53.4965 - accuracy: 0.0000e+00 - val_loss: 167.0008 - val_accuracy: 0.0000e+00
Epoch 3/10
4/4 [==============================] - 0s 6ms/step - loss: 52.7413 - accuracy: 0.0000e+00 - val_loss: 164.6473 - val_accuracy: 0.0000e+00
Epoch 4/10
4/4 [==============================] - 0s 6ms/step - loss: 51.8159 - accuracy: 0.0000e+00 - val_loss: 162.4427 - val_accuracy: 0.0000e+00
Epoch 5/10
4/4 [==============================] - 0s 6ms/step - loss: 51.0917 - accuracy: 0.0000e+00 - val_loss: 160.1798 - val_accuracy: 0.0000e+00
Epoch 6/10
4/4 [==============================] - 0s 6ms/step - loss: 50.4425 - accuracy: 0.0000e+00 - val_loss: 157.8355 - val_accuracy: 0.0000e+00
Epoch 7/10
4/4 [==============================] - 0s 6ms/step - loss: 49.5709 - accuracy: 0.0000e+00 - val_loss: 155.6147 - val_accuracy: 0.0000e+00
Epoch 8/10
4/4 [==============================] - 0s 6ms/step - loss: 48.7816 - accuracy: 0.0000e+00 - val_loss: 153.4298 - val_accuracy: 0.0000e+00
Epoch 9/10
4/4 [==============================] - 0s 6ms/step - loss: 47.9975 - accuracy: 0.0000e+00 - val_loss: 151.2858 - val_accuracy: 0.0000e+00
Epoch 10/10
4/4 [==============================] - 0s 6ms/step - loss: 47.3943 - accuracy: 0.0000e+00 - val_loss: 149.0254 - val_accuracy: 0.0000e+00
1/1 [==============================] - 0s 2ms/step - loss: 80.9333 - accuracy: 0.0000e+00
[80.93333435058594, 0.0]

这篇关于TypeError :(“关键字参数无法理解:",“输入")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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