python imageai error `Function call stack: train_function` - python

Hi sorry for the cringe "tell me what this means" question but I can't seem to figure it out...
Here's the code
from imageai.Classification.Custom import ClassificationModelTrainer
model_trainer = ClassificationModelTrainer()
model_trainer.setModelTypeAsResNet50()
model_trainer.setDataDirectory("images")
model_trainer.trainModel(num_objects=10, num_experiments=200, enhance_data=True, batch_size=8, show_network_summary=True)
and it yields this scary error:
Traceback (most recent call last):
File "marco.py", line 15, in <module>
model_trainer.trainModel(num_objects=10, num_experiments=200, enhance_data=True, batch_size=8, show_network_summary=True)
File "/home/lollo/.local/lib/python3.8/site-packages/imageai/Classification/Custom/__init__.py", line 393, in trainModel
model.fit_generator(train_generator, steps_per_epoch=int(num_train / batch_size), epochs=self.__num_epochs,
File "/home/lollo/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py", line 1847, in fit_generator
return self.fit(
File "/home/lollo/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py", line 1100, in fit
tmp_logs = self.train_function(iterator)
File "/home/lollo/.local/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 828, in __call__
result = self._call(*args, **kwds)
File "/home/lollo/.local/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 888, in _call
return self._stateless_fn(*args, **kwds)
File "/home/lollo/.local/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 2942, in __call__
return graph_function._call_flat(
File "/home/lollo/.local/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 1918, in _call_flat
return self._build_call_outputs(self._inference_function.call(
File "/home/lollo/.local/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 555, in call
outputs = execute.execute(
File "/home/lollo/.local/lib/python3.8/site-packages/tensorflow/python/eager/execute.py", line 59, in quick_execute
tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.InvalidArgumentError: logits and labels must be broadcastable: logits_size=[8,10] labels_size=[8,2]
[[node categorical_crossentropy/softmax_cross_entropy_with_logits (defined at /home/lollo/.local/lib/python3.8/site-packages/imageai/Classification/Custom/__init__.py:393) ]] [Op:__inference_train_function_11908]
Function call stack:
train_function
Thank you for any suggestion <3

Related

InvalidArgumentError: Graph execution error:

I keep getting a "graph execution error" The complete code is in the link if you'd like to see it. I don't really understand the error at all. I was trying to get the epochs running but instead, I get "1/30" and then it just stops. I checked my folders and it appears that I have all jpeg files. I'm in a corner I don't know what to do.
history = model.fit_generator(train_generator,
epochs=30,
verbose=1,
validation_data=validation_generator,
callbacks = [best_model]
)
https://colab.research.google.com/drive/1hvHkDusyqEsdZg5ZRVhhriZrDagpFdU6?usp=sharing
Epoch 1/30
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
<ipython-input-42-5368c251678d> in <module>
----> 1 history = model.fit_generator(train_generator,
2 epochs=30,
3 verbose=1,
4 validation_data=validation_generator,
5 callbacks = [best_model]
2 frames
/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
52 try:
53 ctx.ensure_initialized()
---> 54 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
55 inputs, attrs, num_outputs)
56 except core._NotOkStatusException as e:
InvalidArgumentError: Graph execution error:
Detected at node 'categorical_crossentropy/softmax_cross_entropy_with_logits' defined at (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.8/dist-packages/ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "/usr/local/lib/python3.8/dist-packages/traitlets/config/application.py", line 992, in launch_instance
app.start()
File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelapp.py", line 612, in start
self.io_loop.start()
File "/usr/local/lib/python3.8/dist-packages/tornado/platform/asyncio.py", line 149, in start
self.asyncio_loop.run_forever()
File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
self._run_once()
File "/usr/lib/python3.8/asyncio/base_events.py", line 1859, in _run_once
handle._run()
File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.8/dist-packages/tornado/ioloop.py", line 690, in <lambda>
lambda f: self._run_callback(functools.partial(callback, future))
File "/usr/local/lib/python3.8/dist-packages/tornado/ioloop.py", line 743, in _run_callback
ret = callback()
File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 787, in inner
self.run()
File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 748, in run
yielded = self.gen.send(value)
File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 365, in process_one
yield gen.maybe_future(dispatch(*args))
File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
yielded = next(result)
File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 268, in dispatch_shell
yield gen.maybe_future(handler(stream, idents, msg))
File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
yielded = next(result)
File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 543, in execute_request
self.do_execute(
File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
yielded = next(result)
File "/usr/local/lib/python3.8/dist-packages/ipykernel/ipkernel.py", line 306, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/usr/local/lib/python3.8/dist-packages/ipykernel/zmqshell.py", line 536, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 2854, in run_cell
result = self._run_cell(
File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 2881, in _run_cell
return runner(coro)
File "/usr/local/lib/python3.8/dist-packages/IPython/core/async_helpers.py", line 68, in _pseudo_sync_runner
coro.send(None)
File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3057, in run_cell_async
has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3249, in run_ast_nodes
if (await self.run_code(code, result, async_=asy)):
File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-25-f51df55a1054>", line 1, in <module>
history = model.fit_generator(train_datagen.flow_from_directory(TRAINING_DIR,
File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 2260, in fit_generator
return self.fit(
File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 1409, in fit
tmp_logs = self.train_function(iterator)
File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 1051, in train_function
return step_function(self, iterator)
File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 1040, in step_function
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 1030, in run_step
outputs = model.train_step(data)
File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 890, in train_step
loss = self.compute_loss(x, y, y_pred, sample_weight)
File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 948, in compute_loss
return self.compiled_loss(
File "/usr/local/lib/python3.8/dist-packages/keras/engine/compile_utils.py", line 201, in __call__
loss_value = loss_obj(y_t, y_p, sample_weight=sw)
File "/usr/local/lib/python3.8/dist-packages/keras/losses.py", line 139, in __call__
losses = call_fn(y_true, y_pred)
File "/usr/local/lib/python3.8/dist-packages/keras/losses.py", line 243, in call
return ag_fn(y_true, y_pred, **self._fn_kwargs)
File "/usr/local/lib/python3.8/dist-packages/keras/losses.py", line 1787, in categorical_crossentropy
return backend.categorical_crossentropy(
File "/usr/local/lib/python3.8/dist-packages/keras/backend.py", line 5134, in categorical_crossentropy
return tf.nn.softmax_cross_entropy_with_logits(
Node: 'categorical_crossentropy/softmax_cross_entropy_with_logits'
logits and labels must be broadcastable: logits_size=[16,5] labels_size=[16,11]
[[{{node categorical_crossentropy/softmax_cross_entropy_with_logits}}]] [Op:__inference_train_function_1983]

Invalid Argument Graph Execution error in Tensorflow UNet

So, I'm having a problem with fitting UNet model in Tensorflow. From this line of code
hist = unet.fit(train,
validation_data=val,
steps_per_epoch=STEPS_PER_EPOCH,
validation_steps=VALIDATION_STEPS,
epochs=50)
This is the error message I get
Traceback (most recent call last):
File "C:\Users\Fedor\OneDrive\Рабочий стол\Проект\Херня.py", line 178, in <module>
hist = unet.fit(train,
File "C:\Python\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\Python\lib\site-packages\tensorflow\python\eager\execute.py", line 54, in quick_execute
tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.InvalidArgumentError: Graph execution error:
Detected at node 'sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits' defined at (most recent call last):
File "C:\Users\Fedor\OneDrive\Рабочий стол\Проект\Херня.py", line 178, in <module>
hist = unet.fit(train,
File "C:\Python\lib\site-packages\keras\utils\traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "C:\Python\lib\site-packages\keras\engine\training.py", line 1564, in fit
tmp_logs = self.train_function(iterator)
File "C:\Python\lib\site-packages\keras\engine\training.py", line 1160, in train_function
return step_function(self, iterator)
File "C:\Python\lib\site-packages\keras\engine\training.py", line 1146, in step_function
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "C:\Python\lib\site-packages\keras\engine\training.py", line 1135, in run_step
outputs = model.train_step(data)
File "C:\Python\lib\site-packages\keras\engine\training.py", line 994, in train_step
loss = self.compute_loss(x, y, y_pred, sample_weight)
File "C:\Python\lib\site-packages\keras\engine\training.py", line 1052, in compute_loss
return self.compiled_loss(
File "C:\Python\lib\site-packages\keras\engine\compile_utils.py", line 265, in __call__
loss_value = loss_obj(y_t, y_p, sample_weight=sw)
File "C:\Python\lib\site-packages\keras\losses.py", line 152, in __call__
losses = call_fn(y_true, y_pred)
File "C:\Python\lib\site-packages\keras\losses.py", line 272, in call
return ag_fn(y_true, y_pred, **self._fn_kwargs)
File "C:\Python\lib\site-packages\keras\losses.py", line 2084, in sparse_categorical_crossentropy
return backend.sparse_categorical_crossentropy(
File "C:\Python\lib\site-packages\keras\backend.py", line 5630, in sparse_categorical_crossentropy
res = tf.nn.sparse_softmax_cross_entropy_with_logits(
Node: 'sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits'
logits and labels must have the same first dimension, got logits shape [16384,59] and labels shape [49152]
[[{{node sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits}}]] [Op:__inference_train_function_23608]
I've viewed questions with same error, but they didn't solve my problem

Use Keras to make prediction model throws error

Im trying to use Keras model to recommend visits to some content based on his previous visits and other users behaviours. I have done something similar with a book recommendator system with a rating of 1-5.
user_id content_id visit
1 1 1
2 1 0
3 1 0
1 2 1
2 2 0
3 2 1
I create my embeddings
from keras.layers import Input, Embedding, Flatten, Dot, Dense
from keras.models import Model
from sklearn.model_selection import train_test_split
from keras.models import load_model
# content embedding path
content_input = Input(shape=[1], name="Content-Input")
content_embedding = Embedding(n_content+1, 10, name="Content-Embedding")(content_input)
content_vec = Flatten(name="Flatten-Contents")(content_embedding)
# user embedding path
user_input = Input(shape=[1], name="User-Input")
user_embedding = Embedding(n_users+1, 10, name="User-Embedding")(user_input)
user_vec = Flatten(name="Flatten-Users")(user_embedding)
# dot product and creating model
prod = Dot(name="Dot-Product", axes=1)([content_vec, user_vec])
model = Model([user_input, content_input], prod)
model.compile('adam', 'mean_squared_error')
And I try to create the model
train, test = train_test_split(visits, test_size=0.2, random_state=42)
if os.path.exists('regression_model.h5'):
model = load_model('regression_model.h5')
else:
history = model.fit([train.user_id, train.book_id], train.rating, epochs=5, verbose=1)
model.save('regression_model.h5')
plt.plot(history.history['loss'])
plt.xlabel("Epochs")
plt.ylabel("Training Error")
But then I get a InvalidArgumentError: Graph execution error.
Epoch 1/5
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
/var/folders/y8/4bdyq9hn6p58g8jy30g6vk000000gn/T/ipykernel_85241/1014936592.py in <module>
2 model = load_model('regression_model.h5')
3 else:
----> 4 history = model.fit([train.user_id, train.public_id], train.visit, epochs=5, verbose=1)
5 model.save('regression_model.h5')
6 # plt.plot(history.history['loss'])
~/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb
~/.pyenv/versions/3.7.3/lib/python3.7/site-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
53 ctx.ensure_initialized()
54 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 55 inputs, attrs, num_outputs)
56 except core._NotOkStatusException as e:
57 if name is not None:
InvalidArgumentError: Graph execution error:
Detected at node 'model_10/content-Embedding/embedding_lookup' defined at (most recent call last):
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/ipykernel_launcher.py", line 17, in <module>
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/traitlets/config/application.py", line 976, in launch_instance
app.start()
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/ipykernel/kernelapp.py", line 712, in start
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 199, in start
.. versionadded:: 4.1
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/asyncio/base_events.py", line 539, in run_forever
self._run_once()
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/asyncio/base_events.py", line 1775, in _run_once
handle._run()
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 508, in dispatch_queue
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 497, in process_one
'language_info': self.language_info,
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 404, in dispatch_shell
# FIXME: on rare occasions, the flush doesn't seem to make it to the
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 728, in execute_request
while True:
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/ipykernel/ipkernel.py", line 390, in do_execute
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/ipykernel/zmqshell.py", line 528, in run_cell
)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2915, in run_cell
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2960, in _run_cell
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/core/async_helpers.py", line 78, in _pseudo_sync_runner
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3186, in run_cell_async
except Exception:
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3377, in run_ast_nodes
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3457, in run_code
File "/var/folders/y8/4bdyq9hn6p58g8jy30g6vk000000gn/T/ipykernel_85241/1014936592.py", line 4, in <module>
history = model.fit([train.user_id, train.public_id], train.visit, epochs=5, verbose=1)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/engine/training.py", line 1409, in fit
tmp_logs = self.train_function(iterator)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/engine/training.py", line 1051, in train_function
return step_function(self, iterator)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/engine/training.py", line 1040, in step_function
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/engine/training.py", line 1030, in run_step
outputs = model.train_step(data)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/engine/training.py", line 889, in train_step
y_pred = self(x, training=True)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/engine/training.py", line 490, in __call__
return super().__call__(*args, **kwargs)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/engine/base_layer.py", line 1014, in __call__
outputs = call_fn(inputs, *args, **kwargs)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 92, in error_handler
return fn(*args, **kwargs)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/engine/functional.py", line 459, in call
inputs, training=training, mask=mask)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/engine/functional.py", line 596, in _run_internal_graph
outputs = node.layer(*args, **kwargs)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/engine/base_layer.py", line 1014, in __call__
outputs = call_fn(inputs, *args, **kwargs)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 92, in error_handler
return fn(*args, **kwargs)
File "/Users/xxx/.pyenv/versions/3.7.3/lib/python3.7/site-packages/keras/layers/core/embedding.py", line 199, in call
out = tf.nn.embedding_lookup(self.embeddings, inputs)
Node: 'model_10/content-Embedding/embedding_lookup'
indices[10,0] = 21530 is not in [0, 21025)
[[{{node model_10/content-Embedding/embedding_lookup}}]] [Op:__inference_train_function_6328]
I have tried changing the embedding dimensions, etc but no luck. Could it be that this model is not addapted to boolean data? Could I use another model? Or is the problem lying elsewhere?
Thank you?

Invalid Argument Error: Graph Execution Error and Traceback Error

I'm having multiple errors while running this vanilla rnn training code (code and errors shown below). I don't know if its because of my dataset or is it something else.
The data is made up of opcodes in assembly language.
The size of the training data is (2000, 53203).
This is vanilla RNN training code
import numpy as np
X_test = data[:200]
Y_test = np.array(Y_data[:200])
X_train = data[200:]
Y_train = np.array(Y_data[200:])
from tensorflow.keras.layers import SimpleRNN, Embedding, Dense
from tensorflow.keras.models import Sequential
model = Sequential()
model.add(Embedding(len(word_to_index), 32)) # 임베딩 벡터의 차원은 32
model.add(SimpleRNN(32)) # RNN 셀의 hidden_size는 32
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['acc'])
history = model.fit(X_train, Y_train, epochs=4, batch_size=64, validation_split=0.2)
It's Error Code...
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
C:\Users\ADMINI~1\AppData\Local\Temp/ipykernel_13744/877033043.py in <module>
8
9 model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['acc'])
---> 10 history = model.fit(X_train, Y_train, epochs=4, batch_size=64, validation_split=0.2)
~\anaconda3\lib\site-packages\keras\utils\traceback_utils.py in error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb
~\anaconda3\lib\site-packages\tensorflow\python\eager\execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
52 try:
53 ctx.ensure_initialized()
---> 54 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
55 inputs, attrs, num_outputs)
56 except core._NotOkStatusException as e:
InvalidArgumentError: Graph execution error:
Detected at node 'sequential_3/embedding_2/embedding_lookup' defined at (most recent call last):
File "C:\Users\Administrator\anaconda3\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Administrator\anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Administrator\anaconda3\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "C:\Users\Administrator\anaconda3\lib\site-packages\traitlets\config\application.py", line 846, in launch_instance
app.start()
File "C:\Users\Administrator\anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 677, in start
self.io_loop.start()
File "C:\Users\Administrator\anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 199, in start
self.asyncio_loop.run_forever()
File "C:\Users\Administrator\anaconda3\lib\asyncio\base_events.py", line 596, in run_forever
self._run_once()
File "C:\Users\Administrator\anaconda3\lib\asyncio\base_events.py", line 1890, in _run_once
handle._run()
File "C:\Users\Administrator\anaconda3\lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "C:\Users\Administrator\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 457, in dispatch_queue
await self.process_one()
File "C:\Users\Administrator\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 446, in process_one
await dispatch(*args)
File "C:\Users\Administrator\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 353, in dispatch_shell
await result
File "C:\Users\Administrator\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 648, in execute_request
reply_content = await reply_content
File "C:\Users\Administrator\anaconda3\lib\site-packages\ipykernel\ipkernel.py", line 353, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "C:\Users\Administrator\anaconda3\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "C:\Users\Administrator\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2901, in run_cell
result = self._run_cell(
File "C:\Users\Administrator\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2947, in _run_cell
return runner(coro)
File "C:\Users\Administrator\anaconda3\lib\site-packages\IPython\core\async_helpers.py", line 68, in _pseudo_sync_runner
coro.send(None)
File "C:\Users\Administrator\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3172, in run_cell_async
has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
File "C:\Users\Administrator\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3364, in run_ast_nodes
if (await self.run_code(code, result, async_=asy)):
File "C:\Users\Administrator\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3444, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "C:\Users\ADMINI~1\AppData\Local\Temp/ipykernel_13744/877033043.py", line 10, in <module>
history = model.fit(X_train, Y_train, epochs=4, batch_size=64, validation_split=0.2)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\engine\training.py", line 1445, in fit
val_logs = self.evaluate(
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\engine\training.py", line 1756, in evaluate
tmp_logs = self.test_function(iterator)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\engine\training.py", line 1557, in test_function
return step_function(self, iterator)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\engine\training.py", line 1546, in step_function
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\engine\training.py", line 1535, in run_step
outputs = model.test_step(data)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\engine\training.py", line 1499, in test_step
y_pred = self(x, training=False)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\engine\training.py", line 490, in __call__
return super().__call__(*args, **kwargs)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\engine\base_layer.py", line 1014, in __call__
outputs = call_fn(inputs, *args, **kwargs)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 92, in error_handler
return fn(*args, **kwargs)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\engine\sequential.py", line 374, in call
return super(Sequential, self).call(inputs, training=training, mask=mask)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\engine\functional.py", line 458, in call
return self._run_internal_graph(
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\engine\functional.py", line 596, in _run_internal_graph
outputs = node.layer(*args, **kwargs)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 64, in error_handler
return fn(*args, **kwargs)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\engine\base_layer.py", line 1014, in __call__
outputs = call_fn(inputs, *args, **kwargs)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 92, in error_handler
return fn(*args, **kwargs)
File "C:\Users\Administrator\anaconda3\lib\site-packages\keras\layers\core\embedding.py", line 199, in call
out = tf.nn.embedding_lookup(self.embeddings, inputs)
Node: 'sequential_3/embedding_2/embedding_lookup'
indices[25,40743] = 575 is not in [0, 575)
[[{{node sequential_3/embedding_2/embedding_lookup}}]] [Op:__inference_test_function_4239]
I'm running this on JupyterLab

Keras fit predictions in Callback

I'm trying to get the predictions inside the function on_epoch_end of keras' Callback.
At the moment, to get the predictions, I execute self.model.predict with batch_size of 2, but at the 3rd epochs I get this error:
RuntimeError: Dst tensor is not initialized in Tensorflow
Reading on the web, I notice that this error appears when the GPU goes out of memory. In my case, reading the stack trace, this error is triggered by self.model.predict inside on_epoch_end, it says:
File "mlp_keras.py", line 20, in on_epoch_end predictions =
self.model.predict(self.dataset)
This is the full stack trace:
Traceback (most recent call last):
File "mlp_keras.py", line 150, in <module>
callbacks=[KendallTauHistory(training_dataset, training_dataset_labels, groups_id_count)])
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training.py", line 819, in fit
use_multiprocessing=use_multiprocessing)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 397, in fit
prefix='val_')
File "/usr/lib64/python2.7/contextlib.py", line 24, in __exit__
self.gen.next()
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 771, in on_epoch
self.callbacks.on_epoch_end(epoch, epoch_logs)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/callbacks.py", line 302, in on_epoch_end
callback.on_epoch_end(epoch, logs)
File "mlp_keras.py", line 20, in on_epoch_end
predictions = self.model.predict(self.dataset)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training.py", line 1013, in predict
use_multiprocessing=use_multiprocessing)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 498, in predict
workers=workers, use_multiprocessing=use_multiprocessing, **kwargs)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 426, in _model_iteration
use_multiprocessing=use_multiprocessing)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 706, in _process_inputs
use_multiprocessing=use_multiprocessing)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/data_adapter.py", line 357, in __init__
dataset = self.slice_inputs(indices_dataset, inputs)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/keras/engine/data_adapter.py", line 383, in slice_inputs
dataset_ops.DatasetV2.from_tensors(inputs).repeat()
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/data/ops/dataset_ops.py", line 566, in from_tensors
return TensorDataset(tensors)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/data/ops/dataset_ops.py", line 2765, in __init__
element = structure.normalize_element(element)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/data/util/structure.py", line 113, in normalize_element
ops.convert_to_tensor(t, name="component_%d" % i))
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/framework/ops.py", line 1314, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/framework/tensor_conversion_registry.py", line 52, in _default_conversion_function
return constant_op.constant(value, dtype, name=name)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/framework/constant_op.py", line 258, in constant
allow_broadcast=True)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/framework/constant_op.py", line 266, in _constant_impl
t = convert_to_eager_tensor(value, ctx, dtype)
File "/usr/home/studenti/sp171412/word_ordering/mlp/env/lib/python2.7/site-packages/tensorflow_core/python/framework/constant_op.py", line 96, in convert_to_eager_tensor
return ops.EagerTensor(value, ctx.device_name, dtype)
RuntimeError: Dst tensor is not initialized.
My question is: is there a way to get the predictions without performing predict inside on_epoch_end? Thanks in advance.
Alright, after seeing your last comment, what you could do:
epochs = 100
for epoch in range(epochs):
model.fit(x_train, y_train)
y_predict = model.predict(x_test)

Categories