У меня есть несколько точек сохранения для разных моделей, которые я хотел бы оценить на другом компьютере (Kaggle), но не могу найти документацию о том, как восстановить файл hdf5 и запустить BayesSearchCV с этой точки.
Вот как я создаю BayesSearchCV и сохраняю обратный вызов как .hdf5
Любая помощь очень ценится!
search_space = dict()
search_space["epochs"] = Integer(125, 155, 'uniform')
search_space["batch_size"] = Integer(165, 220, 'uniform')
def bayes_search(filepath, model):
checkpoint_callback = skopt.callbacks.CheckpointSaver(filepath)
NN_start = process_time()
estimator= KerasClassifier (build_fn=model, verbose=0)# , epochs=220, batch_size=256
bayes = BayesSearchCV(estimator, search_spaces=search_space, cv=3)
fit_CV = bayes.fit(X_train, y_train, callback=[checkpoint_callback])
NN_stop = process_time()
print("Elapsed time during BayesCV in minutes:", ((NN_stop - NN_start) /60))
print(fit_CV.best_params_)
return fit_CV, bayes
# Define Model
def buildmodel1(optimizer = 'adam'):
model = Sequential()
model.add(Dense(784, activation='selu',input_dim=784, kernel_initializer="he_normal", use_bias = True))
layers.Dropout(rate=0.4)
model.add(Dense(150, activation='selu', kernel_initializer="he_normal", use_bias = True))
layers.Dropout(rate=0.25)
model.add(Dense(150, activation='selu', kernel_initializer="he_normal"))
layers.Dropout(rate=0.25)
model.add(Dense(150, activation='selu', kernel_initializer="he_normal"))
layers.Dropout(rate=0.25)
model.add(Dense(150, activation='selu', kernel_initializer="he_normal"))
layers.Dropout(rate=0.25)
model.add(Dense(150, activation='selu', kernel_initializer="he_normal"))
layers.Dropout(rate=0.25)
model.add(Dense(10, activation='softmax', kernel_initializer="he_normal"))
# compile the keras model
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
# fit the keras model on the dataset
#model.fit(X_train, y_train, epochs=152, batch_size=176)
# evaluate the keras model
#_, accuracy = model.evaluate(X_val, y_val)
return(model)
# Save for import to Kaggle
filepath = 'my_best_model1.hdf5'
model1_bayesCV, cv_instance = bayes_search(filepath, buildmodel1)