NiftyTorch is a Python API for deploying deep neural networks for Neuroimaging research.


The motivation behind the development of such a library is that there is no centralized tool for deploying 3D deep learning for neuroimaging. In addition, most of the existing tools require expert technical know-how in deep learning or programming, creating a barrier for entry. The goal is to provide a one stop API using which the users can perform classification tasks, Segmentation tasks and Image Generation tasks. The intended audience are the members of neuroimaging who would like to explore deep learning but have no background in coding.

For demos, see this folder.

Highlighted Features

  • Pytorch Embedded End to End data-loading pipeline
  • Built-in Attention module to demographic data and other modalities or mask
  • Additional Loss Functions (not in PyTorch) incorporated to easily use with any network use
  • Automatic Hyperparameter tuning for each network
  • Easily Customizable to use your own network
  • Multi-scale Training
  • Built-in classification networks
  • Built-in CNNs units such as Bottleneck, BinaryActivation


  • Data Loader
    • Classification DataLoader for nifty files
    • Segmentation DataLoader for nifty files
  • Loss Functions
    • Cross Entropy
    • Focal Loss
    • Dice Loss
    • Focal Dice Loss
    • Tversky Loss
    • Lovarsz Softmax
    • Triplet Loss
    • Contrastive Loss
  • Support for including demographic information using attention
    • Position Attention
    • Channel Attention
  • Convolutional Neural Network Units (Layers)
    • BottleNeck Unit
    • Fire Unit
    • Shuffle Unit
    • Binary Activation
    • Binary Convolution
  • Data Augmentation (Transformations)
    • Noise Addition
    • Rotation
    • Random Segmentation Crop
    • Resize
  • Models
    • AlexNet
    • VGGNet
    • ResNet
    • ShuffleNet
    • SqueezeNet
    • XNORNet
  • Training
    • Data level Parallelization
    • Multi Scale Training
    • Hyperparameter Training


NiftyTorch can be installed using:

pip install niftytorch==0.1.1 --extra-index-url=https://pypi.org/simple/

If you encounter problem, check dependencies. NiftyTorch requires torch==1.4.0, torchvision==0.5.0 and optuna==1.4.0. We also noted in some machines latest Numpy generates error (if so, change to an older version, such as numpy-1.16.4 using pip install numpy==1.16.4). For a complete demo on how to set up the requirement and getting started see Getting Started notebook in the Demo folder.


  • For Tutorials and Demos, please visit Demo Repository. For Documentation, please visit niftytorch.github.io.
  • For Announcements and News, follow us on Twitter @NiftyTorch.
  • For Please submit your questions and suggestions via niftytorch @ gmail.com. We appreciate your constructive inputs.


Adithya Subramanian and Farshid Sepehrband
INI Microstructural imaging Group (IMG)
Mark and Mary Stevens Neuroimaging and Informatics Institute (INI)
Keck School of Medicine of USC

Other Contributors

Sankareswari Govindarajan and Haoyu Lan
INI Microstructural imaging Group (IMG)


NiftyTorch would not be possible without liberal imports of the excellent pytorch, torchvision, nipy, numpy, pandas, matplotlib and optuna libraries.