请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

老师,我用子类实现了一下多输入,出现以下问题,请您看一下

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'

正在回答 回答被采纳积分+3

1回答

提问者 weixin_慕丝0226078 2020-11-22 18:40:37

我自己看到这个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_function



0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信