Did not find the expected number of training cases however I have 10 training cases (snapshots of error and json attached)
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.
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:
- Incorrect Directory Path: The directory containing the training data might be incorrectly specified or not exist.
- Empty Dataset Directory: The dataset directory might be empty or not contain the expected files.
- 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
- 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).
- 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).
- 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