title: Cannot get the expected target shape in keras
body: <p>I am new to sequential models. I am working on an image caption generator with attention model in Keras. </p>
  
  <p>I keep getting an error with the expected target shape in Keras. I have worked on basic models before. And for this kind of error, usually there's a mistake with the way I process my dataset.
  However, in this case, I have tried adjusting the shape of my 'y' array by unpacking it, or by trying to pack my 'outputs' list. But it doesn't change the error message.</p>
  
  <pre class="lang-py prettyprint-override"><code>def model(photo_shape, max_len, n_s, vocab_size):
    outputs=list()
    seq=Input(shape=(max_len,), name='inseq')#max_len is 33.
    x = Embedding(vocab_size, 300,mask_zero=True)(seq)  
  
    p=Input(shape=(photo_shape[0],photo_shape[1]),name='picture')
    s,_,c=LSTM(n_s,return_state = True)(p)
    for t in range(max_len):
      context = attention(p,s)
      word=Lambda(lambda x: x[:,t,:])(x)
      context = concat([word,context])
      context=reshape(context)
      s,_,c = lstm(context)
      out = den2(s) #return a dense layer with vocab_size units(none, 2791).
      outputs.append(out)
      #print(np.array(outputs).shape) =&gt; returns (33,)
    model = Model(inputs=[seq,p],outputs=outputs)
    return model
  
  #the following method goes to a generator function.
  def build_sequences(tokenizer, max_length, desc_list, photo):
    X1, X2, y = list(), list(), list()
    desc = desc_list[0]
    seq = tokenizer.texts_to_sequences([desc])[0]
    l=len(seq)
    in_seq, out_seq = seq[:l-1], seq[1:l]
    in_seq = pad_sequences([in_seq],padding='post', maxlen=max_length)[0]
    out_seq =[to_categorical([w], num_classes=vocab_size)[0] for w in out_seq]
    out_seq = pad_sequences([out_seq],padding='post', maxlen=max_length)[0]
    X1.append(in_seq)
    X2.append(photo)
    y.append(out_seq)
    return np.array(X1), np.array(X2), np.array(y)
  </code></pre>
  
  <p>The error I get is this.</p>
  
  <pre class="lang-py prettyprint-override"><code>ValueError: Error when checking model target: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 33 array(s), 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, ..., 0, 0, 0],
         [0, 0, 0, ..., 0, 0,...
  </code></pre>
  
  <p>The debug messages show the following shapes for my inputs and outputs.</p>
  
  <pre class="lang-py prettyprint-override"><code>in_seq: (1, 33)
  photo: (1, 196, 512)
  out_seq: (1, 33, 2971)
  </code></pre>
  
  <p>The first is the batch size, which should not be taken into consideration. So, I do not know why the 33 is not visible to keras. I have tried modifying this shape. But logically, should this not work?</p>
  
  <p>Please let me know if this is a data processing error or a problem with my model structure!</p>
  
  <p>Let me know if more code is required</p>