nnUNet icon indicating copy to clipboard operation
nnUNet copied to clipboard

nnUNet_plan_and_preprocess : command not found

Open Philip2040 opened this issue 2 years ago • 17 comments

Hello guys, I've encountered the following problem. After installing the model, I tried to run the model on my dataset. However, when running the code "nnUNet_plan_and_preprocess -t 001" in the command line, it gave the following error: "nnUNet_plan_and_preprocess : command not found"

It seems that the environment variables aren't properly set. If I want to set them manually, what should I do?

Philip2040 avatar Dec 11 '23 15:12 Philip2040

Hello? can anybody help?

Philip2040 avatar Dec 11 '23 16:12 Philip2040

For some of my computers, it works but for others are not, I am also quite curious about it

Stefan-Yu404 avatar Jan 11 '24 16:01 Stefan-Yu404

See https://github.com/MIC-DKFZ/nnUNet/blob/master/documentation/set_environment_variables.md.

ancestor-mithril avatar Jan 11 '24 16:01 ancestor-mithril

Got it! Thank you

Stefan-Yu404 avatar Jan 11 '24 16:01 Stefan-Yu404

I'm currently facing the same issue, what was the solution? The following environment variables have been manually set and confirmed.

os.environ['nnUNet_raw'] os.environ['nnUNet_preprocessed'] os.environ['results']

slefcourt27 avatar Jan 30 '24 18:01 slefcourt27

I’m currently meeting a problem which is I followed the READNE.md, but I found that when I use the command 'nnUNet_plan_and_preprocess -t 500', the terminal shows nnUNet_plan_and_preprocess: command not found. The dataset environment has been set. Can anyone help me?

CodeHarcourt avatar Mar 07 '24 13:03 CodeHarcourt

Did you install nnUNet v2? The command is nnUNetv2_plan_and_preprocess.

ancestor-mithril avatar Mar 07 '24 14:03 ancestor-mithril

