hlamba28 / Automatic-Image-Captioning

Generating Captions for images using Deep Learning
https://towardsdatascience.com/image-captioning-with-keras-teaching-computers-to-describe-pictures-c88a46a311b8
117 stars 79 forks source link

data_generator error prevents training #4

Open GorillaBus opened 4 years ago

GorillaBus commented 4 years ago

There is an error in the data_generator function that, when trying to train the model, it will throw the following error:

could not broadcast input array from shape (168,2048) into shape (168)

The project was run from the cloned repo, dataset was copied and all paths are checked. All cell outputs until the training cell are equal to the original notebook.

kp1181 commented 4 years ago

@GorillaBus did you manage to get past the above error?

kp1181 commented 4 years ago

In def data_generator, while yielding use yield [np.array(X1), np.array(X2)], np.array(y)

GorillaBus commented 4 years ago

@kp1181 Hi, thanks for your reply. Let me check this tonight and I'll write back. Thanks!

jha-vineet69 commented 3 years ago

@GorillaBus Did it work?

KirolosAdeib commented 3 years ago

Did anyone figure out the error reason?

Abhishek1236 commented 3 years ago

yield ([array(X1), array(X2)], array(y)) this will work for sure . Thanks

poojapatil16 commented 3 years ago

Can anyone please help me to debug this error? ValueError: in user code: /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:805 train_function * return step_function(self, iterator) /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:795 step_function * outputs = model.distribute_strategy.run(run_step, args=(data,)) /usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:1259 run return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs) /usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica return self._call_for_each_replica(fn, args, kwargs) /usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica return fn(args, kwargs) /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:788 run_step outputs = model.train_step(data) /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:754 train_step y_pred = self(x, training=True) /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/base_layer.py:998 call input_spec.assert_input_compatibility(self.input_spec, inputs, self.name) /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/input_spec.py:207 assert_input_compatibility ' input tensors. Inputs received: ' + str(inputs)) 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>]

jha-vineet69 commented 3 years ago

@poojapatil16 Did you try @kp1181's solution? It worked for me.

Abhishek1236 commented 3 years ago

Hello, please have a look in the notebook. I have provided the link to the dataset as well in the readme. https://github.com/Abhishek1236/Image-caption Thanks and Regards Abhishek Ravi

On Fri, 2 Apr, 2021, 1:51 pm poojapatil16, @.***> wrote:

Can anyone please help me to debug this error? ValueError: in user code: /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:805 train_function * return step_function(self, iterator) /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:795 step_function * outputs = model.distribute_strategy.run(run_step, args=(data,)) /usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:1259 run return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs) /usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica return self._call_for_each_replica(fn, args, kwargs) /usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica return fn(args, kwargs) /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:788 run_step outputs = model.train_step(data) /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:754 train_step y_pred = self(x, training=True) /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/base_layer.py:998 call input_spec.assert_input_compatibility(self.input_spec, inputs, self.name) /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/input_spec.py:207 assert_input_compatibility ' input tensors. Inputs received: ' + str(inputs)) 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>]

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hlamba28/Automatic-Image-Captioning/issues/4#issuecomment-812409685, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGB5VCECOTPOYBZUHJMZO7TTGV47DANCNFSM4JR2GHTA .

poojapatil16 commented 3 years ago

Thanks for your replies, issue is resolved.