mirror of
https://github.com/wassname/ray.git
synced 2026-07-28 11:25:04 +08:00
[tune] get checkpoints paths for a trial after tuning (#6643)
This commit is contained in:
@@ -118,9 +118,23 @@ if __name__ == "__main__":
|
||||
verbose=1,
|
||||
stop=stopper.stop,
|
||||
export_formats=[ExportFormat.MODEL],
|
||||
checkpoint_score_attr="mean_accuracy",
|
||||
checkpoint_freq=5,
|
||||
keep_checkpoints_num=4,
|
||||
num_samples=4,
|
||||
config={
|
||||
"lr": tune.uniform(0.001, 1),
|
||||
"momentum": tune.uniform(0.001, 1),
|
||||
})
|
||||
# __tune_end__
|
||||
|
||||
best_trial = analysis.get_best_trial("mean_accuracy")
|
||||
best_checkpoint = max(
|
||||
analysis.get_trial_checkpoints_paths(best_trial, "mean_accuracy"))
|
||||
restored_trainable = PytorchTrainble()
|
||||
restored_trainable.restore(best_checkpoint[0])
|
||||
best_model = restored_trainable.model
|
||||
# Note that test only runs on a small random set of the test data, thus the
|
||||
# accuracy may be different from metrics shown in tuning process.
|
||||
test_acc = test(best_model, get_data_loaders()[1])
|
||||
print("best model accuracy: ", test_acc)
|
||||
|
||||
Reference in New Issue
Block a user