How to fix this problem pls reply i have to submit this project today

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,initial_epoch=1,steps_per_epoch=steps,verbose=1)
model.save(’./model_weight/model_’+str(i)+’.h5’)
KeyError Traceback (most recent call last)
in
1 for i in range(epochs):
2 generator = data_generator(train_descriptions,encoding_train,word_to_idx,max_len,batch_size)
----> 3 model.fit_generator(generator,epochs=1,initial_epoch=1,steps_per_epoch=steps,verbose=1)
4 model.save(’./model_weight/model_’+str(i)+’.h5’)

~\Anaconda3\lib\site-packages\tensorflow\python\util\deprecation.py in new_func(*args, **kwargs)
322 ‘in a future version’ if date is None else (‘after %s’ % date),
323 instructions)
–> 324 return func(*args, **kwargs)
325 return tf_decorator.make_decorator(
326 func, new_func, ‘deprecated’,

~\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
1477 use_multiprocessing=use_multiprocessing,
1478 shuffle=shuffle,
-> 1479 initial_epoch=initial_epoch)
1480
1481 @deprecation.deprecated(

~\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in _method_wrapper(self, *args, **kwargs)
64 def _method_wrapper(self, *args, **kwargs):
65 if not self._in_multi_worker_mode(): # pylint: disable=protected-access
—> 66 return method(self, *args, **kwargs)
67
68 # Running inside run_distribute_coordinator already.

~\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
813 workers=workers,
814 use_multiprocessing=use_multiprocessing,
–> 815 model=self)
816
817 # Container that configures and calls tf.keras.Callbacks.

~\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py in init(self, x, y, sample_weight, batch_size, steps_per_epoch, initial_epoch, epochs, shuffle, class_weight, max_queue_size, workers, use_multiprocessing, model)
1110 use_multiprocessing=use_multiprocessing,
1111 distribution_strategy=ds_context.get_strategy(),
-> 1112 model=model)
1113
1114 strategy = ds_context.get_strategy()

~\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py in init(self, x, y, sample_weights, workers, use_multiprocessing, max_queue_size, model, **kwargs)
770 # Since we have to know the dtype of the python generator when we build the
771 # dataset, we have to look at a batch to infer the structure.
–> 772 peek, x = self._peek_and_restore(x)
773 assert_not_namedtuple(peek)
774 peek = self._standardize_batch(peek)

~\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py in _peek_and_restore(x)
828 @staticmethod
829 def _peek_and_restore(x):
–> 830 peek = next(x)
831 return peek, itertools.chain([peek], x)
832

in data_generator(train_descriptions, encoding_train, word_to_idx, max_len, batch_size)
8 n +=1
9
—> 10 photo = encoding_train[key+".jpg"]
11 for desc in desc_list:
12

KeyError: ‘2513260012_03d33305cf.jpg’

hey @ayangiri3,

change this as

photo = encoding_train[key]

I hope it will work

No is still not working

hey @abhigyaverma27 ,
can you please upload your code on github and share me its link ,
its not easy for me to debug it here.
Would be nice if you can get it done.

Ok sure I will do that

here is the link

hey @abhigyaverma27 ,
i have just updated your code a bit.
You mistake was in while you were creating enoding_train and encoding_test dictionaries.
Hence , as yo were inserting wrong keys into it , hence it was giving error while training.

Have a look here https://colab.research.google.com/drive/1HOCQCyGQcQCae_2iOLzzUfCr51WXa6fA?usp=sharing.

I hope this will resolve your doubt.

Thank you so much for your help. My doubt is resolved.

Thats really good to hear that.

All the best and happy learning :slightly_smiling_face:.

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.