Train neural nets on 3D images (e.g. MRIs) 🧠
Project description
niftiai
niftiai aims to be the easiest framework to train neural nets on 3D images (often NIfTIs), using
fastaieasy neural net trainingniftivieweasy 3D image viewingmriaugeasy 3D image (+MRI-specific) augmentation
pip install niftiai to simplify your code and skip complex frameworks like MONAI and torchio!
Quick Start 🚀
Study the beginner tutorial to understand how 15 lines of code can train a neural net to classify 🧠 MRIs...
import openneuro as on
from deepmriprep import run_preprocess
from fastai.basics import pd, accuracy, CategoryBlock
from niftiai import cnn_learner3d, Scale, ImageDataLoaders3d
DATA_DIR = 'data/ds000005'
on.download(dataset=DATA_DIR[-8:], target_dir=DATA_DIR, include='*/anat/*T1w.*')
df = run_preprocess(bids_dir=DATA_DIR, outputs=['brain'])
table = pd.read_table(f'{DATA_DIR}/participants.tsv')
df = pd.concat([table, df.reset_index()], axis=1)
dls = ImageDataLoaders3d.from_df(df, fn_col='brain', item_tfms=[Scale()],
label_col='sex', y_block=CategoryBlock())
learner = cnn_learner3d(dls, metrics=[accuracy])
learner.fit(3)
learner.show_results() # add plt.show() if not in Jupyter notebook
...and the intermediate tutorial to see how 12 lines of code train a UNet to do MR image segmentation 🤯
import openneuro as on
from deepmriprep import run_preprocess
from niftiai import unet_learner3d, aug_transforms3d, Scale, SegmentationDataLoaders3d
DATA_DIR = 'data/ds000001'
on.download(dataset=DATA_DIR[-8:], target_dir=DATA_DIR, include='*/anat/*T1w.*')
df = run_preprocess(bids_dir=DATA_DIR, outputs=['mask']).reset_index()
aug_tfms = aug_transforms3d()
dls = SegmentationDataLoaders3d.from_df(df, fn_col='t1', item_tfms=Scale(),
label_col='mask', batch_tfms=aug_tfms)
learner = unet_learner3d(dls, c_out=2, linknet=True)
learner.fit(3, lr=1e-2)
learner.show_results() # add plt.show() if not in Jupyter notebook
👩💻 Also study the fastai tutorials to understand the underlying framework that is
... approachable and rapidly productive, while also being deeply hackable...
and discover its wide range of features like
- mixed precision training for reduced VRAM usage via
Learner.to_fp16()andLearner.to_bf16()
learner = learner.to_fp16() # to enable FP16, use this line before training
learner = learner.to_bf16() # to enable BF16, use this line before training
- 1cycle scheduled training for faster convergence via
Learner.fit_one_cycle()
from fastai.callback.all import *
...
learner.fit_one_cycle(...) # instead of learner.fit(...) to enable 1cycle scheduled training
- distributed training to use multiple GPUs via
accelerate
from fastai.distributed import *
...
with learner.distrib_ctx(): learn.fit(...) # and run with "accelerate launch ..."
- ...so much more...
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file niftiai-0.2.0.tar.gz.
File metadata
- Download URL: niftiai-0.2.0.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.9 Linux/6.11.0-26-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92aac83aac0fab3d848c979c005a074e983c8284e283ea75cfc0535d681ec684
|
|
| MD5 |
4cde0d68b4c3819b2d4651c267693aca
|
|
| BLAKE2b-256 |
10b4011e1a2312bd5a6625334993e7bed19de36c21198c4226d2e9092301900a
|
File details
Details for the file niftiai-0.2.0-py3-none-any.whl.
File metadata
- Download URL: niftiai-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.9 Linux/6.11.0-26-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a29b72a53e82b775a05b4e2f4f32d4ab70ddd545c86c9d8e41fabfa791a1b0e
|
|
| MD5 |
247cf192934cb383ac61c0d459967360
|
|
| BLAKE2b-256 |
cc80fc70a7de02f85d35cda67c6c4e6dfcce53df91dd630ea9aaf9930b253d95
|