Value error while training

on training the model im getting this error.
“ValueError: Error when checking target: expected dense_3 to have 2 dimensions, but got array with shape (164, 1, 1853)”.
this is the link to collab notebook->
https://colab.research.google.com/drive/1PXMfxGCQZi6AZLYugyBeLY6WXH1Ue0rG?usp=sharing

Hi @Dr.Dang

The shape of the target you are passing through the generator is (batch_size, 1, num_classes) whereas the Dense layer expects output of the form (batch_size, num_classes). Try this image data_gen where I have made a simple change to the yield statement:

def data_gen(train_description,encoded_train_images,word_to_idx,max_len,batch_size):
  X1,X2,y=[],[],[]
  n=0
  while True:
    for key,desc_list in train_description.items():
      n+=1
      photo=encoded_train_images[key]
      for desc in desc_list:
        seq=[word_to_idx[word] for word in desc.split() if word in word_to_idx]
        for i in range(1,len(seq)):
          xi=seq[0:i]
          yi=seq[i]
          xi=pad_sequences([xi],maxlen=max_len,value=0,padding='post')[0]
          yi=to_categorical([yi],num_classes=1853)
          X1.append(photo)
          X2.append(xi)
          y.append(yi)
      if n==batch_size:
        yield [[np.array(X1), np.array(X2)], np.array(y).reshape(-1, 1853)]
        X1,X2,y=[],[],[]
        n=0

Hope this helps!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.