Failed to convert a NumPy array to a Tensor (Unsupported object type dict)

samm: <blockquote>
<p>history = model.fit_generator(train_generator, epochs=epochs, steps_per_epoch=train_steps, verbose=1, callbacks=[checkpoint], validation_data=val_generator, validation_steps=val_steps)</p>
<p>def create_sequences(tokenizer, max_length, desc_list, photo, vocab_size):<br>
X1, X2, y = list(), list(), list()<br>
for desc in desc_list:<br>
seq = tokenizer.texts_to_sequences([desc])[0]<br>
for i in range(1, len(seq)):<br>
in_seq, out_seq = seq[:i], seq[i] in_seq = pad_sequences([in_seq], maxlen=max_length)[0]<br>
out_seq = to_categorical([out_seq], num_classes=vocab_size)[0]<br>
X1.append(photo)<br>
X2.append(in_seq)<br>
y.append(out_seq)<br>
return array(X1), array(X2), array(y)</p>
<p>def data_generator(descriptions, photos, tokenizer, max_length, imgsIds, vocab_size):<br>
while 1:<br>
for ind in range(len(imgsIds)):<br>
photo = photos[ind]<br>
key = imgsIds[ind]<br>
desc_list = descriptions[str(key)]<br>
in_img, in_seq, out_word = create_sequences( tokenizer, max_length, desc_list, photo, vocab_size) yield [in_img, in_seq], out_word</p>
</blockquote>
<p>i got</p>
<blockquote>
<p>82783/82783 [==============================] - ETA: 0s - loss: 4.0302Traceback (most recent call last):<br>
File “rnn_flickr_fit.py”, line 281, in <br>
main(sys.argv)<br>
File “rnn_flickr_fit.py”, line 278, in main<br>
fit_model(train, train_descriptions, train_rnn_input, val, val_descriptions, val_rnn_input)<br>
File “rnn_flickr_fit.py”, line 265, in fit_model<br>
history = model.fit(train_generator, epochs=epochs, steps_per_epoch=train_steps, verbose=1, callbacks=[checkpoint], validation_data=val_generator, validation_steps=val_steps)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py”, line 1213, in fit<br>
steps_per_execution=self._steps_per_execution)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/data_adapter.py”, line 1364, in get_data_handler<br>
return DataHandler(*args, **kwargs)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/data_adapter.py”, line 1166, in <strong>init</strong><br>
model=model)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/data_adapter.py”, line 811, in <strong>init</strong><br>
peek = _process_tensorlike(peek)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/data_adapter.py”, line 1046, in _process_tensorlike<br>
inputs = nest.map_structure(_convert_numpy_and_scipy, inputs)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/util/nest.py”, line 867, in map_structure<br>
structure[0], [func(*x) for x in entries],<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/util/nest.py”, line 867, in <br>
structure[0], [func(*x) for x in entries],<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/data_adapter.py”, line 1041, in _convert_numpy_and_scipy<br>
return ops.convert_to_tensor_v2_with_dispatch(x, dtype=dtype)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/util/dispatch.py”, line 206, in wrapper<br>
return target(*args, **kwargs)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py”, line 1431, in convert_to_tensor_v2_with_dispatch<br>
value, dtype=dtype, dtype_hint=dtype_hint, name=name)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py”, line 1441, in convert_to_tensor_v2<br>
as_ref=False)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/profiler/trace.py”, line 163, in wrapped<br>
return func(*args, **kwargs)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py”, line 1566, in convert_to_tensor<br>
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/tensor_conversion_registry.py”, line 52, in _default_conversion_function<br>
return constant_op.constant(value, dtype, name=name)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py”, line 265, in constant<br>
allow_broadcast=True)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py”, line 276, in _constant_impl<br>
return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py”, line 301, in _constant_eager_impl<br>
t = convert_to_eager_tensor(value, ctx, dtype)<br>
File “/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py”, line 98, in convert_to_eager_tensor<br>
return ops.EagerTensor(value, ctx.device_name, dtype)<br>
ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type dict).<br>
2021-06-30 20:08:00.122545: W tensorflow/core/kernels/data/generator_dataset_op.cc:107] Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter state is not initialized. The process may be terminated.<br>
[[{{node PyFunc}}]]</p>
</blockquote>

ptrblck: <p>It seems you are using TensorFlow, so you might want to post the question in their discussion board or StackOverflow. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>
<p>Based on the error message it seems that <code>dict</code>s are not supported as inputs to the conversion method.</p>

samm: <p>thanks a lot … i did</p>