evalutils.exceptions.ValidationError: We expected to find 30, but we found .... Please correct the number of predictions. ¶
By: xinjie on July 16, 2022, 10:31 a.m.
This error is related to SimpleITK.ReadImage,you can use the following code to find the files that cause the error: from SimpleITK import ReadImage import glob import os import logging logger = logging.getLogger(name) submit_file = r'path of submit' # the path to your submit file img_list = [x for x in glob.glob(os.path.join(submit_file, "*.nii.gz"))] for path in img_list: try: img = ReadImage(path) except (ValueError, RuntimeError): logger.warning( f"Could not load {path}." )
When reading the problem file, it will report an warning, You can try to save your predictions with the following code to avoid the error: import nibabel as nib def nib_out(segmentation, output_path, image_path): """ save your predictions :param segmentation:Your prediction , the data type is "array". :param output_path:The save path of prediction results. :param image_path:The path of the image corresponding to the prediction result. :return: """ image = nib.load(image_path) segmentation = nib.Nifti1Image(segmentation, image.affine) qform = image.get_qform() segmentation.set_qform(qform) sfrom = image.get_sform() segmentation.set_sform(sfrom) nib.save(segmentation, output_path)