Reputation: 67
Im trying to implement a reinforcement learning algorithm with tensorflow to train an agent.
I want my neural network to have 2 different inputs, the first one an image stack of 4 images with the shape (4,160,120,1) and then just a one dimensional array with 10 entries.
I tried to do it like i did with just one input and defined my call function of my neural network with two inputs and ran my program. When the function train_on_batch was executed it resulted in an error and i received following message, in which states2 is my second input:
ValueError: Models passed to train_on_batch
can only have training
and the first argument in call
as positional arguments, found: ['state2']
So how can I use two inputs for my neural network and still be able to use train_on_batch?
Upvotes: 1
Views: 2006
Reputation: 8092
You can create a model with two inputs something like
input1=tf.keras.Input( shape= .....
# add layers here to process input 1 as you wish
# last layer should be a Flatten layer or GlobalMaxPooling Layer
out1=tf.keras.layers.Flatten()(previous layer)
input2= tf.keras.Input ( shape=....
add layers to process input 2
# last layer should be a Flatten layer or GlobalMaxPooling Layer
out2=tf.keras.layers.Flatten()(previous layer)
# now concatenate the outputs out1 and out2
concatted = tf.keras.layers.Concatenate()([out1, out2])
# now you can add more layers here to process the concatted output as you wish
# last layer should be your output layer
output=Dense (number of classes, activation='softmax;)(previous layer output)
model=keras.Model(inputs=[input1,input2], outputs=output)
# then compile your model
Upvotes: 1
Reputation: 75
You would need to either concatenate the inputs into a single npy array, or use a list of arrays, as stated in the documentation when running the tf.keras.Model.train_on_batch()
function.
Upvotes: 0