RuntimeError: No valid DICOM-NRRD pairs found in the directories

Hi, I’m trying to do machine learning using raw data in dicom format and mask data in nrrd format.
However, the number of dicom files and the number of slices of nrd are not the same.
When I open dicom and nrrd together using slicer, it’s matching, what’s the problem?

Reconstruction of a 3D volume from 2D slices is a very complex task. Most likely there is no problem, there can be several valid reasons for the input slices not matching the dimensions of the reconstructed volume. Tell us more about your data.

No, I’m not trying to reconstruct 2D into 3D.
In slicer, the number of dcm and nrd is the same, but the number of indexes is not the same when imported from python.