I am using Keras tuner. For the simple following code:
import keras_tuner as kt
from tensorflow.keras.regularizers import l1, l2
from tensorflow.keras.models import Sequential
# x: 100 x 20
# y: 1 x 100
tuner = kt.Hyperband(
self.build_auto_encoder_model,
objective='val_loss',
max_epochs=30,
hyperband_iterations=20)
tuner.search(x[0:80], y[0:80], epochs=30, validation_data=(x[80:], y[80:]))
best_model = tuner.get_best_models(1)[0]
def build_auto_encoder_model(hp):
model = Sequential()
regulizer_rate = hp.Choice("regulizer_rate", [1e-1, 1e-2, 1e-3, 1e-4, 1e-5])
model.add(Dense(18, input_dim=20, activation='relu', kernel_regularizer=l1(regulizer_rate)))
model.add(Dense(12, activation='relu', kernel_regularizer=l1(regulizer_rate)))
model.add(Dense(10, activation='relu', kernel_regularizer=l1(regulizer_rate)))
model.compile(optimizer=Adam(1e-2), loss='mse')
I have already tried for the different number of Dense
layers, I am getting the following error:
Tensor's shape (20, 18) is not compatible with supplied shape (20, 15)
However, when totally, created a new project, it works. What was the reason?