I'm working on my own dataset and trying to fine-tune the parameters using the Keras tuner.I'm using the basic model-building function:
from tensorflow.keras import layers
from keras_tuner import RandomSearch
def build_model(hp):
model = keras.Sequential()
model.add(layers.Flatten())
model.add(
layers.Dense(
units=hp.Int("units", min_value=32, max_value=512, step=32),
activation="relu",
)
)
model.add(layers.Dense(10, activation="softmax"))
model.compile(
optimizer=keras.optimizers.Adam(
hp.Choice("learning_rate", values=[1e-2, 1e-3, 1e-4])
),
loss="categorical_crossentropy",
metrics=["accuracy"],
)
return model
After showing the search space summary and trying to search the best values from the following code statement:
tuner.search(X_train, y_train, epochs=15, validation_data=(X_test, y_test))
the following error was raised:
logits and labels must have the same first dimension, got logits shape [32,10] and labels shape [6144]
I tried to change the loss to 'sparse_categorical_crossentropy'
and 'categorical_crossentropy'
but it didn't work.
My dataset shape is as follows:
x_test (201, 16)
y_test (201, 16, 12)
X_train (1803, 16)
y_train (1803, 16, 12)
x_val (500, 16)
y_val (500, 16, 12)