#keras #google-colaboratory
#keras #google-colaboratory
Вопрос:
У меня возникают некоторые проблемы при использовании kerastuner в Colab. Это мой код:
def build_model(hp):
input_ = Input(shape=(20,20,1))
cnn_out1 = Conv2D(filters=16, kernel_size=hp.Int('kernel_size', 3, 7, step=2, default=3) , name='con1',
use_bias=True, activation = tf.nn.relu, kernel_regularizer=keras.regularizers.l2(0.01))(input_)
# cnn_out1 = keras.layers.BatchNormalization(epsilon=1e-6)
cnn_out = MaxPooling2D(pool_size=(2, 2))(cnn_out1)
cnn_out = keras.layers.Flatten()(cnn_out)
cnn_out = Dense(64, activation=tf.nn.relu, name='fc1', use_bias=True)(cnn_out)
cnn_out = keras.layers.Dropout(0.5)(cnn_out)
cnn_out = Dense(64, activation=tf.nn.relu, name='fc2', use_bias=True)(cnn_out)
#将CNN层命名为cnn_model供后期TimeDistributed调用
cnn_model = Model(inputs=input_, outputs=cnn_out)
cnn_model_map = Model(inputs=input_, outputs=cnn_out1)
# cnn_model.summary()
input_seq = Input(shape=(time_seq, 20, 20, 1))
processed_sequences = TimeDistributed(cnn_model)(input_seq)
# rnn_out = keras.layers.GRU(units=128, name='gru1', recurrent_dropout=0.5)(processed_sequences)
rnn_out = keras.layers.GRU(units=128, name='gru1')(processed_sequences)
# rnn_out = keras.layers.LSTM(units=128, name='lstm1')(processed_sequences)
rnn_out = keras.layers.Dropout(0.5)(rnn_out)
predictions = Dense(6, activation='softmax', name='fc3')(rnn_out)
rnn_model = Model(inputs = input_seq, outputs = predictions)
#rnn_model.summary()
rnn_model.compile(loss='categorical_crossentropy', optimizer='Nadam', metrics=['accuracy'])
return rnn_model
tuner = kt.Hyperband(
build_model,
objective = 'val_accuracy',
max_epochs=10,
hyperband_iterations=2
)
tuner.search(data, label_ohe, validation_split=0.1, epochs=30, shuffle='true', callbacks=[tf.keras.callbacks.EarlyStopping(patience=1)])
При запуске этого кода я получаю следующую подсказку
INFO:tensorflow:Reloading Oracle from existing project ./untitled_project/oracle.json
INFO:tensorflow:Reloading Tuner from ./untitled_project/tuner0.json
INFO:tensorflow:Oracle triggered exit
Кто-нибудь знает, как решить эту проблему?
Ответ №1:
он сообщает вам, что проект уже существует. Добавьте перезапись = True в tuner = kt.Гипербанда(build_model, objective = ‘val_accuracy’, max_epochs= 10, hyperband_iterations= 2 )