[tune] get checkpoints paths for a trial after tuning (#6643)

This commit is contained in:
Yuhao Yang
2020-01-17 10:15:04 -08:00
committed by Richard Liaw
parent fa3c513276
commit 5f36e6eacb
4 changed files with 113 additions and 1 deletions
@@ -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)