老师,我用子类实现了一下多输入,出现以下问题,请您看一下
来源:2-14 wide&deep模型的多输入与多输出实战
weixin_慕丝0226078
2020-11-22
x_train_scaled_wide , x_train_scaled_deep = x_train_scaled[:,:5], x_train_scaled[:,2:]
x_test_scaled_wide , x_test_scaled_deep = x_test_scaled[:,:5], x_test_scaled[:,2:]
x_valid_scaled_wide , x_valid_scaled_deep = x_valid_scaled[:,:5], x_valid_scaled[:,2:]
class WideDeepModel(keras.models.Model):
def __init__(self):
super(WideDeepModel, self).__init__()
self.hidden1 = tf.keras.layers.Dense(30,activation='relu')
self.hidden2 = tf.keras.layers.Dense(30,activation='relu')
self.output_layer = tf.keras.layers.Dense(1)
def __call__(self,inputs):
# 转换数据
input_wide, input_deep = inputs
input_wide = tf.keras.layers.Input(shape=[5])
input_deep = tf.keras.layers.Input(shape=[6])
h1 = self.hidden1(input_deep)
h2 = self.hidden2(h1)
concat = tf.keras.layers.concatenate([input_wide,h2])
output = self.output_layer(concat)
return output
model = WideDeepModel()
model.compile(loss="mean_squared_error", optimizer=keras.optimizers.SGD(1e-3))
history = model.fit([x_train_scaled_wide, x_train_scaled_deep],
y_train, epochs=3,
validation_data=(
[x_valid_scaled_wide, x_valid_scaled_deep],
y_valid),
)
问题:
Train on 11610 samples, validate on 3870 samples
Epoch 1/3
32/11610 [..............................] - ETA: 2s
TypeError: __call__() got an unexpected keyword argument 'training'
1回答
-
weixin_慕丝0226078
提问者
2020-11-22
我自己看到这个call没写对,但还是有问题,请老师指点,
这种子类形式的能否实现多输入情况
InvalidArgumentError: You must feed a value for placeholder tensor 'wide_deep_model_4/input_1' with dtype float and shape [?,5]
[[node wide_deep_model_4/input_1 (defined at D:\anaconda3\envs\TensorFlow2\lib\site-
packages\tensorflow_core\python\framework\ops.py:1751) ]] [Op:__inference_distributed_function_1191]
Function call stack:
distributed_function00
相似问题
回答 1
回答 1