How to Fix Error Report: 'evalutils.exceptions.ValidationError: We expected to find 50, but we found 47. Please correct the number of predictions.' ¶
By: minghuizhang24 on Aug. 16, 2022, 2:57 a.m.
We have noticed that some participants have this error report: 'evalutils.exceptions.ValidationError: We expected to find 50, but we found 47. Please correct the number of predictions.'
This may be happens in the procedure of saving the predictions, which may be fixed by replacing the I/O functions by the followings, pay attention to that the metadata (origin and spacing) should be the same as the original input CTs:
import numpy as np import SimpleITK as sitk
Load the NIFTI Files¶
def load_itk_image(filename): itkimage = sitk.ReadImage(filename) numpyImage = sitk.GetArrayFromImage(itkimage) numpyOrigin = np.array(list(reversed(itkimage.GetOrigin()))) numpySpacing = np.array(list(reversed(itkimage.GetSpacing()))) return numpyImage, numpyOrigin, numpySpacing
Save the NIFTI Files¶
def save_itk(image: np.ndarray, filename: str, origin: np.ndarray = [0.0, 0.0, 0.0], spacing: np.ndarray = [1.0, 1.0, 1.0]) -> None: if type(origin) != tuple: if type(origin) == list: origin = tuple(reversed(origin)) else: origin = tuple(reversed(origin.tolist())) if type(spacing) != tuple: if type(spacing) == list: spacing = tuple(reversed(spacing)) else: spacing = tuple(reversed(spacing.tolist())) itkimage = sitk.GetImageFromArray(image, isVector=False) itkimage.SetSpacing(spacing) itkimage.SetOrigin(origin) sitk.WriteImage(itkimage, filename, True)
More Q&A can be found in our Q&A Page! Please pay attention to these.