Skip to content

Commit

Permalink
add 03-03
Browse files Browse the repository at this point in the history
  • Loading branch information
ncullen93 committed Jun 4, 2024
1 parent 366385c commit 78fbe12
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
2 changes: 1 addition & 1 deletion book/03-02.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Prequisites\n",
"### Prerequisites\n",
"\n",
"In this chapter, we will use the standard libraries of nitrain, ants, and numpy. As before, we will be primarily using images already loaded into memory but the concepts still apply to reading images from local folders or the cloud."
]
Expand Down
81 changes: 78 additions & 3 deletions book/03-03.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,93 @@
"\n",
":::{warning}\n",
"This chapter is an unfinished draft. I recommend skipping it for now since it is likely to change.\n",
":::"
":::\n",
"\n",
"In the last chapter, you were introduced to loaders in nitrain. Loaders take in datasets and some extra parameters as input, then they generate batches of training-ready arrays. So far, we have only shown examples were full images were being served in batches. However, it is the case that we will want to train our models on only parts of images such as slices, blocks, or patches.\n",
"\n",
"This is where samplers come in. Samplers are optionally passed into loaders and take in some optional parameters themselves to determine how the images will be sampled. This chapter will introduce you to the different types of samplers and how to use them."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Prerequisites\n",
"\n",
"In this chapter, we will use the standard libraries of nitrain, ants, and numpy. We will load in the samplers module from nitrain which gives us access to all the different types of samplers we will use. As before, we will be primarily using images already loaded into memory but the concepts still apply to reading images from local folders or the cloud."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import nitrain as nt\n",
"from nitrain import samplers\n",
"import ants\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Slices"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Blocks"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Patches"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Slice-patches"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
"source": [
"## Summary\n",
"\n",
"As you saw in this chapter, samplers are used when you want to train your model on parts of images. Nitrain supports sampling 2D slices of 3D images, 2D patches of 2D images, 3D blocks of 3D images, and 2D slice-patches of 3D images. The samplers make this typically complex process of sampling sub-images into something easy and intuitive.\n",
"\n",
"Importantly, the basic philosophy of samplers is that you will train on all possible samples of the image. In other words, a slice sampler will always serve you all the possible slices of an image. You can crop the images if you want to avoid empty slices and you can shuffle the slices to serve them in random order, but all slices will be served to the model eventually in a single training epoch.\n",
"\n",
"In the next chapter, you will learn about applying random augmentation transforms. This is the final piece in getting the most out of loaders and ensuring you have a robust and flexible batch generation strategy."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion book/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ If you have questions about the book specifically, you can post an issue at gith

## About the author

Nicholas Cullen has a BS in Systems Engineering from University of Florida and a PhD in Neuroscience from Lund University in Sweden. He has 10+ years of experience developing tools for medical imaging in Python, R, and C++. He has published 40+ high-impact journal articles on biomarkers, clinical trials, and neurodegenerative diseases and has an H-index of 29.
Nicholas Cullen has a BS in Systems Engineering from University of Florida and a PhD in Biostatistics from Lund University in Sweden. He has 10+ years of experience developing tools for medical imaging in Python, R, and C++. He has published 40+ high-impact journal articles on biomarkers, clinical trials, and neurodegenerative diseases and has an H-index of 29.

He started nitrain to make medical imaging AI more accessible to non-imaging experts. If you have any questions, he can be reached at nickcullen31@gmail.com.

0 comments on commit 78fbe12

Please sign in to comment.