I'm rather new to the world of DL and I'm trying to run a MobileNet model to do a multi-class classification but I keep getting this invalidargumenterror when I run it:
code snippet
datagen = ImageDataGenerator(
rotation_range=0.5,
zoom_range = 0.5,
width_shift_range=0.5,
height_shift_range=0.5,
horizontal_flip=True,
vertical_flip=True)
datagen.fit(x_train)
model = applications.mobilenet.MobileNet(weights = "imagenet", include_top=False, input_shape = (150, 150, 3))
for layer in model.layers[:5]:
layer.trainable = False
#Adding custom Layers
x = model.output
x = Flatten()(x)
x = Dense(512, activation="relu")(x)
x = Dropout(0.5)(x)
x = Dense(1024, activation="relu")(x)
x = Dropout(0.5)(x)
predictions = Dense(1, activation="sigmoid")(x)
model = Model(inputs=model.input, outputs=predictions)
model.compile(loss='categorical_crossentropy',optimizer = "Adam",metrics=['acc'])
history = model.fit(datagen.flow(x_train,y_train, batch_size=50),
epochs = 20, validation_data = (x_val,y_val), steps_per_epoch=80)
error that I get:
WARNING:tensorflow:`input_shape` is undefined or non-square, or `rows` is not in [128, 160, 192, 224]. Weights for input shape (224, 224) will be loaded as the default.
Epoch 1/20
2022-10-20 21:32:06.755928: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:114] Plugin optimizer for device_type GPU is enabled.
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
Cell In [20], line 18
15 model = Model(inputs=model.input, outputs=predictions)
16 model.compile(loss='binary_crossentropy',optimizer = "Adam",metrics=['acc'])
---> 18 history = model.fit(datagen.flow(x_train,y_train, batch_size=50),
19 epochs = 20, validation_data = (x_val,y_val), steps_per_epoch=80)
File ~/miniforge3/lib/python3.10/site-packages/keras/utils/traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.__traceback__)
68 # To get the full stack trace, call:
69 # `tf.debugging.disable_traceback_filtering()`
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb
File ~/miniforge3/lib/python3.10/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:
does anyone know how to solve this error? I'm not too sure if the error has got to do with the size of my input images.
My TensorFlow version is 2.10.0 and I'm running my code on VSC using M2 mac.
thank you!!