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'