MR spectral quantification using convoloutional neural networks.
This framework provides methods to generate datasets from loaded LCModel ".BASIS" files or simulated by FID-A or PyGamma.
- Keras - The Deep Learning framework used
- Tensorflow - Underlying Machine Learning library
- FID-A - MRS simulation toolbox
- PyGamma - Another MRS simulation toolbox
- VeSPA - Versatile Simulation, Pulses and Analysis
- Swansea Benchmark Dataset - Benchmark phantom datasets collected at Swansea University's 3T Siemens scanner.
- Purdue LCModel basis sets - Data source for the LCModel basis sets
- Python 2.7 - Unfortunately, PyGamma still requires Python 2.7 to run so the entire library is written in Python 2.7
- MATLAB - Only required if you plan to simulate new FID-A spectra.
- Linux system packages:
- Git-lfs for git submodule support:
git-lfs
- Python2 virtual environment to isolate installation packages and environment:
python-virtualenv
- Git-lfs for git submodule support:
- Install these using your package manager with root privileges. E.g. Debian based distributions:
sudo apt update && sudo apt install git-lfs python-virtualenv
For simplicity, python packages are installed into a virtual environment.
- Clone the repository:
git clone https://qyber.black/MRIS/mrsnet.git
- Navigate to the directory:
cd mrsnet
- Update submodules:
git submodule init && git submodule update
- Create a virtual environment 'venv':
python2 -m virtualenv venv
- Activate the virtual environment:
source venv/bin/activate
- Install the requirements (CPU or GPU):
- Download the additional required data:
python2 setup.py
Training a network is the default for model.py:
python2 model.py
To see a list of options and their defaults, call:
python2 model.py --help
An example of a more complex training call:
python2 model.py -N 10000 -e 200 -b 16 -d fida --linewidths 0.75 1 1.25 --omega 900 --model_name mrsnet_small_kernel_no_pool
This above example will simulate spectra and train a network with:
- Train for 200 epochs, with a mini-batch size of 16
- Spectra are sourced from FID-A, with a scanner B0 field of 900MHz
- 10,000 Spectra are evenly split (3,333) over the linewidths (0.75, 1, 1.25)
- For the network architecture called "mrsnet_small_kernel_no_pool" (found in networks.py)
By default, networks are stored in MRSNet/models/
along with some basic analytics.
Quantifying spectra:
python2 model.py -m quantify
Defaults are to use the E1 MEGA-PRESS benchmark spectra, with the best network from MRSNet. Output will
Quantifying spectra and specifying the model and spectra directory:
python2 model.py -m quantify --network_path "models/complete/some_model_dir/" --spectra_path "some/spectra/directory/"
The default behaviour of quantify is to use the best network from the MRSNet paper to quantify the bundled E3 dataset:
Quantifying 13 MEGA-PRESS Spectra
This network can only quantify: ['creatine', 'gaba', 'glutamate', 'glutamine', 'n-acetylaspartate']
Network path: ./models/complete/MRSNet/
DICOM path: ./Datasets/Benchmark/E1/MEGA-PRESS/1250Hz/
Spectra ID: GABA_SERIES_00P5MM
Metabolite Quantity
Creatine 0.077157
GABA 0.556846
Glutamate 0.114418
Glutamine 0.203197
N-Acetylaspartate 0.048382
The code will attempt to analyse all of the spectra contained in the provided directory. There are a couple of caveats to enable this to work correctly:
- All three acquisitions for each MEGA-PRESS scan must be present (edit on, edit off, difference).
- Spectra that belong to the same scan must have a unique ID of your choise added to their filename (e.g. SCAN_001).
- If you know the ground truth of the scan, it should be added to the dictionary located in Utilities/constants.py. This enables the code to know which spectra are from the same scans to group them together.
- Spectra of the different acquisition types must be labeled, by adding either "EDIT_OFF", "EDIT_ON" or "DIFF" to anywhere after the unique ID from 2 in their filename.
An example for two MEGA-PRESS scan would be six files:
"SCAN_000_EDIT_OFF.ima"
"SCAN_000_EDIT_ON.ima"
"SCAN_000_DIFF.ima"
"SCAN_001_EDIT_OFF.ima"
"SCAN_001_EDIT_ON.ima"
"SCAN_001_DIFF.ima"
Loading of non-Siemens DICOM files has not been tested.
We use SemVer for versioning. For the versions available, see the tags on this repository.
The code is developed and maintained on qyber\black at https://qyber.black/mrs/code-mrsnet
This code is mirrored at
The mirrors are only for convenience, accessibility and backup.
- Max Chandler, School of Computer Science and Informatics, Cardiff University
- Frank C Langbein, School of Computer Science and Informatics, Cardiff University; langbein.org
- Sophie M Shermer, Physics, Swansea University
- Christopher W Jenkins, Physics and Centre for Nanohealth and Clinical Imaging Unit, Swansea University; Cardiff University Brain Research Imaging Centre (CUBRIC)
- Brian Soher (VeSPA/PyGamma) for help locating the PyGamma pulse sequence code for MEGA-PRESS, PRESS and STEAM.
For any general enquiries relating to this project, send an e-mail.
M Chandler, C Jenkins, SM Shermer, FC Langbein. Code - MRSNet. Version 1.0. FigShare, Softrware, 16th August 2019. [10.6084/m9.figshare.9824417.v1] [DEV:https://qyber.black/mrs/code-mrsnet] [MIRROR:https://github.com/MaxChandler/MRSNet]
Copyright (C) 2019, M Chandler.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.