research-contributions icon indicating copy to clipboard operation
research-contributions copied to clipboard

RuntimeError: applying transform <monai.transforms.io.dictionary.LoadImaged object at 0x7f0f84fb8a90>

Open SiruLiu645 opened this issue 2 years ago • 7 comments

截屏2023-10-02 20 32 32 could you please help me to save this problem?

SiruLiu645 avatar Oct 02 '23 12:10 SiruLiu645

That's been addressed earlier https://github.com/Project-MONAI/MONAI/issues/5603 please upgrade monai or downgrade itk...

wyli avatar Oct 02 '23 12:10 wyli

have you solved this problem?Can you tell me the solution

ASCI02 avatar Mar 27 '24 16:03 ASCI02

I am having the same issue.. Did you find the solution?

DJ-CHB avatar Apr 08 '24 10:04 DJ-CHB

I am having the same issue.. Did you find the solution?

Yes, you can fix this by reinstalling monai with "pip install 'monai[all]==1.1.0'"

ASCI02 avatar Apr 08 '24 12:04 ASCI02

I am trying to run on the BRATS-21 dataset.

python3 main.py --json_list=./jsons/brats21_folds.json --data_dir=./BRATS-2021/ --max_epochs=300 --val_every=5 --noamp --distributed --roi_x=128 --roi_y=128 --roi_z=128 --in_channels=4 --spatial_dims=3 --use_checkpoint --feature_size=48 --fold=0

Original Traceback (most recent call last):
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/transforms/transform.py", line 141, in apply_transform
    return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats)
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/transforms/transform.py", line 98, in _apply_transform
    return transform(data, lazy=lazy) if isinstance(transform, LazyTrait) else transform(data)
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/transforms/io/dictionary.py", line 162, in __call__
    data = self._loader(d[key], reader)
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/transforms/io/array.py", line 282, in __call__
    img_array, meta_data = reader.get_data(img)
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/data/image_reader.py", line 938, in get_data
    data = self._get_array_data(i)
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/data/image_reader.py", line 1012, in _get_array_data
    return np.asanyarray(img.dataobj, order="C")
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/nibabel/arrayproxy.py", line 391, in __array__
    arr = self._get_scaled(dtype=dtype, slicer=())
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/nibabel/arrayproxy.py", line 358, in _get_scaled
    scaled = apply_read_scaling(self._get_unscaled(slicer=slicer), scl_slope, scl_inter)
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/nibabel/arrayproxy.py", line 332, in _get_unscaled
    return array_from_file(self._shape,
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/nibabel/volumeutils.py", line 523, in array_from_file
    n_read = infile.readinto(data_bytes)
  File "/soft/AIDL/conda_envs/pytorch-200/lib/python3.10/gzip.py", line 301, in read
    return self._buffer.read(size)
  File "/soft/AIDL/conda_envs/pytorch-200/lib/python3.10/_compression.py", line 68, in readinto
    data = self.read(len(byte_view))
  File "/soft/AIDL/conda_envs/pytorch-200/lib/python3.10/gzip.py", line 479, in read
    self._read_eof()
  File "/soft/AIDL/conda_envs/pytorch-200/lib/python3.10/gzip.py", line 525, in _read_eof
    raise BadGzipFile("CRC check failed %s != %s" % (hex(crc32),
gzip.BadGzipFile: CRC check failed 0xe9a51edc != 0x4190aef7

The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/transforms/transform.py", line 141, in apply_transform
    return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats)
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/transforms/transform.py", line 98, in _apply_transform
    return transform(data, lazy=lazy) if isinstance(transform, LazyTrait) else transform(data)
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/transforms/compose.py", line 335, in __call__
    result = execute_compose(
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/transforms/compose.py", line 111, in execute_compose
    data = apply_transform(
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/transforms/transform.py", line 171, in apply_transform
    raise RuntimeError(f"applying transform {transform}") from e
RuntimeError: applying transform <monai.transforms.io.dictionary.LoadImaged object at 0x145fb63fbc40>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/torch/utils/data/_utils/worker.py", line 302, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 58, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 58, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/data/dataset.py", line 112, in __getitem__
    return self._transform(index)
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/data/dataset.py", line 98, in _transform
    return apply_transform(self.transform, data_i) if self.transform is not None else data_i
  File "/home/2022022/djain02/packages/lib/python3.10/site-packages/monai/transforms/transform.py", line 171, in apply_transform
    raise RuntimeError(f"applying transform {transform}") from e
RuntimeError: applying transform <monai.transforms.compose.Compose object at 0x145fb641c400>

I am getting this error even with monai 1.1.0 and 1.3.0

DJ-CHB avatar Apr 08 '24 15:04 DJ-CHB

As in my case it gave the suggestion to visit this website: https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies

As the error was due to monai not installing necessary libraries like ITK,etc... to load the images... So, this does help: pip install 'monai[all]==1.1.0'

one2clouds avatar Apr 22 '24 11:04 one2clouds

It can resolved if you install numpy. version 1.21.6 with the monai version suggested in the requirement.txt I am working on this with brats dataset but I am wondering why my dice score is too low..... can one able to regenerate the results?

AbdulRehman0004 avatar Feb 07 '25 18:02 AbdulRehman0004