diff --git a/auto3dseg/docs/ensemble.md b/auto3dseg/docs/ensemble.md index e38eeb4ad5..bb6e7fb2a8 100644 --- a/auto3dseg/docs/ensemble.md +++ b/auto3dseg/docs/ensemble.md @@ -15,7 +15,7 @@ from monai.apps.auto3dseg import ( AlgoEnsembleBuilder, import_bundle_algo_history, ) -from monai.utils.enums import AlgoEnsembleKeys +from monai.utils.enums import AlgoKeys # Assuming you have already trained the models @@ -33,7 +33,7 @@ ensemble = builder.get_ensemble() pred = ensemble() print("ensemble picked the following best {0:d}:".format(n_best)) for algo in ensemble.get_algo_ensemble(): - print(algo[AlgoEnsembleKeys.ID]) + print(algo[AlgoKeys.ID]) ``` ### Customization diff --git a/auto3dseg/notebooks/auto3dseg_autorunner_ref_api.ipynb b/auto3dseg/notebooks/auto3dseg_autorunner_ref_api.ipynb index a56790987d..cc9fbb8471 100644 --- a/auto3dseg/notebooks/auto3dseg_autorunner_ref_api.ipynb +++ b/auto3dseg/notebooks/auto3dseg_autorunner_ref_api.ipynb @@ -66,12 +66,12 @@ "from monai.auto3dseg import algo_to_pickle\n", "from monai.bundle.config_parser import ConfigParser\n", "from monai.config import print_config\n", + "from monai.utils.enums import AlgoKeys\n", "\n", "print_config()" ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -224,7 +224,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -246,7 +245,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -308,11 +306,11 @@ "outputs": [], "source": [ "history = import_bundle_algo_history(work_dir, only_trained=False)\n", - "for task in history:\n", - " for _, algo in task.items():\n", - " algo.train(train_param) # can use default params by `algo.train()`\n", - " acc = algo.get_score()\n", - " algo_to_pickle(algo, template_path=algo.template_path, best_metrics=acc)" + "for algo_dict in history:\n", + " algo = algo_dict[AlgoKeys.ALGO]\n", + " algo.train(train_param) # can use default params by `algo.train()`\n", + " acc = algo.get_score()\n", + " algo_to_pickle(algo, template_path=algo.template_path, best_metric=acc)" ] }, { @@ -355,7 +353,7 @@ ], "metadata": { "kernelspec": { - "display_name": "monai-0", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -369,11 +367,11 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13 (default, Mar 28 2022, 06:59:08) [MSC v.1916 64 bit (AMD64)]" + "version": "3.8.13" }, "vscode": { "interpreter": { - "hash": "85754776c861f3ba5898fde994bfc400ed208cd401a6036e85fdc16c4f506eaf" + "hash": "adad466f3ae0207e0597f6bf999e86a6601b04f4db83734c81b06a9e73a01812" } } }, diff --git a/auto3dseg/notebooks/ensemble_byoc.ipynb b/auto3dseg/notebooks/ensemble_byoc.ipynb index 8e1b62308c..6f5d432c78 100644 --- a/auto3dseg/notebooks/ensemble_byoc.ipynb +++ b/auto3dseg/notebooks/ensemble_byoc.ipynb @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -70,7 +70,7 @@ "from monai.bundle.config_parser import ConfigParser\n", "from monai.config import print_config\n", "from monai.data import create_test_image_3d\n", - "from monai.utils.enums import AlgoEnsembleKeys\n", + "from monai.utils.enums import AlgoKeys\n", "\n", "print_config()" ] @@ -91,7 +91,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -130,7 +130,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -165,7 +165,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -239,9 +239,9 @@ " \"num_warmup_epochs\": 1,\n", "}\n", "\n", - "for h in history:\n", - " for _, algo in h.items():\n", - " algo.train(train_param)" + "for algo_dict in history:\n", + " algo = algo_dict[AlgoKeys.ALGO]\n", + " algo.train(train_param)" ] }, { @@ -266,7 +266,7 @@ "\n", "print(\"The ensemble randomly picks the following models:\")\n", "for algo in ensemble.get_algo_ensemble():\n", - " print(algo[AlgoEnsembleKeys.ID])" + " print(algo[AlgoKeys.ID])" ] } ], @@ -286,7 +286,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.8.10" }, "vscode": { "interpreter": { diff --git a/auto3dseg/notebooks/hpo_nni.ipynb b/auto3dseg/notebooks/hpo_nni.ipynb index 449deab399..7a32863f18 100644 --- a/auto3dseg/notebooks/hpo_nni.ipynb +++ b/auto3dseg/notebooks/hpo_nni.ipynb @@ -76,12 +76,12 @@ "from monai.apps.auto3dseg.utils import export_bundle_algo_history, import_bundle_algo_history\n", "from monai.bundle.config_parser import ConfigParser\n", "from monai.config import print_config\n", + "from monai.utils.enums import AlgoKeys\n", "\n", "print_config()" ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -202,19 +202,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "algorithms imported from the history:\n", - "0: segresnet2d_0\n", - "1: dints_0\n", - "2: swinunetr_0\n", - "3: segresnet_0\n" - ] - } - ], + "outputs": [], "source": [ "try:\n", " history = bundle_generator.get_history()\n", @@ -223,8 +211,9 @@ " history = import_bundle_algo_history(work_dir, only_trained=False)\n", "\n", "print(\"algorithms imported from the history:\")\n", + "\n", "for i, algo_dict in enumerate(history):\n", - " print(f\"{i}: \", list(algo_dict.keys())[0])" + " print(f\"{i}: \", algo_dict[AlgoKeys.ID])" ] }, { @@ -239,23 +228,14 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "User selected algorithm: \n", - "segresnet2d_0\n" - ] - } - ], + "outputs": [], "source": [ - "selected_algorithm_index = 0\n", - "algo_dict = history[selected_algorithm_index]\n", - "algo_name = list(algo_dict.keys())[0]\n", - "algo = algo_dict[algo_name]\n", - "print(\"User selected algorithm: \")\n", - "print(algo_name)" + "for algo_dict in history:\n", + " if algo_dict[AlgoKeys.ID].split(\"_\")[0] == \"segresnet\":\n", + " break\n", + "algo_name = algo_dict[AlgoKeys.ID]\n", + "algo = algo_dict[AlgoKeys.ALGO]\n", + "print(f\"{algo_name} is selected. \")" ] }, { @@ -382,7 +362,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.8.10" }, "vscode": { "interpreter": { diff --git a/auto3dseg/notebooks/hpo_optuna.ipynb b/auto3dseg/notebooks/hpo_optuna.ipynb index 47cd562309..8b145e0fdb 100644 --- a/auto3dseg/notebooks/hpo_optuna.ipynb +++ b/auto3dseg/notebooks/hpo_optuna.ipynb @@ -69,6 +69,7 @@ "from monai.apps.auto3dseg.utils import export_bundle_algo_history, import_bundle_algo_history\n", "from monai.bundle.config_parser import ConfigParser\n", "from monai.config import print_config\n", + "from monai.utils.enums import AlgoKeys\n", "\n", "print_config()" ] @@ -211,7 +212,7 @@ "\n", "print(\"algorithms imported from the history:\")\n", "for i, algo_dict in enumerate(history):\n", - " print(f\"{i}: \", list(algo_dict.keys())[0])" + " print(f\"{i}: \", algo_dict[AlgoKeys.ID])" ] }, { @@ -228,16 +229,15 @@ "metadata": {}, "outputs": [], "source": [ - "selected_algorithm_index = 0\n", - "algo_dict = history[selected_algorithm_index]\n", - "algo_name = list(algo_dict.keys())[0]\n", - "algo = algo_dict[algo_name]\n", - "print(\"User selected algorithm: \")\n", - "print(algo_name)" + "for algo_dict in history:\n", + " if algo_dict[AlgoKeys.ID].split(\"_\")[0] == \"segresnet\":\n", + " break\n", + "algo_name = algo_dict[AlgoKeys.ID]\n", + "algo = algo_dict[AlgoKeys.ALGO]\n", + "print(f\"{algo_name} is selected. \")" ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -333,7 +333,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.8.10" }, "vscode": { "interpreter": {