Traceback when trying to create a cache dataset in monai

username: Mtch123
cooked: <p>Hi guys! This is a problem related to the <a class="mention" href="/u/monai">@MONAI</a> library<br>
This is the error that I am getting:</p>
<pre><code class="lang-auto">Loading dataset:   0%|          | 0/380 [00:00&lt;?, ?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&lt;?, ?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]
--&gt; 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)
--&gt; 171         raise RuntimeError(f"applying transform {transform}") from e
    172 
    173 

RuntimeError: applying transform &lt;monai.transforms.io.dictionary.LoadImaged object at 0x7c21dccc4b80&gt;
</code></pre>
<p>And this is the code I have:</p>
<pre><code class="lang-auto"># The paths are to every image or segmentation, type: &lt;str&gt;
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) #&lt;------ 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)
</code></pre>
<p>I thought that maybe it could be that I am loading a string object, but I think that it was not the problem.</p>
<p>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?</p>

username: ptrblck
cooked: <aside class="quote no-group" data-username="Mtch123" data-post="1" data-topic="192466">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mtch123/48/65714_2.png" class="avatar"> Mtch123:</div>
<blockquote>
<p>Maybe there is a problem with the transformations?</p>
</blockquote>
</aside>
<p>Yes, as indicated by the stacktrace, the <code>svd</code> operation failed during a transformation:</p>
<pre data-code-wrap="python"><code class="lang-python">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]
--&gt; 141         return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats)
    142     except Exception as e:

21 frames
LinAlgError: SVD did not converge
</code></pre>
<p>Try to understand why this op fails and why it’s used in the first place.</p>