Skip to content

semantic updates for Auto3dseg #1288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions auto3dseg/docs/ensemble.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
20 changes: 9 additions & 11 deletions auto3dseg/notebooks/auto3dseg_autorunner_ref_api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -224,7 +224,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -246,7 +245,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -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)"
]
},
{
Expand Down Expand Up @@ -355,7 +353,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "monai-0",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -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"
}
}
},
Expand Down
20 changes: 10 additions & 10 deletions auto3dseg/notebooks/ensemble_byoc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -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()"
]
Expand All @@ -91,7 +91,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -130,7 +130,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -165,7 +165,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -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)"
]
},
{
Expand All @@ -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])"
]
}
],
Expand All @@ -286,7 +286,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.8.10"
},
"vscode": {
"interpreter": {
Expand Down
44 changes: 12 additions & 32 deletions auto3dseg/notebooks/hpo_nni.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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",
Expand All @@ -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])"
]
},
{
Expand All @@ -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. \")"
]
},
{
Expand Down Expand Up @@ -382,7 +362,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.8.10"
},
"vscode": {
"interpreter": {
Expand Down
18 changes: 9 additions & 9 deletions auto3dseg/notebooks/hpo_optuna.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
]
Expand Down Expand Up @@ -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])"
]
},
{
Expand All @@ -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": [
Expand Down Expand Up @@ -333,7 +333,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.8.10"
},
"vscode": {
"interpreter": {
Expand Down