I'm trying to fit a ConvNet model using Keras' fit generator, but it fails when trying to feed the data to the input layer. It's telling me it's expecting a three-dimensional input, but my input is only two. If I add a channel to my input shape, it asks for four dimensions.
Here's the exact error when I don't add a channel parameter:
ValueError: Error when checking input: expected input_1 to have 3 dimensions, but got array with shape (1000, 597)
And again when I change the input shape to (1000, 597, 1):
ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (1000, 597)
Here's the code for my model:
def initialise_model():
input_layer = Input((1, 1000, 597))
conv_layer_1 = Conv2D(filters=30, kernel_size=(10, 1), strides=(1, 1), padding="same", activation="relu")(input_layer)
conv_layer_2 = Conv2D(filters=30, kernel_size=(8, 1), strides=(8, 1), padding="same", activation="relu")(conv_layer_1)
conv_layer_3 = Conv2D(filters=40, kernel_size=(6, 1), strides=(6, 1), padding="same", activation="relu")(conv_layer_2)
conv_layer_4 = Conv2D(filters=50, kernel_size=(5, 1), strides=(1, 1), padding="same", activation="relu")(conv_layer_3)
conv_layer_5 = Conv2D(filters=50, kernel_size=(5, 1), strides=(1, 1), padding="same", activation="relu")(conv_layer_4)
flatten_layer = Flatten()(conv_layer_5)
dense_layer = Dense(1024, activation="relu")(flatten_layer)
label_layer = Dense(1024, activation="relu")(dense_layer)
output_layer = Dense(1, activation="linear")(label_layer)
model = Model(inputs=input_layer, outputs=output_layer)
adam_optimiser = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08)
model.compile(optimizer=adam_optimiser, loss="mean_squared_error", metrics=["accuracy", "mean_squared_error"])
return model
And my fit generator:
model = initialise_model()
early_stopping = EarlyStopping(monitor="val_loss", min_delta=0, patience=0, verbose=1, restore_best_weights=True)
model.fit_generator(generator, epochs=1, steps_per_epoch=1, verbose=2, callbacks=[early_stopping])
It's worth noting that the output of my generator is as expected, with the correct shape.
Many thanks