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...
Metadata
Release files for niftiai 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| niftiai-0.3.0.tar.gz | 12.5 kB | Without provenance | Details for niftiai-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| niftiai-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for niftiai-0.3.0-py3-none-any.whl |
Total release size: 26.4 kB
Release files / niftiai-0.3.0.tar.gz
| Download URL | niftiai-0.3.0.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
29fef3b21590469f8aa6a7935c50f21a58672b50b4a16e85263eb30aaddcc0de
|
|
BLAKE2b-256 checksum How to use checksums |
59deb91710a62e97aaa10b9fb9df40c7f9f9873ae2daec1f654d1dd50bcfece7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.12.3 Linux/6.14.0-27-generic
|
Release files / niftiai-0.3.0-py3-none-any.whl
| Download URL | niftiai-0.3.0-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d139685e3114c596caf8bb1c4dfc175c7a20fec2a7a288a6570befdfc198e2dd
|
|
BLAKE2b-256 checksum How to use checksums |
2a796d062410e7838efe8edfc6d6aaa61c807b3367b945cf7ffd5408f92baf52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.12.3 Linux/6.14.0-27-generic
|
Security for niftiai 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.