Skip to content

Commit

Permalink
Last notebook started
Browse files Browse the repository at this point in the history
  • Loading branch information
ericspod committed Aug 31, 2023
1 parent 0000e1e commit b82a5f7
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bundle/02_mednist_classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"\n",
"In this tutorial we'll describe how to create a bundle for a classification network. This will include how to train and apply the network on the command line. MedNIST will be used as the dataset with the bundle based off the [MONAI 101 notebook](https://github.com/Project-MONAI/tutorials/blob/main/2d_classification/monai_101.ipynb).\n",
"\n",
"The dataset is kindly made available by Dr. Bradley J. Erickson M.D., Ph.D. (Department of Radiology, Mayo Clinic) under the Creative Commons CC BY-SA 4.0 license. If you use the MedNIST dataset, please acknowledge the source of the MedNIST dataset: the repository https://github.com/Project-MONAI/MONAI/ or the MedNIST tutorial for image classification https://github.com/Project-MONAI/MONAI/blob/master/examples/notebooks/mednist_tutorial.ipynb.\n",
"\n",
"This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.\n",
"\n",
"First we'll consider a condensed version of the code from that notebook and go step-by-step how best to represent this as a bundle:"
]
},
Expand Down
165 changes: 165 additions & 0 deletions bundle/04_integrating_code.ipynb
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
}

0 comments on commit b82a5f7

Please sign in to comment.