Bosen
Bosen

Reputation: 941

How to pass more than 1 input into a Tensorflow Neural Network?

I am stuck at passing in 3 inputs (placeholders with different shapes) into a neural network's hidden layer.

This is what I have so far:

with tf.name_scope("Final_Check"):
    # TODO: Is this the correct way to pass 3 inputs into the hidden layer?
    final_layer1 = tf.layers.dense([self.final_time_input, self.final_request_input, self.final_stream_input],
                                   500,
                                   activation=tf.nn.relu,
                                   name="final_hl1")
    final_layer2 = tf.layers.dense(final_layer1,
                                   500,
                                   activation=tf.nn.relu,
                                   name="final_h12")
    final_layer3 = tf.layers.dense(final_layer2,
                                   500,
                                   activation=tf.nn.relu,
                                   name="final_hl3")

    final_output = tf.layers.dense(final_layer3,
                                   500,
                                   activation=tf.nn.relu,
                                   name="final_output")

Placeholders:

  1. self.final_time_input
  2. self.final_request_input
  3. self.final_stream_input

Hidden Layers: all the final_layer[1-3] and final_output

I have tried Googling for some sample code but unable to find any.

Upvotes: 1

Views: 735

Answers (1)

eaksan
eaksan

Reputation: 575

tf.layers.dense expects tensor input. It is a list ([self.final_time_input, self.final_request_input, self.final_stream_input]) in your case. You need to concatenate them by using tf.concat such that

tf.concat([self.final_time_input, self.final_request_input, self.final_stream_input], axis=1)

Assuming that input tensors have a shape of [batch_size, feature_size] where feature_size can be different.

Upvotes: 2

Related Questions