TypeError:_init_subclassed_network()在使用TensorFlow Keras时获得了意外的关键字参数'input'

时间:2019-07-29 02:58:14

标签: python tensorflow keras

我用以下代码构建了一个模型:

model_input = Input(shape=(449, 8, 1))
x = Conv2D(64, (25, 20),padding='same', input_shape=( 449, 8, 1),activation="relu")(model_input)
x = BatchNormalization()(x)
x = Conv2D(128, (25, 20),padding='same', input_shape=( 449, 8, 1),activation="relu")(x)
x = BatchNormalization()(x)
x = Flatten()(x)
x = Dense(8, activation='relu')(x)
x = BatchNormalization()(x)
x = Dense(8, activation='softmax')(x)
model = Model(input=model_input ,output=x)

在导入以下Keras库时,它可以完美运行:

from keras.layers import Conv2D, Input, BatchNormalization, Flatten, Dense
from keras.models import Model
from keras.optimizers import Adam

但是当我尝试在tensorflow中使用内置的Keras API并构建相同的模型时:

from tensorflow.keras.layers import Conv2D, Input, BatchNormalization, Flatten, Dense
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import Adam

错误已合并:

TypeError:_init_subclassed_network()获得了意外的关键字参数“输入”

我正在使用tensorflow-gpu 1.13.1。

1 个答案:

答案 0 :(得分:1)

我在Keras API上看到,参数为inputsoutputs

请重新检查,Keras API