fastMRI
fastMRI copied to clipboard
TypeError: slice indices must be integers or None or have an index method
Hello,
I'm encountering an error message: "TypeError: slice indices must be integers or None or have an index method" while implementing CS for a brain dataset using the equispaced mask. This error occurs at a specific section of the code, indicating an issue that I'm having trouble understanding.
In the subsample.py file within the equispaced function, I made the following modification:
if offset is None:
offset = self.rng.randint(0, high=round(acceleration))
mask = np.zeros(num_cols, dtype=np.float32)
mask[offset::acceleration] = 1
return mask
I added the following code snippet:
else:
offset_value = offset[0] if isinstance(offset, tuple) else offset
offset = int(offset_value) if offset is not None else None
This modification resolved the issue for a single volume, but when applied to multiple volumes, it did not work as expected.
Additionally, in the transform.py file, I couldn't get the mask function. Here's the relevant code snippet from the apply_mask function:
mask, num_low_frequencies = mask_func(shape, offset, seed)
if padding is not None:
mask[..., : padding[0], :] = 0
mask[..., padding[1] :, :] = 0 # padding value inclusive on the right of zeros
masked_data = data * mask + 0.0 # the + 0.0 removes the sign of the zeros
return masked_data, mask, num_low_frequencies
I have attached a screenshot of the error message for reference.
Best regards,