InsightSoftwareConsortium / ITK

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.
https://itk.org
Apache License 2.0
1.4k stars 664 forks source link

Can't process LUNA16 data with .mhd format #3701

Open USTC-yzy1996 opened 1 year ago

USTC-yzy1996 commented 1 year ago

Hi, I met an error in "https://github.com/Project-MONAI/tutorials/tree/main/detection". I went with README.md and met an error when running code: python3 luna16_prepare_env_files.py python3 luna16_prepare_images.py -c ./config/config_train_luna1616g.json The error shows that the MONAI reader can not process files with .mhd format. Please check out this bug. Thanks a lot! ^^

github-actions[bot] commented 1 year ago

Thank you for contributing an issue!

Welcome to the ITK community!

We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. Also, please check existing open issues and consider discussion on the ITK Discourse.

dzenanz commented 1 year ago

Do you mind providing the text of the error message? An attempt to reproduce this error entails downloading this dataset.

USTC-yzy1996 commented 1 year ago

Sure, the error messages are as follows: MONAI version: 1.0.0 Numpy version: 1.17.2+intel.0 Pytorch version: 1.7.0 MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False MONAI rev id: 170093375ce29267e45681fcec09dfa856e1d7e7 MONAI file: /home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/init.py

Optional dependencies: Pytorch Ignite version: NOT INSTALLED or UNKNOWN VERSION. Nibabel version: 3.1.1 scikit-image version: 0.15.0 Pillow version: 6.2.0 Tensorboard version: 1.14.0 gdown version: NOT INSTALLED or UNKNOWN VERSION. TorchVision version: NOT INSTALLED or UNKNOWN VERSION. tqdm version: 4.36.1 lmdb version: NOT INSTALLED or UNKNOWN VERSION. psutil version: 5.6.3 pandas version: 0.25.1 einops version: 0.3.0 transformers version: NOT INSTALLED or UNKNOWN VERSION. mlflow version: NOT INSTALLED or UNKNOWN VERSION. pynrrd version: NOT INSTALLED or UNKNOWN VERSION.

For details about installing the optional dependencies, please visit: https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies

/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/io/array.py:192: UserWarning: required package for reader itkreader is not installed, or the version doesn't match requirement. f"required package for reader {_r} is not installed, or the version doesn't match requirement."

534 2022-10-22 14:57:53,095 - NibabelReader: unable to load ('/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.250397690690072950000431855143.mhd',).

2022-10-22 14:57:53,095 - PILReader: unable to load ('/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.250397690690072950000431855143.mhd',).

2022-10-22 14:57:53,095 - NumpyReader: unable to load ('/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.250397690690072950000431855143.mhd',).

2022-10-22 14:57:53,096 - PydicomReader: unable to load ('/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.250397690690072950000431855143.mhd',).

Traceback (most recent call last): 2022-10-22 14:57:53,098 - NibabelReader: unable to load ('/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.287966244644280690737019247886.mhd',).

File "luna16_prepare_images.py", line 127, in 2022-10-22 14:57:53,098 - PILReader: unable to load ('/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.287966244644280690737019247886.mhd',).

2022-10-22 14:57:53,098 - NumpyReader: unable to load ('/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.287966244644280690737019247886.mhd',).

2022-10-22 14:57:53,098 - PydicomReader: unable to load ('/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.287966244644280690737019247886.mhd',).

main()

File "luna16_prepare_images.py", line 115, in main 2022-10-22 14:57:53,099 - NibabelReader: unable to load ('/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.768276876111112560631432843476.mhd',).

for batch_data in process_loader:

File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 435, in next 2022-10-22 14:57:53,099 - PILReader: unable to load ('/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.768276876111112560631432843476.mhd',).

data = self._next_data()

File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data 2022-10-22 14:57:53,099 - NumpyReader: unable to load ('/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.768276876111112560631432843476.mhd',).

