forked from Project-MONAI/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "64bd2d8c-4799-4073-bc28-c3632589c525", | ||
"metadata": {}, | ||
"source": [ | ||
"Copyright (c) MONAI Consortium \n", | ||
"Licensed under the Apache License, Version 2.0 (the \"License\"); \n", | ||
"you may not use this file except in compliance with the License. \n", | ||
"You may obtain a copy of the License at \n", | ||
" http://www.apache.org/licenses/LICENSE-2.0 \n", | ||
"Unless required by applicable law or agreed to in writing, software \n", | ||
"distributed under the License is distributed on an \"AS IS\" BASIS, \n", | ||
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \n", | ||
"See the License for the specific language governing permissions and \n", | ||
"limitations under the License.\n", | ||
"\n", | ||
"# Integrating Non-MONAI Code Into a Bundle\n", | ||
"\n", | ||
"This notebook will discuss strategies for integrating non-MONAI deep learning code into a bundle. This allows existing Pytorch workflows to be integrated into the bundle ecosystem, for example as a distributable bundle for the model zoo or some other repository like Hugging Face, or to integrate with MONAI Label. The assumption taken here is that you already have the components for preprocessing, inference, validation, and other parts of a workflow, and so the task is how to integrate these parts into MONAI types which can be embedded in config files.\n", | ||
"\n", | ||
"In the following cells we'll construct a bundle which follows the [CIFAR10 tutorial](https://github.com/pytorch/tutorials/blob/32d834139b8627eeacb5fb2862be9f095fcb0b52/beginner_source/blitz/cifar10_tutorial.py) in Pytorch's tutorials repo. A number of code components will be copied into the `scripts` directory of the bundle and linked into config files suitable to be used on the command line.\n", | ||
"\n", | ||
"We'll start with an initialised bundle and provide an appropriate metadata file describing the CIFAR10 classification network we'll provide:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "eb9dc6ec-13da-4a37-8afa-28e2766b9343", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\u001b[01;34mIntegrationBundle\u001b[00m\n", | ||
"├── \u001b[01;34mconfigs\u001b[00m\n", | ||
"│ └── metadata.json\n", | ||
"├── \u001b[01;34mdocs\u001b[00m\n", | ||
"│ └── README.md\n", | ||
"├── LICENSE\n", | ||
"└── \u001b[01;34mmodels\u001b[00m\n", | ||
"\n", | ||
"3 directories, 3 files\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%%bash\n", | ||
"\n", | ||
"python -m monai.bundle init_bundle IntegrationBundle\n", | ||
"rm IntegrationBundle/configs/inference.json\n", | ||
"tree IntegrationBundle" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 15, | ||
"id": "b29f053b-cf16-4ffc-bbe7-d9433fdfa872", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Overwriting IntegrationBundle/configs/metadata.json\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%%writefile IntegrationBundle/configs/metadata.json\n", | ||
"\n", | ||
"{\n", | ||
" \"version\": \"0.0.1\",\n", | ||
" \"changelog\": {\n", | ||
" \"0.0.1\": \"Initial version\"\n", | ||
" },\n", | ||
" \"monai_version\": \"1.2.0\",\n", | ||
" \"pytorch_version\": \"2.0.0\",\n", | ||
" \"numpy_version\": \"1.23.5\",\n", | ||
" \"optional_packages_version\": {},\n", | ||
" \"name\": \"IntegrationBundle\",\n", | ||
" \"task\": \"Example Bundle\",\n", | ||
" \"description\": \"This illustrates integrating non-MONAI code (CIFAR10 classification) into a bundle\",\n", | ||
" \"authors\": \"Your Name Here\",\n", | ||
" \"copyright\": \"Copyright (c) Your Name Here\",\n", | ||
" \"data_source\": \"CIFAR10\",\n", | ||
" \"data_type\": \"float32\",\n", | ||
" \"intended_use\": \"This is suitable for demonstration only\",\n", | ||
" \"network_data_format\": {\n", | ||
" \"inputs\": {\n", | ||
" \"image\": {\n", | ||
" \"type\": \"image\",\n", | ||
" \"format\": \"magnitude\",\n", | ||
" \"modality\": \"natural\",\n", | ||
" \"num_channels\": 3,\n", | ||
" \"spatial_shape\": [32, 32],\n", | ||
" \"dtype\": \"float32\",\n", | ||
" \"value_range\": [-1, 1],\n", | ||
" \"is_patch_data\": false,\n", | ||
" \"channel_def\": {\n", | ||
" \"0\": \"red\",\n", | ||
" \"1\": \"green\",\n", | ||
" \"2\": \"blue\"\n", | ||
" }\n", | ||
" }\n", | ||
" },\n", | ||
" \"outputs\": {\n", | ||
" \"pred\": {\n", | ||
" \"type\": \"probabilities\",\n", | ||
" \"format\": \"classes\",\n", | ||
" \"num_channels\": 10,\n", | ||
" \"spatial_shape\": [10],\n", | ||
" \"dtype\": \"float32\",\n", | ||
" \"value_range\": [0, 1],\n", | ||
" \"is_patch_data\": false,\n", | ||
" \"channel_def\": {\n", | ||
" \"0\": \"plane\",\n", | ||
" \"1\": \"car\",\n", | ||
" \"2\": \"bird\",\n", | ||
" \"3\": \"cat\",\n", | ||
" \"4\": \"deer\",\n", | ||
" \"5\": \"dog\",\n", | ||
" \"6\": \"frog\",\n", | ||
" \"7\": \"horse\",\n", | ||
" \"8\": \"ship\",\n", | ||
" \"9\": \"truck\"\n", | ||
" }\n", | ||
" }\n", | ||
" }\n", | ||
" }\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "f9eac927-052d-4632-966f-a87f06311b9b", | ||
"metadata": {}, | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python [conda env:monai]", | ||
"language": "python", | ||
"name": "conda-env-monai-py" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |