Skip to content

Commit 056a542

Browse files
authored
[DLMED] update bundle tutorial (Project-MONAI#741)
Signed-off-by: Nic Ma <[email protected]>
1 parent 437b08f commit 056a542

File tree

1 file changed

+48
-23
lines changed

1 file changed

+48
-23
lines changed

modules/bundle/get_started.ipynb

+48-23
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
"This notebook is a step-by-step tutorial to help get started to develop a bundle package, which contains a config file to construct the training pipeline and also has a `metadata.json` file to define the metadata information.\n",
1414
"\n",
1515
"This notebook mainly contains the below sections:\n",
16-
"- Define a training config with `JSON` or `YAML` format\n",
17-
"- Execute training based on bundle scripts and configs\n",
18-
"- Hybrid programming with config and python code\n",
16+
"- Define a training config with `JSON` or `YAML` format.\n",
17+
"- Execute training based on bundle scripts and configs.\n",
18+
"- Execute other scripts for bundle functionalities.\n",
19+
"- Hybrid programming with config and python code.\n",
1920
"\n",
2021
"You can find the usage examples of MONAI bundle key features and syntax in this tutorial, like:\n",
2122
"- Instantiate a python object from a dictionary config with `_target_` indicating class or function name or module path.\n",
@@ -511,9 +512,7 @@
511512
"source": [
512513
"## Execute training with bundle script - `run`\n",
513514
"\n",
514-
"There are several predefined scripts in MONAI bundle module to help execute `regular training`, `metadata verification base on schema`, `network input / output verification`, `export to TorchScript model`, etc.\n",
515-
"\n",
516-
"Here we leverage the `run` script and specify the ID of trainer in the config.\n",
515+
"There are several predefined scripts in MONAI bundle module, here we leverage the `run` script and specify the ID of trainer in the config.\n",
517516
"\n",
518517
"Just define the entry point expressions in the config to execute in order, and specify the `runner_id` in CLI script."
519518
]
@@ -535,7 +534,9 @@
535534
"cell_type": "markdown",
536535
"metadata": {},
537536
"source": [
538-
"`python -m monai.bundle run training --config_file configs/train.json`"
537+
"```shell\n",
538+
"python -m monai.bundle run training --config_file configs/train.json\n",
539+
"```"
539540
]
540541
},
541542
{
@@ -546,28 +547,52 @@
546547
"\n",
547548
"To override some config items at runtime, users can specify the target `id` and `value` at command line, or override the `id` with some content in another config file. Here we set the device to `cuda:1` at runtime.\n",
548549
"\n",
549-
"Please note that \"#\" and \"$\" may be meaningful syntax for some `shell` and `CLI` tools, so may need to add escape character or quotes for them in the command line, like: `\"\\$torch.device('cuda:1')\"`. For more details: https://github.com/google/python-fire/blob/v0.4.0/fire/parser.py#L60."
550-
]
551-
},
552-
{
553-
"cell_type": "markdown",
554-
"metadata": {},
555-
"source": [
556-
"`python -m monai.bundle run training --config_file configs/train.json --device \"\\$torch.device('cuda:1')\"`"
557-
]
558-
},
559-
{
560-
"cell_type": "markdown",
561-
"metadata": {},
562-
"source": [
563-
"Override content from another config file."
550+
"Please note that \"#\" and \"$\" may be meaningful syntax for some `shell` and `CLI` tools, so may need to add escape character or quotes for them in the command line, like: `\"\\$torch.device('cuda:1')\"`. For more details: https://github.com/google/python-fire/blob/v0.4.0/fire/parser.py#L60.\n",
551+
"```shell\n",
552+
"python -m monai.bundle run training --config_file configs/train.json --device \"\\$torch.device('cuda:1')\"\n",
553+
"```\n",
554+
"Override content from another config file.\n",
555+
"```shell\n",
556+
"python -m monai.bundle run training --config_file configs/train.json --network \"%configs/test.json#network\"\n",
557+
"```"
564558
]
565559
},
566560
{
567561
"cell_type": "markdown",
568562
"metadata": {},
569563
"source": [
570-
"`python -m monai.bundle run training --config_file configs/train.json --network \"%configs/test.json#network\"`"
564+
"## Execute other bundle scripts\n",
565+
"\n",
566+
"Besides `run`, there are also many other scripts for bundle functionalities. All the scripts are available at: https://docs.monai.io/en/latest/bundle.html#scripts.\n",
567+
"\n",
568+
"Here is some typical examples:\n",
569+
"\n",
570+
"1. Initialize a bundle directory based on the template and pretrained checkpoint weights.\n",
571+
"```shell\n",
572+
"python -m monai.bundle init_bundle --bundle_dir <target dir> --ckpt_file <checkpoint path>\n",
573+
"```\n",
574+
"\n",
575+
"2. Export the model checkpoint to a `TorchScript` model at the given filepath with metadata and config included as JSON files.\n",
576+
"```shell\n",
577+
"python -m monai.bundle ckpt_export network --filepath <export path> --ckpt_file <checkpoint path> --config_file <config path>\n",
578+
"```\n",
579+
"\n",
580+
"3. Verify the format of provided `metadata` file based on the predefined `schema`.\n",
581+
"```shell\n",
582+
"python -m monai.bundle verify_metadata --meta_file <meta path>\n",
583+
"```\n",
584+
"\n",
585+
"4. Verify the input and output data shape and data type of network defined in the metadata. It will test with fake Tensor data according to the required data shape in `metadata`.\n",
586+
"```shell\n",
587+
"python -m monai.bundle verify_net_in_out network --meta_file <metadata path> --config_file <config path>\n",
588+
"```\n",
589+
"The acceptable data shape in the metadata can support `\"*\"` for any size, or use an expression with Python mathematical operators and one character variables to represent dependence on an unknown quantity, for example, `\"2**p\"` represents a size which must be a power of 2, `\"2**p*n\"` must be a multiple of a power of 2. `\"spatial_shape\": [ \"32 * n\", \"2 ** p * n\", \"*\"]`.\n",
590+
"\n",
591+
"\n",
592+
"5. Download a bundle from Github release or URL.\n",
593+
"```shell\n",
594+
"python -m monai.bundle download --name <bundle_name>\n",
595+
"```"
571596
]
572597
},
573598
{

0 commit comments

Comments
 (0)