Open David-hosting opened 1 year ago
@David-hosting, This is a known issue. Developers are working on resolving this bug. Also could you please take a look at the issue and comment from the developer with the similar feature for the reference. Thank you
This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.
hello! i have the same bug.. is there any solution for it?
I am also facing the same error but in the RandomFlip layer. Will be grateful if anyone can tell me a fix for this.
bueno no se paso gracias
facing same error
Hello, I ran into the same problem today and have no idea how to deal with this. It would be great if someone can provide some advise.
# code snippet
model = tf.keras.Sequential([ tf.keras.layers.Dense(16, activation='relu'), tf.keras.layers.Dense(16, activation='relu'), tf.keras.layers.Dense(1, activation='sigmoid') ])
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001), loss=tf.keras.losses.BinaryCrossentropy(), metrics=['accuracy'])
model.fit(x_train, y_train, batch_size=16, epochs=20, validation_data=(x_valid, y_valid))
I'm facing the same issue.....can anyone tell me what to do....?
I am straugleing with the same issue while working on a project , any body can help would be very much appriciated . Thank you ! Below is the error........
InvalidArgumentError Traceback (most recent call last)
1 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 'sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits' 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
I am straugleing with the same issue while working on a project , any body can help would be very much appriciated . Thank you ! Below is the error........
@573-pankaj Is there any solution for that issue I'm also facing this issue so, if you find any solution please share with community.Thanks
Okay will share!
I was also faccing the same issue. I resolved it by properly using the type of data that I am feeding in my model. Try seeing the tensors types that you guys are using. For eg I was returning the data in numpy tensors and I was directly using it in my model witthout saig in numpy file and then reloading it from there.
In nutshell I just want to highlight that I was getting this isssue becasue of mismatching between the data objecct that I was feeding my model.
same problem im facing is there any solution to find out
I'm also getting the same error. Any solution yet?
InvalidArgumentError Traceback (most recent call last) Input In [25], in <cell line: 5>() 2 model.compile(optimizer='adam', loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False), metrics=['accuracy']) 4 #Fit the model ----> 5 history = model.fit(train, epochs=EPOCHS, batch_size=BATCH_SIZE, verbose=1, validation_data=val)
File ~\anaconda\lib\site-packages\keras\utils\traceback_utils.py:67, in filter_traceback.
File ~\anaconda\lib\site-packages\tensorflow\python\eager\execute.py:54, 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: 57 if name is not None:
InvalidArgumentError: Graph execution error:
Input is empty. [[{{node decode_image/DecodeImage}}]] [[IteratorGetNext]] [Op:__inference_train_function_3767]
I am trying to make an image classification program. I am following a video and I ran into some problems, some I think I solved, and others I just couldn't. I am trying to create a model with Transfer Learning and up until now the video was kind of ok but I think it is outdated. I searched the web but couldn't find anything to help solve my problem. Anything would be helpful.
Here is my code:
!pip install -q -U "tensorflow-gpu==2.2.0" !pip install -q -U tensorflow_hub !pip install -q -U tensorflow_datasets import time import numpy as np import matplotlib.pylab as plt import tensorflow as tf import tensorflow_hub as hub import tensorflow_datasets as tfds tfds.disable_progress_bar() from tensorflow.keras import layers #Here was supposed to be a split function to split the data 80% (train), 20% (validation), I don't know what I did but in the line below I did "split=['train[:80%]', 'train[20%:]']" is it ok? or should I change something there? splits, info = tfds.load('cats_vs_dogs', with_info=True, as_supervised=True, split=['train[:80%]', 'train[20%:]']) (train_examples, validation_examples) = splits def format_image(image, label): images = tf.image.resize(image, (IMAGE_RES, IMAGE_RES))//255.0 return image, label num_examples = info.splits['train'].num_examples BATCH_SIZE = 32 IMAGE_RES = 224 train_batches = train_examples.cache().shuffle(num_examples//4).map(format_image).batch(BATCH_SIZE).prefetch(1) validation_batches = validation_examples.cache().map(format_image).batch(BATCH_SIZE).prefetch(1) URL = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4" feature_extractor = hub.KerasLayer(URL, input_shape=(IMAGE_RES,IMAGE_RES,3)) feature_extractor.trainable = False model = tf.keras.Sequential([ feature_extractor, layers.Dense(2, activation='softmax') ]) model.summary() model.compile( optimizer='adam', loss=tf.losses.SparseCategoricalCrossentropy(), metrics=['accuracy']) EPOCHS = 2 history = model.fit(train_batches, epochs=EPOCHS, validation_data=validation_batches) #From here I get the problem
Model Summary:
Error:
InvalidArgumentError: Graph execution error: Detected at node 'IteratorGetNext' 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-11-ce74159d340b>", line 7, in <module> history = model.fit(train_batches, 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 1039, in step_function data = next(iterator) Node: 'IteratorGetNext' Detected at node 'IteratorGetNext' 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-11-ce74159d340b>", line 7, in <module> history = model.fit(train_batches, 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 1039, in step_function data = next(iterator) Node: 'IteratorGetNext' 2 root error(s) found. (0) INVALID_ARGUMENT: Cannot batch tensors with different shapes in component 0. First element had shape [408,500,3] and element 1 had shape [360,343,3]. [[{{node IteratorGetNext}}]] [[IteratorGetNext/_2]] (1) INVALID_ARGUMENT: Cannot batch tensors with different shapes in component 0. First element had shape [408,500,3] and element 1 had shape [360,343,3]. [[{{node IteratorGetNext}}]] 0 successful operations. 0 derived errors ignored. [Op:__inference_train_function_24172]
I also faced difficult with the same error when i'm running image classification. The training images were MRI images (grayscale) and indexed images ie its dimension is like (221,181,1). I reduced the third dimension by the following code im = data.astype(np.uint8) im = im[:,:,0] I debugged and got results
@David-hosting I think the problem might be in the format_image
method. It's not really formatting the images because the transformation is assigned to a variable images
and the method is returning image
(the same input)
Mam, the problem was solved by me, that code is updated there for the first query. Thank you
Sincerely,. Dr.S.Karthigai Selvi
On Wed, Feb 15, 2023 at 8:16 AM Jesus Salinas Vela @.***> wrote:
@David-hosting https://github.com/David-hosting I think the problem might be in the format_image method. It's not really formatting the images because the transformation is assigned to a variable images and the method is returning image (the same input)
[image: Screen Shot 2023-02-14 at 21 43 33] https://user-images.githubusercontent.com/28662284/218914175-478c0fdb-22ff-4a0f-9133-862781a0499f.png
— Reply to this email directly, view it on GitHub https://github.com/keras-team/tf-keras/issues/66, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5YU55QH5NX6PTUV2E7A7ADWXQ7PDANCNFSM6AAAAAATF5E7TI . You are receiving this because you commented.Message ID: @.***>
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) history = model.fit(my_train_images, my_train_labels, batch_size=100, epochs=30, validation_data=(my_test_images, my_test_labels))
Error>>
Epoch 1/30InvalidArgumentError Traceback (most recent call last)
1 frames /usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name) 50 try: 51 ctx.ensure_initialized() ---> 52 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, 53 inputs, attrs, num_outputs) 54 except core._NotOkStatusException as e:
InvalidArgumentError: Graph execution error:
Detected at node 'sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits' 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
Also facing the same problem, came here for solutions :)
I also faced these issues but the issues I faced In auto keras for time series forecasting. when I debug it there were the issues with the input shape
any workarounds?
I managed to fix this by using an older version of tensorflow and metal. Hope this article helps!
Hello, I ran into the same problem today and have no idea how to deal with this. It would be great if someone can provide some advise.
# code snippet
model = tf.keras.Sequential([ tf.keras.layers.Dense(16, activation='relu'), tf.keras.layers.Dense(16, activation='relu'), tf.keras.layers.Dense(1, activation='sigmoid') ])
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001), loss=tf.keras.losses.BinaryCrossentropy(), metrics=['accuracy'])
model.fit(x_train, y_train, batch_size=16, epochs=20, validation_data=(x_valid, y_valid))
same issue. I was following a Udemy course on tensorflow and Keras, almost same code and run into same issue.
It gives the error in the validation. I faced with the same problem when I tried to use "model.predict()". When you give the validation data as variable it throws error. (for example when you write "model.predict([[a,b]]))". But when you give an integer or float (model.predict([[17,2]])) it works. I bypassed the problem by writing "model.predict([[float(a),float(b)]])" (you can use the related type instead float). I believe that the problem is being caused by a bug or smt in TensorFlow. This solution worked for me. You can give it a shot.
I followed the error msg and it was complaining about missing so. lib files, but I looked and they were there, so I added this in my bashrc, then it works.
export XLA_FLAGS=--xla_gpu_cuda_data_dir=/usr/lib/cuda
After doing many hit and trials .I resolved this error in my case was due to insufficient memory in machine Connecting with google collab gpu worked for me
I faced same error by running this code, can anyone help.............
import json import numpy as np from sklearn.model_selection import train_test_split import tensorflow.keras as keras import matplotlib.pyplot as plt
DATA_PATH ="D:/Untitled Folder/data_18.json"
def load_data(data_path): """Loads training dataset from json file. :param data_path (str): Path to json file containing data :return X (ndarray): Inputs :return y (ndarray): Targets """
with open(data_path, "r") as fp:
data = json.load(fp)
X = np.array(data["mfcc"])
y = np.array(data["labels"])
return X, y
def plot_history(history): """Plots accuracy/loss for training/validation set as a function of the epochs :param history: Training history of model :return: """
fig, axs = plt.subplots(2)
# create accuracy sublpot
axs[0].plot(history.history["accuracy"], label="train accuracy")
axs[0].plot(history.history["val_accuracy"], label="test accuracy")
axs[0].set_ylabel("Accuracy")
axs[0].legend(loc="lower right")
axs[0].set_title("Accuracy eval")
# create error sublpot
axs[1].plot(history.history["loss"], label="train error")
axs[1].plot(history.history["val_loss"], label="test error")
axs[1].set_ylabel("Error")
axs[1].set_xlabel("Epoch")
axs[1].legend(loc="upper right")
axs[1].set_title("Error eval")
plt.show()
def prepare_datasets(test_size, validation_size): """Loads data and splits it into train, validation and test sets. :param test_size (float): Value in [0, 1] indicating percentage of data set to allocate to test split :param validation_size (float): Value in [0, 1] indicating percentage of train set to allocate to validation split :return X_train (ndarray): Input training set :return X_validation (ndarray): Input validation set :return X_test (ndarray): Input test set :return y_train (ndarray): Target training set :return y_validation (ndarray): Target validation set :return y_test (ndarray): Target test set """
# load data
X, y = load_data(DATA_PATH)
# create train, validation and test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=test_size)
X_train, X_validation, y_train, y_validation = train_test_split(X_train, y_train, test_size=validation_size)
return X_train, X_validation, X_test, y_train, y_validation, y_test
def build_model(input_shape): """Generates RNN-LSTM model :param input_shape (tuple): Shape of input set :return model: RNN-LSTM model """
# build network topology
model = keras.Sequential()
# 2 LSTM layers
model. Add(keras.layers.LSTM(64, input_shape=input_shape, return_sequences=True))
model. Add(keras.layers.LSTM(64))
# dense layer
model. Add(keras.layers.Dense(64, activation='relu'))
model. Add(keras.layers.Dropout(0.3))
# output layer
model. Add(keras.layers.Dense(10, activation='softmax'))
return model
if name == "main":
# get train, validation, test splits
X_train, X_validation, X_test, y_train, y_validation, y_test = prepare_datasets(0.25, 0.2)
# create network
input_shape = (X_train.shape[1], X_train.shape[2]) # 130, 13
model = build_model(input_shape)
# compile model
optimizer = keras.optimizers.Adam(learning_rate=0.0001)
model. Compile(optimizer=optimizer,
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model. Summary()
# train model
history = model. Fit(X_train, y_train, validation_data=(X_validation, y_validation), batch_size=32, epochs=30)
# plot accuracy/error for training and validation
plot_history(history)
# evaluate model on test set
test_loss, test_acc = model.evaluate(X_test, y_test, verbose=2)
print('\nTest accuracy:', test_acc)
The error:-
InvalidArgumentError: Graph execution error:
Detected at node 'sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits' defined at (most recent call last):
File "C:\Users\96475\anaconda3\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\96475\anaconda3\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\96475\anaconda3\lib\site-packages\ipykernel_launcher.py", line 17, in
I'm having the same error. I would appreciate your help.
train_data = tf.data.Dataset.from_generator(lambda: data_adapter, output_signature=(tf.TensorSpec(shape=(sig_len, n_sig), dtype=tf.float64), tf.TensorSpec(shape=(), dtype=tf.string))) \ .take(2000) \ .batch(32) val_data = tf.data.Dataset.from_generator(lambda: data_adapter, output_signature=(tf.TensorSpec(shape=(sig_len, n_sig), dtype=tf.float64), tf.TensorSpec(shape=(), dtype=tf.string))) \ .skip(2000) \ .batch(32) model.fit_generator(train_data, epochs=10, validation_data=val_data) UnimplementedError: Graph execution error:
Detected at node 'binary_crossentropy/Cast' defined at (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.10/dist-packages/ipykernel_launcher.py", line 16, in
Try to check if any file is not an image file, this error is occurring just because of containing other files in dataset folder, this change will surely solve this problem...
In my case, I used the wrong input shape. Try check if you are using the correct input dim
Thank you. I solved the problem. I wrote codes compatible with TF 2.0.
I'm having the same problem with my project. Anyone could help please, the deadline is soon :):
from tensorflow.keras.layers import Input, Embedding, LSTM, Dense from tensorflow.keras.models import Model from tensorflow.keras.losses import SparseCategoricalCrossentropy from tensorflow.keras.optimizers import Adam
def get_model(input_shape, vocab_size, embedding_dim, rnn_units): input = Input(shape=input_shape) embedding = Embedding(vocab_size, embedding_dim, input_length=max_sequence_len)(input) lstm = LSTM(rnn_units)(embedding) output = Dense(vocab_size, activation='softmax')(lstm) model = Model(input,output) model.compile(loss = SparseCategoricalCrossentropy(), optimizer = Adam(), metrics=['accuracy']) model.summary() return model
from tensorflow.keras.callbacks import EarlyStopping callback = EarlyStopping(monitor='val_accuracy', mode = 'max', patience=5, restore_best_weights=True)
vocab_size = len(tokenizer.word_index) #total num of unique words embedding_dim = 16 rnn_units = 55 batch_size = 32 epochs = 10 model = get_model(max_sequence_len, vocab_size, embedding_dim, rnn_units)
history = model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_data = (x_val, y_val), callbacks = [callback])
InvalidArgumentError Traceback (most recent call last)
1 frames /usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name) 50 try: 51 ctx.ensure_initialized() ---> 52 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, 53 inputs, attrs, num_outputs) 54 except core._NotOkStatusException as e:
InvalidArgumentError: Graph execution error:
Detected at node 'sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits' defined at (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.10/dist-packages/ipykernel_launcher.py", line 16, in
I was working on lane detection along with object detection n i am also facing same problem Graph execution error:
Can anyone help me to solve thi problem?
@573-pankaj Is there any solution for that issue I'm also facing this issue so, if you find any solution please share with community.Thanks
hello @573-pankaj, I am stuck with the same error, can you please share your solution?
Tuve el mismo problema y logré solucionarlo. No se si sea la misma solución para todos. Lo que hice fue asegurarme que la cantidad de neuronas de salida fueran la mismas cantidad de categorías de imágenes que tengo.
tf.keras.layers.Dense(2, activation='softmax')
en mi caso solo eran dos categorías.
InvalidArgumentError Traceback (most recent call last) Cell In [25], line 9 6 nb_validation_samples = 3006 7 epochs=25 ----> 9 history=model.fit( 10 train_generator, 11 steps_per_epoch=nb_train_samples//batch_size, 12 epochs=epochs, 13 callbacks=callbacks, 14 validation_data=validation_generator, 15 validation_steps=nb_validation_samples//batch_size)
File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\utils\traceback_utils.py:70, in filter_traceback.tf.debugging.disable_traceback_filtering()
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb
File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\eager\execute.py:52, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name) 50 try: 51 ctx.ensure_initialized() ---> 52 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, 53 inputs, attrs, num_outputs) 54 except core._NotOkStatusException as e: 55 if name is not None:
InvalidArgumentError: Graph execution error:
Detected at node 'categorical_crossentropy/softmax_cross_entropy_with_logits' defined at (most recent call last):
File "C:\Users\pavan\AppData\Local\Programs\Python\Python310\Lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\pavan\AppData\Local\Programs\Python\Python310\Lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\pavan\AppData\Local\Programs\Python\Python310\lib\site-packages\ipykernel_launcher.py", line 17, in
I fixed the error , it was because of additional files ,causing the number of classes assigned in the code and number of classes present in files to mismatch.
Upgrading TensorFlow or Keras may help
I am trying to make an image classification program. I am following a video and I ran into some problems, some I think I solved, and others I just couldn't. I am trying to create a model with Transfer Learning and up until now the video was kind of ok but I think it is outdated. I searched the web but couldn't find anything to help solve my problem. Anything would be helpful. Here is my code:
!pip install -q -U "tensorflow-gpu==2.2.0" !pip install -q -U tensorflow_hub !pip install -q -U tensorflow_datasets import time import numpy as np import matplotlib.pylab as plt import tensorflow as tf import tensorflow_hub as hub import tensorflow_datasets as tfds tfds.disable_progress_bar() from tensorflow.keras import layers #Here was supposed to be a split function to split the data 80% (train), 20% (validation), I don't know what I did but in the line below I did "split=['train[:80%]', 'train[20%:]']" is it ok? or should I change something there? splits, info = tfds.load('cats_vs_dogs', with_info=True, as_supervised=True, split=['train[:80%]', 'train[20%:]']) (train_examples, validation_examples) = splits def format_image(image, label): images = tf.image.resize(image, (IMAGE_RES, IMAGE_RES))//255.0 return image, label num_examples = info.splits['train'].num_examples BATCH_SIZE = 32 IMAGE_RES = 224 train_batches = train_examples.cache().shuffle(num_examples//4).map(format_image).batch(BATCH_SIZE).prefetch(1) validation_batches = validation_examples.cache().map(format_image).batch(BATCH_SIZE).prefetch(1) URL = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4" feature_extractor = hub.KerasLayer(URL, input_shape=(IMAGE_RES,IMAGE_RES,3)) feature_extractor.trainable = False model = tf.keras.Sequential([ feature_extractor, layers.Dense(2, activation='softmax') ]) model.summary() model.compile( optimizer='adam', loss=tf.losses.SparseCategoricalCrossentropy(), metrics=['accuracy']) EPOCHS = 2 history = model.fit(train_batches, epochs=EPOCHS, validation_data=validation_batches) #From here I get the problem
Model Summary: Error:
InvalidArgumentError: Graph execution error: Detected at node 'IteratorGetNext' 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-11-ce74159d340b>", line 7, in <module> history = model.fit(train_batches, 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 1039, in step_function data = next(iterator) Node: 'IteratorGetNext' Detected at node 'IteratorGetNext' 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-11-ce74159d340b>", line 7, in <module> history = model.fit(train_batches, 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 1039, in step_function data = next(iterator) Node: 'IteratorGetNext' 2 root error(s) found. (0) INVALID_ARGUMENT: Cannot batch tensors with different shapes in component 0. First element had shape [408,500,3] and element 1 had shape [360,343,3]. [[{{node IteratorGetNext}}]] [[IteratorGetNext/_2]] (1) INVALID_ARGUMENT: Cannot batch tensors with different shapes in component 0. First element had shape [408,500,3] and element 1 had shape [360,343,3]. [[{{node IteratorGetNext}}]] 0 successful operations. 0 derived errors ignored. [Op:__inference_train_function_24172]
I also faced difficult with the same error when i'm running image classification. The training images were MRI images (grayscale) and indexed images ie its dimension is like (221,181,1). I reduced the third dimension by the following code im = data.astype(np.uint8) im = im[:,:,0] I debugged and got results
I had this same issue, found out the problem was in the loss I used. I changed mine from sparse_categorical_crossentropy
to categorical_crossentropy
. So maybe just use the categorical_crossentropy instead and see if it works.
hello! i have the same bug.. is there any solution for it?
did u find any way?
It is very simple guys just match
shape = 224 train_generator(target_size = (shape, shape)), with model input_shape(shape, shape)
It is very simple guys just match
shape = 224 train_generator(target_size = (shape, shape)), with model input_shape(shape, shape)
is shape =224 a predefined argument or assigned value?
As @AnujLahoty stated before, a possible fix is using a different data type. I used an int (2000) and changed it to a float (2000.0) and that fixed this error for me.
It is very simple guys just match
shape = 224 train_generator(target_size = (shape, shape)), with model input_shape(shape, shape)
yes, this worked for me. Thankyou.
I faced this issue on kaggle when I was using the original environment. I don't know what causes that issue but when I changed to latest one it solved the error. the tensorflow version didn't changed but problem didn't appear. it might be version of some libraries doesnt match.
I am trying to make an image classification program. I am following a video and I ran into some problems, some I think I solved, and others I just couldn't. I am trying to create a model with Transfer Learning and up until now the video was kind of ok but I think it is outdated. I searched the web but couldn't find anything to help solve my problem. Anything would be helpful.
Here is my code:
!pip install -q -U "tensorflow-gpu==2.2.0" !pip install -q -U tensorflow_hub !pip install -q -U tensorflow_datasets import time import numpy as np import matplotlib.pylab as plt import tensorflow as tf import tensorflow_hub as hub import tensorflow_datasets as tfds tfds.disable_progress_bar() from tensorflow.keras import layers #Here was supposed to be a split function to split the data 80% (train), 20% (validation), I don't know what I did but in the line below I did "split=['train[:80%]', 'train[20%:]']" is it ok? or should I change something there? splits, info = tfds.load('cats_vs_dogs', with_info=True, as_supervised=True, split=['train[:80%]', 'train[20%:]']) (train_examples, validation_examples) = splits def format_image(image, label): images = tf.image.resize(image, (IMAGE_RES, IMAGE_RES))//255.0 return image, label num_examples = info.splits['train'].num_examples BATCH_SIZE = 32 IMAGE_RES = 224 train_batches = train_examples.cache().shuffle(num_examples//4).map(format_image).batch(BATCH_SIZE).prefetch(1) validation_batches = validation_examples.cache().map(format_image).batch(BATCH_SIZE).prefetch(1) URL = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4" feature_extractor = hub.KerasLayer(URL, input_shape=(IMAGE_RES,IMAGE_RES,3)) feature_extractor.trainable = False model = tf.keras.Sequential([ feature_extractor, layers.Dense(2, activation='softmax') ]) model.summary() model.compile( optimizer='adam', loss=tf.losses.SparseCategoricalCrossentropy(), metrics=['accuracy']) EPOCHS = 2 history = model.fit(train_batches, epochs=EPOCHS, validation_data=validation_batches) #From here I get the problem
Model Summary:
Error:
InvalidArgumentError: Graph execution error: Detected at node 'IteratorGetNext' 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-11-ce74159d340b>", line 7, in <module> history = model.fit(train_batches, 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 1039, in step_function data = next(iterator) Node: 'IteratorGetNext' Detected at node 'IteratorGetNext' 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-11-ce74159d340b>", line 7, in <module> history = model.fit(train_batches, 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 1039, in step_function data = next(iterator) Node: 'IteratorGetNext' 2 root error(s) found. (0) INVALID_ARGUMENT: Cannot batch tensors with different shapes in component 0. First element had shape [408,500,3] and element 1 had shape [360,343,3]. [[{{node IteratorGetNext}}]] [[IteratorGetNext/_2]] (1) INVALID_ARGUMENT: Cannot batch tensors with different shapes in component 0. First element had shape [408,500,3] and element 1 had shape [360,343,3]. [[{{node IteratorGetNext}}]] 0 successful operations. 0 derived errors ignored. [Op:__inference_train_function_24172]
Check the output layer its should be equal to the number of classes present in the datasets
For me it was a batch size error please check your hyper parameters and then run it again!!
We had the same error message (InvalidArgumentError: Graph execution error), and in our case the problem was the labels. For some reason, our labels went from 1 - 4 at some point, and changing them to 0 - 3 solved the problem. Apparently keras needs the labels to start at 0 (feel free to correct me if I'm wrong). Hope that helps some of you who encounter this issue.
hello! i have the same bug.. is there any solution for it?
I am trying to make an image classification program. I am following a video and I ran into some problems, some I think I solved, and others I just couldn't. I am trying to create a model with Transfer Learning and up until now the video was kind of ok but I think it is outdated. I searched the web but couldn't find anything to help solve my problem. Anything would be helpful.
Here is my code:
Model Summary:
Error: