fepegar / slicertorchio Goto Github PK
View Code? Open in Web Editor NEW3D Slicer module for TorchIO.
License: Other
3D Slicer module for TorchIO.
License: Other
๐ Feature
Add all the transforms of torchio to Slicer.
Motivation
Slicer is very useful for testing/visualization.
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.
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, usingscales=(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.
๐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
๐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
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๏ผ
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.
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?
This will probably be solved by changing the link to the repository in https://github.com/Slicer/ExtensionsIndex/blob/master/TorchIO.s4ext, using the link for HTTPS instead of SSH.
๐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?
SlicerTorchIO/TorchIOTransforms/TorchIOTransforms.py
Lines 242 to 245 in 6cac093
======================================================================
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.