Skip to main content

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

  • fastai easy neural net training
  • niftiview easy 3D image viewing
  • mriaug easy 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

learner = learner.to_fp16()  # to enable FP16, use this line before training
learner = learner.to_bf16()  # to enable BF16, use this line before training
from fastai.callback.all import *
...
learner.fit_one_cycle(...)  # instead of learner.fit(...) to enable 1cycle scheduled training
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

niftiai-0.1.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

niftiai-0.1.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file niftiai-0.1.0.tar.gz.

File metadata

  • Download URL: niftiai-0.1.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.10.13 Linux/5.15.0-56-generic

File hashes

Hashes for niftiai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 23aa7959918a3efe15e17163f9f4bfb922a8611e5e4e076d8a195cb6a99088f4
MD5 8bcee023e8f53bb0907eb931aa839a86
BLAKE2b-256 86cfd0ed3168a51aa4afef1400752b519778b050077f758c35ed2e9270a068c2

See more details on using hashes here.

File details

Details for the file niftiai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: niftiai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.10.13 Linux/5.15.0-56-generic

File hashes

Hashes for niftiai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a05333053329037914cc6837bb8f2f8200241f2b1cb25ba36d0d033105191fc
MD5 164e3c8a407b541fe5bd6b9cf2b15fc9
BLAKE2b-256 29e4bf6de4c5e9d2149714f47c375f1aca87b88e52467ed8bcb6cf37f2f86b7c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page