簡體   English   中英

使用 Keras Tuner 搜索調諧器

[英]Tuner search with Keras Tuner

我正在使用 Keras Tuner 包。我嘗試使用此處解釋的示例進行超參數調整https://www.tensorflow.org/tutorials/keras/keras_tuner 代碼運行良好,但是當我啟動代碼時,但當我嘗試第二次和第三次啟動時,我遇到了問題。

tuner.search(X_train, Y_train, epochs=50, validation_split=0.2, callbacks=[stop_early])

# Get the optimal hyperparameters
best_hps=tuner.get_best_hyperparameters(num_trials=1)[0]

print(f"""
The hyperparameter search is complete. The optimal number of units in the first densely-connected
layer is {best_hps.get('units')} and the optimal learning rate for the optimizer
is {best_hps.get('learning_rate')}.
""")

第二次執行后代碼不會啟動並顯示前一次的結果。

INFO:tensorflow:Oracle triggered exit

The hyperparameter search is complete. The optimal number of units in the first densely-connected
layer is 128 and the optimal learning rate for the optimizer
is 0.001.

那么知道如何解決這個問題嗎?

Keras Tuner 將檢查點保存在 gcs 或本地目錄中的目錄中。 如果您想稍后恢復搜索,則可以使用此選項。 由於您的搜索之前已經完成,因此再次運行搜索將不會執行任何操作。 您必須先刪除該目錄才能重新開始搜索。

在您的示例中,在調諧器搜索之前,您將擁有以下內容:

tuner = kt.Hyperband(model_builder,
                     objective='val_accuracy',
                     max_epochs=10,
                     factor=3,
                     directory='my_dir',
                     project_name='intro_to_kt')

那就是要刪除的目錄。

下次,要在開始之前自動刪除,您可以將該代碼更改為:

tuner = kt.Hyperband(model_builder,
                     objective='val_accuracy',
                     max_epochs=10,
                     factor=3,
                     directory='my_dir',
                     project_name='intro_to_kt',
                     # if True, overwrite above directory if search is run again - i.e. don't resume
                     overwrite = True)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM