Initialise a new bundle directory with some default configuration files and optionally network weights. Typical usage example: .. code-block:: bash python -m monai.bundle init_bundle /path/to/bundle_dir network_ckpt.pt Args: bundle_dir: directory name to create,
(
bundle_dir: PathLike,
ckpt_file: PathLike | None = None,
network: torch.nn.Module | None = None,
dataset_license: bool = False,
metadata_str: dict | str | None = None,
inference_str: dict | str | None = None,
)
| 1745 | |
| 1746 | |
| 1747 | def init_bundle( |
| 1748 | bundle_dir: PathLike, |
| 1749 | ckpt_file: PathLike | None = None, |
| 1750 | network: torch.nn.Module | None = None, |
| 1751 | dataset_license: bool = False, |
| 1752 | metadata_str: dict | str | None = None, |
| 1753 | inference_str: dict | str | None = None, |
| 1754 | ) -> None: |
| 1755 | """ |
| 1756 | Initialise a new bundle directory with some default configuration files and optionally network weights. |
| 1757 | |
| 1758 | Typical usage example: |
| 1759 | |
| 1760 | .. code-block:: bash |
| 1761 | |
| 1762 | python -m monai.bundle init_bundle /path/to/bundle_dir network_ckpt.pt |
| 1763 | |
| 1764 | Args: |
| 1765 | bundle_dir: directory name to create, must not exist but parent direct must exist |
| 1766 | ckpt_file: optional checkpoint file to copy into bundle |
| 1767 | network: if given instead of ckpt_file this network's weights will be stored in bundle |
| 1768 | dataset_license: if `True`, a default license file called "data_license.txt" will be produced. This |
| 1769 | file is required if there are any license conditions stated for data your bundle uses. |
| 1770 | metadata_str: optional metadata string to write to bundle, if not given a default will be used. |
| 1771 | inference_str: optional inference string to write to bundle, if not given a default will be used. |
| 1772 | """ |
| 1773 | if metadata_str is None: |
| 1774 | metadata_str = DEFAULT_METADATA |
| 1775 | if inference_str is None: |
| 1776 | inference_str = DEFAULT_INFERENCE |
| 1777 | |
| 1778 | bundle_dir = Path(bundle_dir).absolute() |
| 1779 | |
| 1780 | if bundle_dir.exists(): |
| 1781 | raise ValueError(f"Specified bundle directory '{str(bundle_dir)}' already exists") |
| 1782 | |
| 1783 | if not bundle_dir.parent.is_dir(): |
| 1784 | raise ValueError(f"Parent directory of specified bundle directory '{str(bundle_dir)}' does not exist") |
| 1785 | |
| 1786 | configs_dir = bundle_dir / "configs" |
| 1787 | models_dir = bundle_dir / "models" |
| 1788 | docs_dir = bundle_dir / "docs" |
| 1789 | |
| 1790 | bundle_dir.mkdir() |
| 1791 | configs_dir.mkdir() |
| 1792 | models_dir.mkdir() |
| 1793 | docs_dir.mkdir() |
| 1794 | |
| 1795 | if isinstance(metadata_str, dict): |
| 1796 | metadata_str = json.dumps(metadata_str, indent=4) |
| 1797 | |
| 1798 | if isinstance(inference_str, dict): |
| 1799 | inference_str = json.dumps(inference_str, indent=4) |
| 1800 | |
| 1801 | with open(str(configs_dir / "metadata.json"), "w") as o: |
| 1802 | o.write(metadata_str) |
| 1803 | |
| 1804 | with open(str(configs_dir / "inference.json"), "w") as o: |
nothing calls this directly
no test coverage detected
searching dependent graphs…