Traceback when trying to create a cache dataset in monai

Hi guys! This is a problem related to the @MONAI library
This is the error that I am getting:

Loading dataset:   0%|          | 0/380 [00:00<?, ?it/s]/usr/local/lib/python3.10/dist-packages/nibabel/nifti1.py:1060: RuntimeWarning: invalid value encountered in divide
  R = RZS / zooms
/usr/local/lib/python3.10/dist-packages/numpy/linalg/linalg.py:2154: RuntimeWarning: invalid value encountered in det
  r = _umath_linalg.det(a, signature=signature)
Loading dataset:   0%|          | 0/380 [00:00<?, ?it/s]
---------------------------------------------------------------------------
LinAlgError                               Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/monai/transforms/transform.py in apply_transform(transform, data, map_items, unpack_items, log_stats, lazy, overrides)
    140             return [_apply_transform(transform, item, unpack_items, lazy, overrides, log_stats) for item in data]
--> 141         return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats)
    142     except Exception as e:

21 frames
LinAlgError: SVD did not converge

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

RuntimeError                              Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/monai/transforms/transform.py in apply_transform(transform, data, map_items, unpack_items, log_stats, lazy, overrides)
    169             else:
    170                 _log_stats(data=data)
--> 171         raise RuntimeError(f"applying transform {transform}") from e
    172 
    173 

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

And this is the code I have:

# The paths are to every image or segmentation, type: <str>
train_files = [{"vol": image_name, "seg": label_name} for image_name, label_name in zip(path_train_volumes, path_train_segmentation)]
test_files = [{"vol": image_name, "seg": label_name} for image_name, label_name in zip(path_test_volumes, path_test_segmentation)]
dict_keys = ["vol", "seg"]

train_transforms = Compose(
    [
        LoadImaged(keys=dict_keys),
        EnsureChannelFirstd(keys=dict_keys),
        Orientationd(keys=dict_keys, axcodes="RAS"),
        ScaleIntensityRanged(keys=dict_keys, a_min=0, a_max=700, b_min=0.0, b_max=1.0, clip=True),
        CropForegroundd(keys=dict_keys, source_key="vol"),
        Resized(keys=dict_keys, spatial_size=[256, 256, 155]),
        ToTensord(keys=dict_keys)
    ]
)

test_transforms = Compose(
    [
        LoadImaged(keys=dict_keys),
        EnsureChannelFirstd(keys=dict_keys),
        Orientationd(keys=dict_keys, axcodes="RAS"),
        ScaleIntensityRanged(keys=dict_keys, a_min=0, a_max=700, b_min=0.0, b_max=1.0, clip=True),
        CropForegroundd(keys=dict_keys, source_key="vol"),
        Resized(keys=dict_keys, spatial_size=[256, 256, 155]),
        ToTensord(keys=dict_keys)
    ]
)

train_ds = CacheDataset(data=train_files, transform=train_transforms) #<------ Line where the traceback is
train_loader = DataLoader(train_ds, batch_size=1)

test_ds = CacheDataset(data=test_files, transform=test_transforms)
test_loader = DataLoader(test_ds, batch_size=1)

I thought that maybe it could be that I am loading a string object, but I think that it was not the problem.

Every item in the train_files variable is a dictionary that contains the key “vol” or “seg” and the values are the respective paths. Maybe there is a problem with the transformations?

Yes, as indicated by the stacktrace, the svd operation failed during a transformation:

LinAlgError                               Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/monai/transforms/transform.py in apply_transform(transform, data, map_items, unpack_items, log_stats, lazy, overrides)
    140             return [_apply_transform(transform, item, unpack_items, lazy, overrides, log_stats) for item in data]
--> 141         return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats)
    142     except Exception as e:

21 frames
LinAlgError: SVD did not converge

Try to understand why this op fails and why it’s used in the first place.