nnUNet icon indicating copy to clipboard operation
nnUNet copied to clipboard

Did not find the expected number of training cases however I have 10 training cases (snapshots of error and json attached)

Open MaimoonaAkram opened this issue 1 year ago • 1 comments

assert len(dataset) == expected_num_training, 'Did not find the expected number of training cases '
AssertionError: Did not find the expected number of training cases (10). Found 0 instead.

image

image

MaimoonaAkram avatar Aug 08 '24 11:08 MaimoonaAkram

Hi @MaimoonaAkram.

Issue Summary

The script nnUNetv2_plan_and_preprocess is throwing an AssertionError because it did not find the expected number of training cases (10) in the dataset directory. Instead, it found 0 training cases.

Possible Cause

This error typically occurs when the script is unable to locate the expected training data in the specified directory. The most likely causes are:

  1. Incorrect Directory Path: The directory containing the training data might be incorrectly specified or not exist.
  2. Empty Dataset Directory: The dataset directory might be empty or not contain the expected files.
  3. Mismatched File Naming Convention: The files in the dataset might not follow the expected naming convention (e.g., missing or incorrect file extensions).

Suggested Solutions

  1. Check Directory Path: Ensure that the path specified in the script for the dataset directory is correct and points to the right location (nnUNet_raw/Dataset786/imagesTr in this case).
  2. Verify Dataset Files: Ensure that the imagesTr directory contains the expected number of training files (10 in this case) and that they are correctly named (e.g., with the .nii.gz extension as specified).
  3. Re-run the Script After Verification: Once you've confirmed that the dataset is in the correct location and properly formatted, re-run the nnUNetv2_plan_and_preprocess command.

Additional Debugging

You can also check the number of files in the imagesTr directory using Python:

Copy code
import os

training_len = len(os.listdir('nnUNet_raw/Dataset786/imagesTr'))
print(f'Number of training files found: {training_len}')

If this returns 0, it confirms that the directory is either empty or incorrectly specified.


Please review these suggestions and ensure that the dataset is correctly structured before re-running the script. If the issue persists, further debugging might be necessary.

Best regards,

Carsten

sten2lu avatar Aug 13 '24 07:08 sten2lu