3

I Just had trouble making the network and i cant get the inputs rigt, the shape of the tensors is the same as i need in my project. But i keep getting this error. ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), for inputs ['input_1', 'input_2'] but instead got the following list of 1 arrays: [array([[[[[0, 0, 0], [0, 0, 0], [0, 0, 0]],

     [[0, 0, 0],
      [0, 0, 0],
      [0, 0, 0]],

     [[0, 0, 0],
      [0, 0, 0],
      [0, 0, 0]]],

Here is my code

x1_train = [[[[0, 0, 0],[0, 0, 0],[0, 0, 0]],[[0, 0, 0],[0, 0, 0],[0, 0, 0]],[[0, 0, 0],[0, 0, 0],[0, 0, 0]]],[[[0, 0, 0],[0, 0, 0],[0, 0, 0]],[[0, 0, 0],[0, 0, 0],[0, 0, 0]],[[0, 0, 0],[0, 0, 0],[0, 0, 0]]]]
y_train = [[0.3]]

# define two sets of inputs
inputA = tf.keras.Input(shape=(3,3,3))
inputB = tf.keras.Input(shape=(3,3,3))
# the first branch operates on the first input
x = tf.keras.layers.Dense(8, activation="relu")(inputA)
x = tf.keras.layers.Dense(4, activation="relu")(x)
x = tf.keras.Model(inputs=inputA, outputs=x)
# the second branch opreates on the second input
y = tf.keras.layers.Dense(64, activation="relu")(inputB)
y = tf.keras.layers.Dense(32, activation="relu")(y)
y = tf.keras.layers.Dense(4, activation="relu")(y)
y = tf.keras.Model(inputs=inputB, outputs=y)
# combine the output of the two branches
combined = tf.keras.layers.concatenate([x.output, y.output])
# apply a FC layer and then a regression prediction on the
# combined outputs
z = tf.keras.layers.Dense(2, activation="relu")(combined)
z = tf.keras.layers.Dense(1, activation="sigmoid")(z)
# our model will accept the inputs of the two branches and
# then output a single value
model = tf.keras.models.Model(inputs=[x.input, y.input], outputs=z)

model.compile(optimizer='adam',
              loss='mean_absolute_percentage_error', #mean_absolute_percentage_error
              metrics=['accuracy'])

model.fit(x=[x_train, x1_train], y=y_train, epochs = 1)````


I get the error message 
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), for inputs ['input_1', 'input_2'] but instead got the following list of 1 arrays:

2
  • You did not specify how x_train is defined, but in any case, I think you may need to pass a tuple of arrays, not a list, so Keras does not interpret it as a single big array - so x=(x_train, x1_train). Commented Apr 17, 2020 at 9:54
  • sry. x_train is the same as x1_train. making it a touple still gives me the same error message Commented Apr 17, 2020 at 10:18

1 Answer 1

3

Your input arrays must be NumPy arrays, not lists. So you can have:

import numpy as np

x1_train = np.array([
    [[[0, 0, 0],[0, 0, 0],[0, 0, 0]],
     [[0, 0, 0],[0, 0, 0],[0, 0, 0]],
     [[0, 0, 0],[0, 0, 0],[0, 0, 0]]],
    [[[0, 0, 0],[0, 0, 0],[0, 0, 0]],
     [[0, 0, 0],[0, 0, 0],[0, 0, 0]],
     [[0, 0, 0],[0, 0, 0],[0, 0, 0]]]])
x_train = x1_train
y_train = np.array([[0.3], [0.3]])

Then you will not receive that error anymore. The training still fails, though, because the shape of the labels in y_train (num_examples x 1) does not match the shape of the model output (num_examples x 3 x 3 x 1), but that is a different issue.

Sign up to request clarification or add additional context in comments.

3 Comments

Ty very much. How do i fix the second issue then? i cant seem to figure out where i defined the shape of the output or if et just matches the input?
For a different issue, please ask a different question, since it is how StackOverflow works. Also, never forget to upvote/accept an answer if it solved your problem.
@MadsSkov Yes, you may ask a new question about that, although I recommend you to at least try to analyse it yourself first. If you look at z.shape, you will see it has the shape I mention. The shape of the output is defined by the shape in the Input layers and then the operations the each layer in the network applies. I'm not sure what exactly you are attempting to do, but the shape of the labels simply does not match the value computed by the neural network.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.