project-monai / slicermonaiviz Goto Github PK
View Code? Open in Web Editor NEWMONAIViz - 3D Slicer Extension
License: Apache License 2.0
MONAIViz - 3D Slicer Extension
License: Apache License 2.0
yaml seems to be needed for most bundles, but neither MONAI nor the bundles install it.
It should be probably added as a dependency of MONAI or the bundles that require it, but as a workaround it could be added to the installation instructions.
After installing the extension and running it for the first time, monai
python package is not installed.
The following two methods do not exist:
SlicerMONAIViz/MONAIViz/MONAIViz.py
Line 842 in 9dd9dc2
Hi,
great tool so far! I am trying to apply a Lambdad
function in my transform chain.
For example, after LoadImaged
I want to apply the transform:
Lambdad(keys=["image"], func=lambda x: x.squeeze())
If I add the Lambdad transform in my stack in the MONAIViz panel, and I add the params keys=["image"]
and func=lambda x: x.squeeze()
, I receive the following error message:
Traceback (most recent call last):
File "C:/Projects/SlicerMONAIViz/MONAIViz/MONAIViz.py", line 537, in onRunTransform
t = eval(exp)
File "<string>", line 1
monai.transforms.Lambdad(keys=['image'], func=<function <lambda> at 0x0000017BD75F3280>)
^
SyntaxError: invalid syntax
I am not sure what's happening under the hood in this module - would a lambda eval even be possible?
Thanks in advance!
transformation
train_transforms = Compose(
[
LoadImaged(keys=["image", "label"]),
EnsureChannelFirstd(keys=["image", "label"]),
ScaleIntensityRanged(
keys=["image"],
a_min=-1024.0,
a_max=1906.0,
b_min=0.0,
b_max=1.0,
clip=True,
),
Spacingd(keys=["image", "label"], pixdim=(1.5, 1.5, 2.0), mode=("bilinear", "nearest")),
Orientationd(keys=["image", "label"], axcodes="RAS"),
Resized(keys=["image", "label"],spatial_size = (240,240,128)),
DivisiblePadd(keys=["image", "label"], k = 64),
RandCropByPosNegLabeld(
keys=["image", "label"],
label_key="label",
spatial_size=(96, 96, 96),
pos=1,
neg=1,
num_samples=4,
image_key="image",
image_threshold=0 ) ])
val_transforms = Compose(
[
LoadImaged(keys=["image", "label"]),
EnsureChannelFirstd(keys=["image", "label"]),
ScaleIntensityRanged(
keys=["image"],
a_min=-1024.0,
a_max=1906.0,
b_min=0.0,
b_max=1.0,
clip=True),
#CropForegroundd(keys=["image", "label"], source_key="image"),
Orientationd(keys=["image", "label"], axcodes="RAS"),
Spacingd(keys=["image", "label"], pixdim=(1.5, 1.5, 2.0), mode=("bilinear", "nearest")),
Resized(keys=["image", "label"],spatial_size = (240,240,128)),
DivisiblePadd(keys=["image", "label"],k = 64)])
data shape from loader
data = first(train_loader)
data['image'].shape , data['label'].shape
(torch.Size([4, 1, 96, 96, 96]), torch.Size([4, 1, 96, 96, 96]))
Model:
model = UNet(
spatial_dims=3,
in_channels=1,
out_channels=3,
channels=(16, 32, 64, 128, 256),
strides=(2, 2, 2, 2),
num_res_units=2,
norm=Norm.BATCH,
).to(device)
----------
epoch 1/100
epoch 1 average loss: 0.7484
----------
epoch 2/100
epoch 2 average loss: 0.7053
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1629,0,0], thread: [64,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1629,0,0], thread: [68,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1629,0,0], thread: [72,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1312,0,0], thread: [65,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1630,0,0], thread: [64,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1630,0,0], thread: [68,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1630,0,0], thread: [72,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1630,0,0], thread: [76,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1762,0,0], thread: [65,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1762,0,0], thread: [69,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1762,0,0], thread: [71,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1762,0,0], thread: [73,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1762,0,0], thread: [77,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1762,0,0], thread: [81,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1628,0,0], thread: [64,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1628,0,0], thread: [67,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1628,0,0], thread: [68,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1628,0,0], thread: [71,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1628,0,0], thread: [72,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1761,0,0], thread: [29,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1628,0,0], thread: [56,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1628,0,0], thread: [59,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1628,0,0], thread: [60,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1312,0,0], thread: [50,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1312,0,0], thread: [54,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1312,0,0], thread: [58,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1312,0,0], thread: [62,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1630,0,0], thread: [52,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1630,0,0], thread: [56,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1630,0,0], thread: [60,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1761,0,0], thread: [65,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1761,0,0], thread: [69,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1761,0,0], thread: [71,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1761,0,0], thread: [73,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1761,0,0], thread: [77,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1895,0,0], thread: [64,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1894,0,0], thread: [64,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1894,0,0], thread: [68,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1894,0,0], thread: [72,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2018,0,0], thread: [65,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2018,0,0], thread: [67,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2018,0,0], thread: [69,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2018,0,0], thread: [71,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2018,0,0], thread: [73,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2018,0,0], thread: [75,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2018,0,0], thread: [77,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2018,0,0], thread: [81,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2018,0,0], thread: [85,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [1894,0,0], thread: [60,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2021,0,0], thread: [49,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2021,0,0], thread: [53,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2021,0,0], thread: [57,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2021,0,0], thread: [61,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2017,0,0], thread: [45,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2017,0,0], thread: [49,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2017,0,0], thread: [53,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2017,0,0], thread: [55,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2017,0,0], thread: [57,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2017,0,0], thread: [59,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2017,0,0], thread: [61,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
/usr/local/src/pytorch/aten/src/ATen/native/cuda/ScatterGatherKernel.cu:365: operator(): block: [2017,0,0], thread: [63,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
File <timed exec>:48
File /opt/conda/lib/python3.10/site-packages/monai/metrics/metric.py:344, in CumulativeIterationMetric.__call__(self, y_pred, y, **kwargs)
324 def __call__(
325 self, y_pred: TensorOrList, y: TensorOrList | None = None, **kwargs: Any
326 ) -> torch.Tensor | Sequence[torch.Tensor | Sequence[torch.Tensor]]:
327 """
328 Execute basic computation for model prediction and ground truth.
329 It can support both `list of channel-first Tensor` and `batch-first Tensor`.
(...)
342 a `batch-first` tensor (BC[HWD]) or a list of `batch-first` tensors.
343 """
--> 344 ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
345 if isinstance(ret, (tuple, list)):
346 self.extend(*ret)
File /opt/conda/lib/python3.10/site-packages/monai/metrics/metric.py:73, in IterationMetric.__call__(self, y_pred, y, **kwargs)
71 # handling a list of channel-first data
72 if isinstance(y_pred, (list, tuple)) or isinstance(y, (list, tuple)):
---> 73 return self._compute_list(y_pred, y, **kwargs)
74 # handling a single batch-first data
75 if isinstance(y_pred, torch.Tensor):
File /opt/conda/lib/python3.10/site-packages/monai/metrics/metric.py:97, in IterationMetric._compute_list(self, y_pred, y, **kwargs)
83 """
84 Execute the metric computation for `y_pred` and `y` in a list of "channel-first" tensors.
85
(...)
94 Note: subclass may enhance the operation to have multi-thread support.
95 """
96 if y is not None:
---> 97 ret = [
98 self._compute_tensor(p.detach().unsqueeze(0), y_.detach().unsqueeze(0), **kwargs)
99 for p, y_ in zip(y_pred, y)
100 ]
101 else:
102 ret = [self._compute_tensor(p_.detach().unsqueeze(0), None, **kwargs) for p_ in y_pred]
File /opt/conda/lib/python3.10/site-packages/monai/metrics/metric.py:98, in <listcomp>(.0)
83 """
84 Execute the metric computation for `y_pred` and `y` in a list of "channel-first" tensors.
85
(...)
94 Note: subclass may enhance the operation to have multi-thread support.
95 """
96 if y is not None:
97 ret = [
---> 98 self._compute_tensor(p.detach().unsqueeze(0), y_.detach().unsqueeze(0), **kwargs)
99 for p, y_ in zip(y_pred, y)
100 ]
101 else:
102 ret = [self._compute_tensor(p_.detach().unsqueeze(0), None, **kwargs) for p_ in y_pred]
File /opt/conda/lib/python3.10/site-packages/monai/metrics/meandice.py:95, in DiceMetric._compute_tensor(self, y_pred, y)
93 raise ValueError(f"y_pred should have at least 3 dimensions (batch, channel, spatial), got {dims}.")
94 # compute dice (BxC) for each channel for each batch
---> 95 return self.dice_helper(y_pred=y_pred, y=y)
File /opt/conda/lib/python3.10/site-packages/monai/metrics/meandice.py:260, in DiceHelper.__call__(self, y_pred, y)
258 x_pred = (y_pred[b, 0] == c) if (y_pred.shape[1] == 1) else y_pred[b, c].bool()
259 x = (y[b, 0] == c) if (y.shape[1] == 1) else y[b, c]
--> 260 c_list.append(self.compute_channel(x_pred, x))
261 data.append(torch.stack(c_list))
262 data = torch.stack(data, dim=0).contiguous() # type: ignore
File /opt/conda/lib/python3.10/site-packages/monai/metrics/meandice.py:219, in DiceHelper.compute_channel(self, y_pred, y)
217 """"""
218 y_o = torch.sum(y)
--> 219 if y_o > 0:
220 return (2.0 * torch.sum(torch.masked_select(y, y_pred))) / (y_o + torch.sum(y_pred))
221 if self.ignore_empty:
File /opt/conda/lib/python3.10/site-packages/monai/data/meta_tensor.py:282, in MetaTensor.__torch_function__(cls, func, types, args, kwargs)
280 if kwargs is None:
281 kwargs = {}
--> 282 ret = super().__torch_function__(func, types, args, kwargs)
283 # if `out` has been used as argument, metadata is not copied, nothing to do.
284 # if "out" in kwargs:
285 # return ret
286 if _not_requiring_metadata(ret):
File /opt/conda/lib/python3.10/site-packages/torch/_tensor.py:1295, in Tensor.__torch_function__(cls, func, types, args, kwargs)
1292 return NotImplemented
1294 with _C.DisableTorchFunctionSubclass():
-> 1295 ret = func(*args, **kwargs)
1296 if func in get_default_nowrap_functions():
1297 return ret
RuntimeError: CUDA error: device-side assert triggered
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.
good day,
tensor size for image , label checked from train dataloader just before the training
data = first(train_loader)
data['image'][6].shape , data['label'][6].shape
(torch.Size([1, 90, 90, 40]), torch.Size([1, 90, 90, 40]))
Model:
device = torch.device("cuda")
model = UNet(
spatial_dims=3,
in_channels=1,
out_channels=3,
channels=(16, 32, 64, 128, 256),
strides=(2, 2, 2, 2),
num_res_units=2,
norm=Norm.BATCH,
).to(device)
Error:
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 5 but got size 6 for tensor number 1 in the list.
any ideas on what to check? and what are the 5 and 6 dimensions?
Note: labels have background + 2 colors not 1
Thanks
Since we will be releasing Slicer 5.4 this week, we could probably change this to `version 5.4 or higher`
Originally posted by @jcfr in #23 (comment)
while making exact transformations for training and val data the output dims are different and I'm interested to know how.
#setting piplines for train and validation
train_transforms = Compose(
[
LoadImaged(keys=["image", "label"]),
EnsureChannelFirstd(keys=["image", "label"]),
ScaleIntensityRanged(
keys=["image"],
a_min=-1024.0,
a_max=1906.0,
b_min=0.0,
b_max=1.0,
clip=True,
),
Resized(keys=["image", "label"],spatial_size = (240,240,120)),
CropForegroundd(keys=["image", "label"], source_key="image"),
DivisiblePadd(keys=["image", "label"], k = 16),
Orientationd(keys=["image", "label"], axcodes="RAS"),
Spacingd(keys=["image", "label"], pixdim=(1.5, 1.5, 2.0), mode=("bilinear", "nearest")),
RandCropByPosNegLabeld(
keys=["image", "label"],
label_key="label",
spatial_size=(96, 96, 96),
pos=1,
neg=1,
num_samples=4,
image_key="image",
allow_smaller = True,
image_threshold=0)])
val_transforms = Compose(
[
LoadImaged(keys=["image", "label"]),
EnsureChannelFirstd(keys=["image", "label"]),
ScaleIntensityRanged(
keys=["image"],
a_min=-1024.0,
a_max=1906.0,
b_min=0.0,
b_max=1.0,
clip=True),
Resized(keys=["image", "label"],spatial_size = (240,240,120)),
CropForegroundd(keys=["image", "label"], source_key="image"),
DivisiblePadd(keys=["image", "label"], k = 16),
Orientationd(keys=["image", "label"], axcodes="RAS"),
Spacingd(keys=["image", "label"], pixdim=(1.5, 1.5, 2.0), mode=("bilinear", "nearest"))])
original dims: (512, 512, 37)
train_loder output : ([313, 313, 131])
val_loader output: ([242, 242, 116])
roi = (96,96,96)
error message:
MONAI hint: if your transforms intentionally create images of different shapes, creating your `DataLoader` with `collate_fn=pad_list_data_collate` might solve this problem (check its documentation).
what are recommendations for handling such dimensions (512, 512, 33)?
the plugin currently requires an image path
SlicerMONAIViz/MONAIViz/MONAIViz.py
Lines 501 to 503 in 9cbb50b
LoadImageD
.
would be great to remove this requirement and the user can apply transforms to a volume node that is already in a scene.
I was able to install it on Linux, but when trying to edit transform, I am getting the following error:
Selected Transform for Edit: 0
Traceback (most recent call last):
File "/home/herzc/Slicer-5.4.0-linux-amd64/slicer.org/Extensions-31938/MONAIViz/lib/Slicer-5.4/qt-scripted-modules/MONAIViz.py", line 398, in onEditTransform
with open(doc_html, "wb", encoding="utf-8") as fp:
ValueError: binary mode doesn't take an encoding argument
This piece of code:
SlicerMONAIViz/MONAIViz/MONAIViz.py
Lines 440 to 445 in 27c6fa8
I´m trying to add TR to review my training workflow but I can´t edit arguments.
TR´s in monai.transforms have no default arguments (empty) and all others are not editable.
Slicer 5.6.2
Windows
Selected Transform for Edit: False Traceback (most recent call last): File "C:/Users/_____/AppData/Local/slicer.org/Slicer 5.6.2/slicer.org/Extensions-32448/MONAIViz/lib/Slicer-5.6/qt-scripted-modules/MONAIViz.py", line 398, in onEditTransform with open(doc_html, "wb", encoding="utf-8") as fp: ValueError: binary mode doesn't take an encoding argument
Thanks
Instead of asking the user to install MONAI manually, we should display a confirmation popup: OK to install MONAI or cancel to install it manually.
After installing dependencies with MONAIVizLogic.installMONAI()
and then importing monai, I am getting the following errors.
>>> import monai
Traceback (most recent call last):
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/utils/module.py", line 210, in load_submodules
mod = import_module(name)
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/apps/__init__.py", line 15, in <module>
from .mmars import MODEL_DESC, RemoteMMARKeys, download_mmar, get_model_spec, load_from_mmar
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/apps/mmars/__init__.py", line 14, in <module>
from .mmars import download_mmar, get_model_spec, load_from_mmar
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/apps/mmars/mmars.py", line 29, in <module>
import monai.networks.nets as monai_nets
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/networks/nets/__init__.py", line 101, in <module>
from .swin_unetr import PatchMerging, PatchMergingV2, SwinUNETR
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/networks/nets/swin_unetr.py", line 21, in <module>
import torch.utils.checkpoint as checkpoint
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/torch/utils/checkpoint.py", line 18, in <module>
from torch.testing._internal.logging_tensor import LoggingTensorMode, capture_logs
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/torch/testing/_internal/logging_tensor.py", line 2, in <module>
from torch.utils._pytree import tree_map
ImportError: cannot import name 'tree_map' from 'torch.utils._pytree' (/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/torch/utils/_pytree.py)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/__init__.py", line 58, in <module>
load_submodules(sys.modules[__name__], False, exclude_pattern=excludes)
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/utils/module.py", line 220, in load_submodules
raise type(e)(f"{e}\n{msg}").with_traceback(e.__traceback__) from e # raise with modified message
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/utils/module.py", line 210, in load_submodules
mod = import_module(name)
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/apps/__init__.py", line 15, in <module>
from .mmars import MODEL_DESC, RemoteMMARKeys, download_mmar, get_model_spec, load_from_mmar
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/apps/mmars/__init__.py", line 14, in <module>
from .mmars import download_mmar, get_model_spec, load_from_mmar
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/apps/mmars/mmars.py", line 29, in <module>
import monai.networks.nets as monai_nets
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/networks/nets/__init__.py", line 101, in <module>
from .swin_unetr import PatchMerging, PatchMergingV2, SwinUNETR
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/monai/networks/nets/swin_unetr.py", line 21, in <module>
import torch.utils.checkpoint as checkpoint
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/torch/utils/checkpoint.py", line 18, in <module>
from torch.testing._internal.logging_tensor import LoggingTensorMode, capture_logs
File "/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/torch/testing/_internal/logging_tensor.py", line 2, in <module>
from torch.utils._pytree import tree_map
ImportError: cannot import name 'tree_map' from 'torch.utils._pytree' (/Applications/Slicer-5.4.0_stable.app/Contents/lib/Python/lib/python3.9/site-packages/torch/utils/_pytree.py)
Multiple versions of MONAI may have been installed?
Please see the installation guide: https://docs.monai.io/en/stable/installation.html
[DEBUG][Qt] 12.10.2023 11:07:20 [] (unknown:0) - Session start time .......: 2023-10-12 11:07:20
[DEBUG][Qt] 12.10.2023 11:07:20 [] (unknown:0) - Slicer version ...........: 5.4.0 (revision 31938 / 311cb26) macosx-amd64 - installed release
[DEBUG][Qt] 12.10.2023 11:07:21 [] (unknown:0) - Operating system .........: macOS / 13.5 / 22G74 / UTF-8 - 64-bit
[DEBUG][Qt] 12.10.2023 11:07:21 [] (unknown:0) - Memory ...................: 65536 MB physical, 0 MB virtual
[DEBUG][Qt] 12.10.2023 11:07:21 [] (unknown:0) - CPU ......................: Apple M2 Max, 12 cores, 12 logical processors
[DEBUG][Qt] 12.10.2023 11:07:21 [] (unknown:0) - VTK configuration ........: OpenGL2 rendering, Sequential threading
[DEBUG][Qt] 12.10.2023 11:07:21 [] (unknown:0) - Qt configuration .........: version 5.15.8, with SSL, requested OpenGL 3.2 (core profile)
[DEBUG][Qt] 12.10.2023 11:07:21 [] (unknown:0) - Internationalization .....: disabled, language=
[DEBUG][Qt] 12.10.2023 11:07:21 [] (unknown:0) - Developer mode ...........: enabled
[DEBUG][Qt] 12.10.2023 11:07:21 [] (unknown:0) - Application path .........: /Applications/Slicer-5.4.0_stable.app/Contents/MacOS
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.