Skip to main content

spectrai: a deep learning framework for spectral data.

Project description

spectrai

spectrai is an open-source deep learning framework designed to facilitate the training of neural networks on spectral data and enable comparison between different methods. Spectrai provides numerous built-in spectral data pre-processing and augmentation methods, neural networks for spectral data including spectral and spectral image denoising, spectral and spectral image classification, spectral image segmentation, and spectral image super-resolution.

Contents

  1. Introduction
  2. Examples
  3. Installation
  4. Usage
  5. Environment
  6. Citation

Introduction

Spectral acquisition and imaging play important roles across numerous fields such as machine vision, remote sensing, and biomedical imaging. While there is much potential for spectral deep learning applications, existing deep learning frameworks and models for computer vision are largely oriented towards RGB images. Spectral data differs substantially from RGB images, however, and poses numerous requirements for which standard neural network architectures, data augmentations, and hyperparameter defaults are often unsuitable. Application of existing deep learning models to spectral datasets thus requires careful modification and adaptation to make training on spectral data possible and effective. For example, while spectral augmentations (e.g., spectral flipping or shifting) may be applied, standard image augmentations (e.g., brightness or contrast changes) may introduce unwanted spectral distortions. Similarly, although 2D convolutional neural networks (CNNs) may be extended to multi-channel hyperspectral images, many spectral deep learning applications employ 1D or 3D CNNs, necessitating modification of existing 2D CNN architectures or the development of novel task-specific architectures. Lastly, the large size of spectral image hypercubes poses significant memory constraints which may require modification of network architectures and training hyperparameters (e.g., batch size, patch size, scaling, data augmentation) to enable effective single- or multi-GPU training.

We have thus developed spectrai, a deep learning framework designed specifically for spectral data. spectrai is built on the popular PyTorch library and includes baseline implementations of several networks for tasks including spectral calibration, spectral (image) classification, spectral denoising, spectral image segmentation, and spectral image super-resolution. In addition to a Python command line interface, spectrai provides a MATLAB graphical user interface (GUI) to guide non-expert users through deep learning training and inference procedures.

Figure_1 spectrai MATLAB GUI.

Examples

Spectral Image Segmentation

We demonstrate spectral image segmentation using the recently developed AeroRIT hyperspectral image dataset (dataset, paper).

Figure_2 AeroRIT Hyperspectral Image Semantic Segmentation.

Spectral Denoising

We demonstrate spectral denoising using a dataset of Raman spectra of MDA-MB-231 human breast cancer cells (dataset, paper).

Figure_3 Raman Spectral Denoising.

Spectral Image SuperResolution

We demonstrate spectral image super-resolution using the HELICoiD dataset of intraoperative hyperspectral images of human brains (dataset, paper).

Figure_4 HELICoiD Hyperspectral Image 8x Spatial Super-Resolution.

Installation

spectrai core

spectrai is hosted on the Python Package Index (PyPI). The latest version of spectrai can be installed using:

    >> pip install spectrai

*Note: this will not include the spectrai.mlapp MATLAB application

spectrai + MATLAB GUI

If you would like to use the spectrai MATLAB GUI, please follow the following steps:

Note that we provide the spectrai MATLAB GUI as an editable MATLAB application (.mlapp) to enable further open-source development. If desired, this can be exported to create an executable file. See here for details.

  1. Install MATLAB 2020b

  2. Install Python 3.8

    *Note: changes introduced in Python 3.9 are not compatible with MATLAB.

    *Note: MATLAB will not work with Anaconda Python distributions.

  3. In MATLAB, type the following to confirm the settings for MATLAB's Python interpreter (see here for details):

    >> pyenv
    
  4. Download spectrai.

  5. In MATLAB, navigate the working directory to:

    ~/spectrai/spectrai
    

Usage

spectrai core

spectrai can be run from the command line by typing:

  1. To train a model from scratch:
    >> spectrai_train
    
  2. To evaluate a pretrained model:
    >> spectrai_evaluate
    
  3. To apply a pretrained model to a dataset:
    >> spectrai_apply
    

The above commands will operate on a default config file provided in spectrai/spectrai/configs. To apply spectrai to new data, spectrai settings can be assigned in one of two ways:

  1. By default, settings are determined from .yml config files. Default config files are stored in spectrai/spectrai/configs. Users can develop custom config files, save them in the configs folder, and then specify them using the --config commandline flag, e.g.:
    >> spectrai_train --config custom_config.yml --verbose
    
  2. Alternatively, users can start from a default config file and modify individual settings via the commandline as required, e.g.:
    >> spectrai_train --activation PReLU --batch_size 16 --data_normalization "Max Value"
    

Suitable values for different parameters are listed in the default config files.

spectrai + MATLAB GUI

spectrai can alternatively be run from the MATLAB GUI. This GUI provides an easy-to-use interface that guides users through task selection, data loading, and data augmentation, as well as providing suggested initial default hyperparameter values. Additionally, the GUI provides visual feedback on losses and neural network outputs during training.

To run spectrai from the MATLAB GUI:

  1. Open MATLAB and navigate the working directory to:
    ~/spectrai/spectrai
    
  2. Type:
    >> appdesigner
    
  3. Open spectrai.mlapp
  4. Click Run (green play button on top menu bar)
  5. Starting at Training/Inference do the following:
    1. In Training/Inference, select a training/inference option
    2. In Deep Learning Task, select a deep learning option
      • Based on the option selected, unsuitable or irrelevant fields will be disabled (grayed out)
    3. In Data Manager:
      • Select a data format
      • Load input/target data as appropriate (by default assumes data is stored in a single directory as separate files unless the Data as Directory checkbox is unticked
      • Select shuffle data, if desired
      • Select split data and enter data splits, if desired
    4. In Training Hyperparameters, set training hyperparameters
    5. In Network Hyperparameters, set network hyperparameters
    6. In Data Augmentation, select any data augmentations desired
    7. In Preprocessing, set any data preprocessing required (example effects of preprocessing can be viewed by selecting Preview Spectra or Preview Images)
    8. Press Train, Evaluate, or Apply as appropriate

Environment

spectrai was implemented and tested in MATLAB R2020b and Python 3.8.8 using PyTorch 1.4.0 on a desktop computer with a Core i7-8700 CPU at 3.2 GHz (Intel), 32 GB of RAM, and a Titan V GPU (NVIDIA), running Windows 10 (Microsoft). spectrai has not yet been extensively tested in other environments (it's on our to do list).

Citation

If you find this code helpful in your work, please cite the following paper:

Conor C. Horgan and Mads S. Bergholt, "spectrai: a deep learning framework for spectral data", arXiv 2021, arXiv

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

spectrai-0.1.0.tar.gz (48.4 kB view details)

Uploaded Source

Built Distribution

spectrai-0.1.0-py3-none-any.whl (54.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spectrai-0.1.0.tar.gz
  • Upload date:
  • Size: 48.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.8

File hashes

Hashes for spectrai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ba15b0ad92acc99c9fd26db0f622a4c85f568a05112c8e6ead339ae84fc96c36
MD5 dfd066f6d89fcebd15e75e65299a5898
BLAKE2b-256 e926b15c31002852427b8286543b6c2879df3268f64138c0d40083bd7b469293

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spectrai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 54.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.8

File hashes

Hashes for spectrai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af0d7f80b169bac5cf053e7999919fd8d6f1860e647238c433a1363443dbe300
MD5 f697166fd5bd3cbddf2b37c145f8bc02
BLAKE2b-256 755dac2ff54a5dc0074c0749b756cbc3c92a59bff0f014b6c0ec1191e983fba9

See more details on using hashes here.

Supported by

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