Error in the code to be debugged

Here is the code section with error:

Training the model

epochs = 20
batch_size = 3
number_pics_per_batch=2000
steps = len(train_descriptions)//batch_size

for i in range(epochs):
generator = data_generator(train_descriptions,encoding_train,word_to_idx,max_len,batch_size)
model.fit_generator(generator,epochs=1,steps_per_epoch=steps,verbose=1)
model.save(’/model_’+str(i)+’.h5’)

The error is:

"
ValueError: Layer model_1 expects 2 input(s), but it received 3 input tensors. Inputs received: [<tf.Tensor ‘IteratorGetNext:0’ shape=(None, None) dtype=float32>, <tf.Tensor ‘IteratorGetNext:1’ shape=(None, None) dtype=int32>, <tf.Tensor ‘IteratorGetNext:2’ shape=(None, None) dtype=float32>]"

hey @nikhil_sarda,
check the output of your generator.
it should be 2 arrays , not 3.

yield [[np.array(X1),np.array(X2)],np.array(y)]

This is what I yield in the generator. This was sent in the video as well and technically I am sending two lists only… two more inside one. Is there some other way to pass it?

I had checked what error it said but it doesn’t fit. I am sending two only.

hey @nikhil_sarda ,
can you please share your code link.

Ya, sure

https://colab.research.google.com/drive/1D6px-y962rmZ3Kv5AdeJuX3MIAiOxeaL?usp=sharing

try like this
input_img_features = Input(shape=(2048,),name=“input_img”)

For Captions

input_captions = Input(shape=(max_len,),name=“input_cap”)

and then in generator
change the yield to

yield {‘input_img’:np.array(X1),‘input_cap’:np.array(X2)},np.array(y)

try this once.

It worked! Thanks… Can you say what was going wrong in the previous code?

it wasn’t something wrong as such ,
generally we face this issue while providing multiple inputs , sometimes its just fails to do so.
Hence , this way comes into action then

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.