GithubHelp home page GithubHelp logo

slicertorchio's Introduction

TorchIO logo

Tools like TorchIO are a symptom of the maturation of medical AI research using deep learning techniques.

Jack Clark, Policy Director at OpenAI (link).


This repository contains the code for a 3D Slicer extension that can be used to experiment with the TorchIO Python package without any coding.

More information on the extension can be found on the TorchIO documentation.

Please use the Preview Release of 3D Slicer.

Original Random blur
Original Random blur
Random flip Random noise
Random flip Random noise
Random affine transformation Random elastic transformation
Random affine transformation Random elastic transformation
Random bias field artifact Random motion artifact
Random bias field artifact Random motion artifact
Random spike artifact Random ghosting artifact
Random spike artifact Random ghosting artifact

Installation

The extension can be installed using Extensions Manager.

Continuous integration

The build status can be checked on CDash.

Credits

If you like this repository, please click on Star!

If you use this tool for your research, please cite our paper:

F. Pérez-García, R. Sparks, and S. Ourselin. TorchIO: a Python library for efficient loading, preprocessing, augmentation and patch-based sampling of medical images in deep learning. Computer Methods and Programs in Biomedicine (June 2021), p. 106236. ISSN: 0169-2607.doi:10.1016/j.cmpb.2021.106236.

BibTeX entry:

