We Are Going To Discuss About how can reslove : InvalidArgumentError: Graph execution error?. So lets Start this Python Article.
how can reslove : InvalidArgumentError: Graph execution error?
- How to solve how can reslove : InvalidArgumentError: Graph execution error?
You just have to make sure your labels are zero-based starting from 0 to 2, since your output layer has 3 nodes and a
softmax
activation function and you are usingsparse_categorical_crossentropy
. Here is a working example:import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.Conv2D(filters=16, kernel_size=(3,3), activation='relu',input_shape=(256, 256, 3)), tf.keras.layers.Conv2D(filters=32, kernel_size=(3,3), activation='relu'), tf.keras.layers.MaxPool2D(pool_size=(2,2)), tf.keras.layers.BatchNormalization(axis=-1), tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), activation='relu'), tf.keras.layers.Conv2D(filters=128, kernel_size=(3,3), activation='relu'), tf.keras.layers.MaxPool2D(pool_size=(2,2)), tf.keras.layers.BatchNormalization(axis=-1), tf.keras.layers.Flatten(), tf.keras.layers.Dense(512,activation='relu'), tf.keras.layers.BatchNormalization() , tf.keras.layers.Dropout(rate=0.5), tf.keras.layers.Dense(3,activation='softmax') ]) learning_rate = 0.001 epochs=2 opt= tf.keras.optimizers.Adam(learning_rate=learning_rate , decay=learning_rate/(epochs*0.5)) model.compile(loss='sparse_categorical_crossentropy',optimizer=opt,metrics=['accuracy']) aug = tf.keras.preprocessing.image.ImageDataGenerator( rotation_range=10, zoom_range=0.15, width_shift_range=0.1, height_shift_range=0.1, shear_range=0.15, horizontal_flip= False, vertical_flip= False, fill_mode="nearest" ) X_train = tf.random.normal((50, 256, 256, 3)) y_train = tf.random.uniform((50, ), maxval=3, dtype=tf.int32) history = model.fit(aug.flow(X_train, y_train, batch_size=2), epochs=epochs)
Use the dummy data as an orientation for your real data. - how can reslove : InvalidArgumentError: Graph execution error?
You just have to make sure your labels are zero-based starting from 0 to 2, since your output layer has 3 nodes and a
softmax
activation function and you are usingsparse_categorical_crossentropy
. Here is a working example:import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.Conv2D(filters=16, kernel_size=(3,3), activation='relu',input_shape=(256, 256, 3)), tf.keras.layers.Conv2D(filters=32, kernel_size=(3,3), activation='relu'), tf.keras.layers.MaxPool2D(pool_size=(2,2)), tf.keras.layers.BatchNormalization(axis=-1), tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), activation='relu'), tf.keras.layers.Conv2D(filters=128, kernel_size=(3,3), activation='relu'), tf.keras.layers.MaxPool2D(pool_size=(2,2)), tf.keras.layers.BatchNormalization(axis=-1), tf.keras.layers.Flatten(), tf.keras.layers.Dense(512,activation='relu'), tf.keras.layers.BatchNormalization() , tf.keras.layers.Dropout(rate=0.5), tf.keras.layers.Dense(3,activation='softmax') ]) learning_rate = 0.001 epochs=2 opt= tf.keras.optimizers.Adam(learning_rate=learning_rate , decay=learning_rate/(epochs*0.5)) model.compile(loss='sparse_categorical_crossentropy',optimizer=opt,metrics=['accuracy']) aug = tf.keras.preprocessing.image.ImageDataGenerator( rotation_range=10, zoom_range=0.15, width_shift_range=0.1, height_shift_range=0.1, shear_range=0.15, horizontal_flip= False, vertical_flip= False, fill_mode="nearest" ) X_train = tf.random.normal((50, 256, 256, 3)) y_train = tf.random.uniform((50, ), maxval=3, dtype=tf.int32) history = model.fit(aug.flow(X_train, y_train, batch_size=2), epochs=epochs)
Use the dummy data as an orientation for your real data.
Solution 1
You just have to make sure your labels are zero-based starting from 0 to 2, since your output layer has 3 nodes and a softmax
activation function and you are using sparse_categorical_crossentropy
. Here is a working example:
import tensorflow as tf
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(filters=16, kernel_size=(3,3), activation='relu',input_shape=(256, 256, 3)),
tf.keras.layers.Conv2D(filters=32, kernel_size=(3,3), activation='relu'),
tf.keras.layers.MaxPool2D(pool_size=(2,2)),
tf.keras.layers.BatchNormalization(axis=-1),
tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), activation='relu'),
tf.keras.layers.Conv2D(filters=128, kernel_size=(3,3), activation='relu'),
tf.keras.layers.MaxPool2D(pool_size=(2,2)),
tf.keras.layers.BatchNormalization(axis=-1),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(512,activation='relu'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.Dropout(rate=0.5),
tf.keras.layers.Dense(3,activation='softmax')
])
learning_rate = 0.001
epochs=2
opt= tf.keras.optimizers.Adam(learning_rate=learning_rate , decay=learning_rate/(epochs*0.5))
model.compile(loss='sparse_categorical_crossentropy',optimizer=opt,metrics=['accuracy'])
aug = tf.keras.preprocessing.image.ImageDataGenerator(
rotation_range=10,
zoom_range=0.15,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.15,
horizontal_flip= False,
vertical_flip= False,
fill_mode="nearest"
)
X_train = tf.random.normal((50, 256, 256, 3))
y_train = tf.random.uniform((50, ), maxval=3, dtype=tf.int32)
history = model.fit(aug.flow(X_train, y_train, batch_size=2), epochs=epochs)
Use the dummy data as an orientation for your real data.
Original Author AloneTogether Of This Content
Solution 2
Otherwise if you use Colab. Please change run time type by selecting Runtime -> Change run time type -> GPU
Original Author N Tan Of This Content
Solution 3
The same issue happens with me so you need to make sure that they’re all of the same image aspect ratios (ex: 1:1, 4:3, 16:9, etc,.)
Original Author harsha Peteti Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.