2022-10-22 14:57:53,099 - PydicomReader: unable to load ('/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.768276876111112560631432843476.mhd',).

return self._process_data(data)

File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data data.reraise() File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/torch/_utils.py", line 428, in reraise raise self.exc_type(msg) RuntimeError: Caught RuntimeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/transform.py", line 91, in apply_transform return _apply_transform(transform, data, unpack_items) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/transform.py", line 55, in _apply_transform return transform(parameters) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/io/dictionary.py", line 154, in call data = self._loader(d[key], reader) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/io/array.py", line 259, in call f"{self.class.name} cannot find a suitable reader for file: {filename}.\n" RuntimeError: LoadImage cannot find a suitable reader for file: /ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.250397690690072950000431855143.mhd. Please install the reader libraries, see also the installation instructions: https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies. The current registered: [<monai.data.image_reader.PydicomReader object at 0x7f5aa3578a50>, <monai.data.image_reader.NumpyReader object at 0x7f5aa3578f50>, <monai.data.image_reader.PILReader object at 0x7f5aa3578e50>, <monai.data.image_reader.NibabelReader object at 0x7f5aa3578f10>]. Traceback (most recent call last): File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/io/array.py", line 243, in call img = reader.read(filename) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/data/imagereader.py", line 912, in read img = nib.load(name, **kwargs) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/nibabel/loadsave.py", line 56, in load filename) nibabel.filebasedimages.ImageFileError: Cannot work out file type of "/ssdm2/yuyu/LUNA16/1.3.6.1.4.1.14519.5.2.1.6279.6001.250397690690072950000431855143.mhd"

Traceback (most recent call last): File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/io/array.py", line 243, in call img = reader.read(filename) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/data/imagereader.py", line 1167, in read img = PILImage.open(name, **kwargs) TypeError: open() got an unexpected keyword argument 'affine_lps_to_ras'

Traceback (most recent call last): File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/io/array.py", line 243, in call img = reader.read(filename) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/data/image_reader.py", line 1074, in read img = np.load(name, allowpickle=True, **kwargs) TypeError: load() got an unexpected keyword argument 'affine_lps_to_ras'

Traceback (most recent call last): File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/io/array.py", line 243, in call img = reader.read(filename) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/data/imagereader.py", line 481, in read ds = pydicom.dcmread(fp=name, **kwargs) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/pydicom/filereader.py", line 870, in dcmread force=force, specific_tags=specific_tags) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/pydicom/filereader.py", line 667, in read_partial preamble = read_preamble(fileobj, force) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/pydicom/filereader.py", line 620, in read_preamble raise InvalidDicomError("File is missing DICOM File Meta Information " pydicom.errors.InvalidDicomError: File is missing DICOM File Meta Information header or the 'DICM' prefix is missing from the header. Use force=True to force reading.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/transform.py", line 91, in apply_transform return _apply_transform(transform, data, unpack_items) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/transform.py", line 55, in _applytransform return transform(parameters) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/compose.py", line 173, in call input = apply_transform(transform, input, self.map_items, self.unpack_items, self.log_stats) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/transform.py", line 118, in apply_transform raise RuntimeError(f"applying transform {transform}") from e RuntimeError: applying transform <monai.transforms.io.dictionary.LoadImaged object at 0x7f5ad4ef1e50>

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop data = fetcher.fetch(index) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/data/dataset.py", line 105, in getitem return self._transform(index) File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/data/dataset.py", line 91, in _transform return apply_transform(self.transform, data_i) if self.transform is not None else data_i File "/home/ys3/anaconda3/envs/deepsvdd/lib/python3.7/site-packages/monai/transforms/transform.py", line 118, in apply_transform raise RuntimeError(f"applying transform {transform}") from e RuntimeError: applying transform <monai.transforms.compose.Compose object at 0x7f5aa3511f90>

dzenanz commented 1 year ago

It looks like you don't have ITK installed. Try pip install itk.