Thank you for your help! But now I meet a new problem, which is nnUNetv2_plan_and_preprocess -d 500 Fingerprint extraction... Traceback (most recent call last): File "/home/nas/.local/bin/nnUNetv2_plan_and_preprocess", line 8, in <module> sys.exit(plan_and_preprocess_entry()) File "/home/nas/huoguohao/nnUNet/nnunetv2/experiment_planning/plan_and_preprocess_entrypoints.py", line 182, in plan_and_preprocess_entry extract_fingerprints(args.d, args.fpe, args.npfp, args.verify_dataset_integrity, args.clean, args.verbose) File "/home/nas/huoguohao/nnUNet/nnunetv2/experiment_planning/plan_and_preprocess_api.py", line 46, in extract_fingerprints extract_fingerprint_dataset(d, fingerprint_extractor_class, num_processes, check_dataset_integrity, clean, File "/home/nas/huoguohao/nnUNet/nnunetv2/experiment_planning/plan_and_preprocess_api.py", line 25, in extract_fingerprint_dataset dataset_name = convert_id_to_dataset_name(dataset_id) File "/home/nas/huoguohao/nnUNet/nnunetv2/utilities/dataset_name_id_conversion.py", line 48, in convert_id_to_dataset_name raise RuntimeError(f"Could not find a dataset with the ID {dataset_id}. Make sure the requested dataset ID " RuntimeError: Could not find a dataset with the ID 500. Make sure the requested dataset ID exists and that nnU-Net knows where raw and preprocessed data are located (see Documentation - Installation). Here are your currently defined folders: nnUNet_preprocessed=/home/nas/nnUNet/nnUNetFrame/DATASET/nnUNet_preprocessed nnUNet_results=/home/nas/nnUNet/nnUNetFrame/DATASET/RESULTS_FOLDER nnUNet_raw=/home/nas/nnUNet/nnUNetFrame/DATASET/nnUNet_raw_data_base/nnUNet_raw_data/Task500_MYTASK If something is not right, adapt your environment variables. .

CodeHarcourt avatar Mar 07 '24 14:03 CodeHarcourt

See https://github.com/MIC-DKFZ/nnUNet/blob/master/documentation/how_to_use_nnunet.md and https://github.com/MIC-DKFZ/nnUNet/blob/master/documentation/set_environment_variables.md.

ancestor-mithril avatar Mar 07 '24 14:03 ancestor-mithril

Thank you for being so helpful. Now I can use the command nnUNetv2_plan_and_preprocess -d 500 --verify_dataset_integrity, but there is another problem which is RuntimeError: Some segmentation images contained unexpected labels. Please check text output above to see which one(s). . I can't solve it. Because I don't know why the terminal show Error: Unexpected labels found in file /home/nas/nnUNet/nnUNetFrame/DATASET/nnUNet_raw/Dataset500_BTS/labelsTr/BRATS_360.nii.gz. Expected: [0, 1, 2, 3] Found: [0. 1. 2. 4.]

CodeHarcourt avatar Mar 08 '24 04:03 CodeHarcourt

This means that BRATS_360.nii.gz has floating point labels instead of integers. You can solve this problem by loading and saving the segmentation mask again after casting it to np.uint8.

ancestor-mithril avatar Mar 08 '24 18:03 ancestor-mithril

This means that BRATS_360.nii.gz has floating point labels instead of integers. You can solve this problem by loading and saving the segmentation mask again after casting it to np.uint8.

I followed your instructions. But the problem doesn't resolve. I try to redownload the dataset and retry this process. But I beat the air. I use the code def convert_datatype(input_dir, output_dir): if not os.path.exists(output_dir): os.makedirs(output_dir) for filename in os.listdir(input_dir): if filename.endswith(".nii.gz"): input_file = os.path.join(input_dir, filename) output_file = os.path.join(output_dir, filename) img = nib.load(input_file) data = img.get_fdata() data = data.astype(np.uint8) new_img = nib.Nifti1Image(data, img.affine, img.header) nib.save(new_img, output_file) I think the code is right. so what solution can i try ones again.

CodeHarcourt avatar Mar 12 '24 13:03 CodeHarcourt

Did you check that the data type changed? For the file that raises the error, open it, load the numpy array and check the dtype. Example:

print(nib.load('/home/nas/nnUNet/nnUNetFrame/DATASET/nnUNet_raw/Dataset500_BTS/labelsTr/BRATS_360.nii.gz').get_fdata().dtype)

ancestor-mithril avatar Mar 12 '24 13:03 ancestor-mithril

Thank you. I run your and then find that the data type no change. It is float64. I change my code. Now it is `import os import nibabel as nib import numpy as np from monai.data.image_reader import nib

input_dir = 'G:\nnUNet\nnUNetFrame\DATASET\nnUNet_raw\Dataset500_BTS\labelsTr' output_dir = 'G:\nnUNet\nnUNetFrame\DATASET\nnUNet_raw\Dataset500_BTS\labelsTr_uint8'

if not os.path.exists(output_dir): os.makedirs(output_dir)

for filename in os.listdir(input_dir): if filename.endswith('.nii.gz'): nii_file = nib.load(os.path.join(input_dir, filename)) data = nii_file.get_fdata() data_uint8 = data.astype(np.uint8) new_nii = nib.Nifti1Image(data_uint8, nii_file.affine, nii_file.header) output_filename = os.path.join(output_dir, filename) nib.save(new_nii, output_filename) print(f'yes')` But it can't change the data type. What can i do next? Can you help me?

CodeHarcourt avatar Mar 13 '24 06:03 CodeHarcourt

maybe you have to delete the file first. If not, use SimpleITK:

img = sitk.ReadImage(path)
spacing = img.GetSpacing()
origin = img.GetOrigin()
direction = img.GetDirection()
array = sitk.GetArrayFromImage(img)
os.remove(path)
img = sitk.GetImageFromArray(array.astype(np.uint8))
img.SetSpacing(spacing)
img.SetOrigin(origin)
img.SetDirection(direction)
sitk.WriteImage(img, path)

ancestor-mithril avatar Mar 13 '24 08:03 ancestor-mithril

Ok. I use two different methods to change the data type. And then combine them to one folder. I solve this problem.Thank you very much. Now I begin to train the model.

CodeHarcourt avatar Mar 13 '24 10:03 CodeHarcourt

Yeah, bro. I meet a new problem which is the train_loss and the val_loss. They are too high. The train_loss and val_loss synchronous rise. This means the dataset may need to be data cleaned or change the structure of the net. In the five epochs the terminal shows Current learning rate: 0.00995 train_loss -0.7964 val_loss -0.7616 Pseudo dice [0.7497, 0.8259, 0.8752] Epoch time: 154.69 s Yayy! New best EMA pseudo Dice: 0.7575 and the first epoch Current learning rate: 0.01 train_loss -0.3213 val_loss -0.6368 Pseudo dice [0.5874, 0.7518, 0.8273] Epoch time: 168.24 s Yayy! New best EMA pseudo Dice: 0.7221 I used your method to reset the data type of the labelsTr. But maybe something was wrong. Can you give me some advice?

CodeHarcourt avatar Mar 14 '24 12:03 CodeHarcourt