@article{perez-garcia_torchio_2021,
    title = {TorchIO: a Python library for efficient loading, preprocessing, augmentation and patch-based sampling of medical images in deep learning},
    journal = {Computer Methods and Programs in Biomedicine},
    pages = {106236},
    year = {2021},
    issn = {0169-2607},
    doi = {https://doi.org/10.1016/j.cmpb.2021.106236},
    url = {https://www.sciencedirect.com/science/article/pii/S0169260721003102},
    author = {P{\'e}rez-Garc{\'i}a, Fernando and Sparks, Rachel and Ourselin, S{\'e}bastien},
}

This project is supported by the following institutions:

slicertorchio's People

Contributors

che85 avatar fepegar avatar jcfr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

slicertorchio's Issues

Type error when converting to torch Tensor

Hi there, I'm running into an issue when applying any transform through your extension. I have posted version info and python console output below. Thanks

3DSlicer version: 4.11.20200930 r29402 / 002be18
Python version: 3.6.7

Slicer python output:

Transform kwargs:
{'num_control_points': (7, 7, 7), 'max_displacement': (7.5, 7.5, 7.5), 'locked_borders': 2, 'image_interpolation': 'linear'}
Transform args: {'scales': (0.8, 1.2000000000000002), 'degrees': (-10.0, 10.0), 'translation': (0.0, 0.0), 'isotropic': False, 'image_interpolation': 'linear', 'default_pad_value': 'minimum'}
TorchIO returned the error: Traceback (most recent call last):
File "C:/Users/BACLARK/AppData/Roaming/NA-MIC/Extensions-29402/TorchIO/lib/Slicer-4.11/qt-scripted-modules/TorchIOTransforms.py", line 201, in onApplyButton
outputImage = self.currentTransform(inputVolumeNode, outputVolumeNode)
File "C:\Users\BACLARK\AppData\Roaming\NA-MIC\Extensions-29402\TorchIO\lib\Slicer-4.11\qt-scripted-modules\TorchIOTransformsLib\Transform.py", line 118, in call
data, affine = torchio.io.sitk_to_nib(image)
File "C:\Users\BACLARK\AppData\Local\NA-MIC\Slicer 4.11.20200930\lib\Python\Lib\site-packages\torchio\data\io.py", line 285, in sitk_to_nib
data = ensure_4d(data, num_spatial_dims=input_spatial_dims)
File "C:\Users\BACLARK\AppData\Local\NA-MIC\Slicer 4.11.20200930\lib\Python\Lib\site-packages\torchio\data\io.py", line 313, in ensure_4d
tensor = torch.as_tensor(tensor)
TypeError: can't convert np.ndarray of type numpy.uint16. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.

AttributeError: 'Tensor' object has no attribute 'astype'

log :

TorchIO returned the error: Traceback (most recent call last):
File "/home/ubuntu/.config/NA-MIC/Extensions-29402/TorchIO/lib/Slicer-4.11/qt-scripted-modules/TorchIOTransforms.py", line 201, in onApplyButton
outputImage = self.currentTransform(inputVolumeNode, outputVolumeNode)
File "/home/ubuntu/.config/NA-MIC/Extensions-29402/TorchIO/lib/Slicer-4.11/qt-scripted-modules/TorchIOTransformsLib/Transform.py", line 119, in call
tensor = torch.from_numpy(data.astype(np.float32)) # why do I need this? Open a TorchIO issue?
AttributeError: 'Tensor' object has no attribute 'astype'

Transform kwargs:
{'scales': (1.79, 1.99), 'degrees': (-180.0, 180.0), 'translation': (14.5, 34.5), 'isotropic': True, 'image_interpolation': 'gaussian', 'default_pad_value': 'minimum'}

Can you help me?

Does not work with GPU-enabled PyTorch

🐛Bug
I pip-installed torch within Slicer's Python interpreter with parameters torch==1.9.0+cu102 torchvision==0.10.0+cu102 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html, the same way as I did in a regular install. Trying to switch to the TorchIOTransforms module results in a hang, followed by a crash.

To reproduce

Installed the extension, try to open it, click cancel on the "install Pytorch" prompt, install it manually as above, try to open the extension again, again click cancel and install torchio myself.

Expected behavior

When I try to switch to the module, the extension's GUI shows up.

Actual behavior

When I try to switch to the module, Slicer's GUI locks up, then after maybe 10-20 seconds exits without a message.

Slicer version

4.13.0-2021-06-28 r30015 / 1807944

Traceback in TorchIOTransforms testing due to missing attribute

🐛Bug
There doesn't appear to be a pipInstallTorch or pipInstallTorchIO in the TorchIOTransformsLogic class as discovered in factory build test https://slicer.cdash.org/test/19799012. @fepegar These were removed in ec1274a. There instead appears to be a installTorchIO available?

slicer.mrmlScene.Clear(0)
logic = TorchIOTransformsLogic()
logic.pipInstallTorch(showDialog=False)
logic.pipInstallTorchIO(showDialog=False)

======================================================================
ERROR: test_TorchIOTransforms (TorchIOTransforms.TorchIOTransformsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/work/Preview/S-0-E-b/TorchIO-build/lib/Slicer-4.13/qt-scripted-modules/TorchIOTransforms.py", line 244, in setUp
    logic.pipInstallTorch(showDialog=False)
AttributeError: 'TorchIOTransformsLogic' object has no attribute 'pipInstallTorch'

Slicer version

Slicer-4.13.0-2021-10-19

Can't find slicerrc.py

Thanks for sharing this work. After downloading 3D slicer on ubuntu 18, I could not find ~/.slicerrc.py to modify it. Can you please clarify how I can install this extension?

Thanks in advance.

Paths in README

I noticed the paths in the README are not up to date anymore

I had to change it to:

from pathlib import Path

modulePath = Path('~/git/SlicerTorchIO/TorchIOTransforms/TorchIOTransforms.py').expanduser()
moduleFactory = slicer.app.moduleManager().factoryManager()
moduleFactory.registerModule(qt.QFileInfo(str(modulePath)))
moduleFactory.loadModules([modulePath.stem])

Also I could not run this in using Slicer 4.10.2 because that version uses Python2. I downloaded Slicer 4.13.0, which uses Python3, but I get the following error:

Requirement already satisfied: six in ./lib/Python/lib/python3.6/site-packages (from packaging>=14.3->nibabel->torchio) (1.15.0)
TorchIO was installed successfully
Traceback (most recent call last):
  File "/home/derk/SlicerTorchIO/TorchIOTransforms/TorchIOTransforms.py", line 266, in checkTorchIO
    import torchio
  File "/home/derk/Downloads/Slicer-4.13.0-2020-11-25-linux-amd64/lib/Python/lib/python3.6/site-packages/torchio/__init__.py", line 11, in <module>
    from .transforms import *  # noqa: F401, F403
  File "/home/derk/Downloads/Slicer-4.13.0-2020-11-25-linux-amd64/lib/Python/lib/python3.6/site-packages/torchio/transforms/__init__.py", line 1, in <module>
    from .transform import Transform
  File "/home/derk/Downloads/Slicer-4.13.0-2020-11-25-linux-amd64/lib/Python/lib/python3.6/site-packages/torchio/transforms/transform.py", line 13, in <module>
    from ..data.subject import Subject
  File "/home/derk/Downloads/Slicer-4.13.0-2020-11-25-linux-amd64/lib/Python/lib/python3.6/site-packages/torchio/data/__init__.py", line 1, in <module>
    from .queue import Queue
  File "/home/derk/Downloads/Slicer-4.13.0-2020-11-25-linux-amd64/lib/Python/lib/python3.6/site-packages/torchio/data/queue.py", line 9, in <module>
    from .subject import Subject
  File "/home/derk/Downloads/Slicer-4.13.0-2020-11-25-linux-amd64/lib/Python/lib/python3.6/site-packages/torchio/data/subject.py", line 5, in <module>
    from .image import Image
  File "/home/derk/Downloads/Slicer-4.13.0-2020-11-25-linux-amd64/lib/Python/lib/python3.6/site-packages/torchio/data/image.py", line 8, in <module>
    from PIL import Image as ImagePIL
  File "/home/derk/Downloads/Slicer-4.13.0-2020-11-25-linux-amd64/lib/Python/lib/python3.6/site-packages/PIL/Image.py", line 94, in <module>
    from . import _imaging as core
ImportError: /home/derk/Downloads/Slicer-4.13.0-2020-11-25-linux-amd64/lib/Python/lib/python3.6/site-packages/PIL/_imaging.cpython-36m-x86_64-linux-gnu.so: ELF load command address/offset not properly aligned

Any ideas? Or should I use a different Slicer version?

Add missing transforms

🚀 Feature
Add all the transforms of torchio to Slicer.

Motivation
Slicer is very useful for testing/visualization.

Tooltips are truncated

Screen Shot 2020-06-21 at 13 20 49

Whereas the full docs say:

Tuple :math:(a, b) defining the scaling
magnitude. The scaling values along each dimension are
:math:(s_1, s_2, s_3), where :math:s_i \sim \mathcal{U}(a, b).
For example, using scales=(0.5, 0.5) will zoom out the image,
making the objects inside look twice as small while preserving
the physical size and position of the image.

Error loading torchio extension

🐛Bug
Error loading torchio extension

To reproduce

I installed slicer and installed torchio extension from the extension manager

Expected behavior

Torchio extension loads on starting slicer

Actual behavior

Torchio extension does not load on starting slicer

  File "<string>", line 1, in <module>
  File "/home/reasat/Slicer-4.11.20210226-linux-amd64/lib/Python/lib/python3.6/imp.py", line 170, in load_source
    module = _exec(spec, sys.modules[name])
  File "<frozen importlib._bootstrap>", line 618, in _exec
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/reasat/Slicer-4.11.20210226-linux-amd64/NA-MIC/Extensions-29738/TorchIO/lib/Slicer-4.11/qt-scripted-modules/TorchIOModule.py", line 15, in <module>
    import PyTorchUtils
ModuleNotFoundError: No module named 'PyTorchUtils'
loadSourceAsModule - Failed to load file "/home/reasat/Slicer-4.11.20210226-linux-amd64/NA-MIC/Extensions-29738/TorchIO/lib/Slicer-4.11/qt-scripted-modules/TorchIOModule.py"  as module "TorchIOModule" !
Fail to instantiate module  "TorchIOModule"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/reasat/Slicer-4.11.20210226-linux-amd64/lib/Python/lib/python3.6/imp.py", line 170, in load_source
    module = _exec(spec, sys.modules[name])
  File "<frozen importlib._bootstrap>", line 618, in _exec
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/reasat/Slicer-4.11.20210226-linux-amd64/NA-MIC/Extensions-29738/TorchIO/lib/Slicer-4.11/qt-scripted-modules/TorchIOTransforms.py", line 19, in <module>
    from TorchIOModule import TorchIOModuleLogic
ImportError: cannot import name 'TorchIOModuleLogic'
loadSourceAsModule - Failed to load file "/home/reasat/Slicer-4.11.20210226-linux-amd64/NA-MIC/Extensions-29738/TorchIO/lib/Slicer-4.11/qt-scripted-modules/TorchIOTransforms.py"  as module "TorchIOTransforms" !
Fail to instantiate module  "TorchIOTransforms"
The following modules failed to be instantiated:
   TorchIOModule
   TorchIOTransforms
Switch to module:  "Welcome"

Slicer version
4.11.20210226 r29738 / 7a593c8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.