Automatic-Image-Captioning icon indicating copy to clipboard operation
Automatic-Image-Captioning copied to clipboard

data_generator error prevents training

Open GorillaBus opened this issue 5 years ago • 10 comments

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.

GorillaBus avatar Nov 26 '19 16:11 GorillaBus

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

kp1181 avatar May 08 '20 16:05 kp1181

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

kp1181 avatar May 08 '20 19:05 kp1181

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

GorillaBus avatar May 11 '20 11:05 GorillaBus

@GorillaBus Did it work?

jha-vineet69 avatar Jan 12 '21 17:01 jha-vineet69

Did anyone figure out the error reason?

KirolosAdeib avatar Feb 28 '21 13:02 KirolosAdeib

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

Abhishek1236 avatar Mar 18 '21 07:03 Abhishek1236

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>]

poojapatil16 avatar Apr 02 '21 08:04 poojapatil16

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

jha-vineet69 avatar Apr 02 '21 09:04 jha-vineet69

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 .

Abhishek1236 avatar Apr 02 '21 11:04 Abhishek1236

Thanks for your replies, issue is resolved.

poojapatil16 avatar Apr 04 '21 13:04 poojapatil16