nnUNet icon indicating copy to clipboard operation
nnUNet copied to clipboard

ValueError when running prediction

Open lolawang22 opened this issue 10 months ago • 5 comments

Hi, as I was running nnUNetv2_predict I encountered the following error and wondered how can I solve it. Is there anyway nnUNetv2_predict can skip error prediction cases? Thank you!

My command: nnUNetv2_predict -d Dataset220_KiTS2023 -i input_folder -o output_folder -f 0 1 2 3 4 -tr nnUNetTrainer -c 3d_lowres -p nnUNetPlans -npp 1 -nps 1 --continue_prediction

The error: Predicting case_00676: perform_everything_on_device: True 0%| | 0/16 [00:00<?, ?it/s]/home/siw669/anaconda3/envs/nnunet/lib/python3.12/site-packages/skimage/transform/_warps.py:160: RuntimeWarning: divide by zero encountered in divide factors = np.divide(input_shape, output_shape) 100%|███████████████████████████████████████████| 16/16 [00:10<00:00, 1.47it/s] 44%|███████████████████▎ | 7/16 [00:01<00:02, 3.85it/s]Process SpawnProcess-4: Traceback (most recent call last): File "/home/siw669/anaconda3/envs/nnunet/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap self.run() File "/home/siw669/anaconda3/envs/nnunet/lib/python3.12/multiprocessing/process.py", line 108, in run self._target(*self._args, **self._kwargs) File "/home/siw669/nnunet/nnunetv2/inference/data_iterators.py", line 57, in preprocess_fromfiles_save_to_queue raise e File "/home/siw669/nnunet/nnunetv2/inference/data_iterators.py", line 31, in preprocess_fromfiles_save_to_queue data, seg, data_properties = preprocessor.run_case(list_of_lists[idx], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/siw669/nnunet/nnunetv2/preprocessing/preprocessors/default_preprocessor.py", line 139, in run_case data, seg = self.run_case_npy(data, seg, data_properties, plans_manager, configuration_manager, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/siw669/nnunet/nnunetv2/preprocessing/preprocessors/default_preprocessor.py", line 109, in run_case_npy if np.max(seg) > 127: ^^^^^^^^^^^ File "/home/siw669/anaconda3/envs/nnunet/lib/python3.12/site-packages/numpy/core/fromnumeric.py", line 2810, in max return _wrapreduction(a, np.maximum, 'max', axis, None, out, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/siw669/anaconda3/envs/nnunet/lib/python3.12/site-packages/numpy/core/fromnumeric.py", line 88, in _wrapreduction return ufunc.reduce(obj, axis, dtype, out, **passkwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: zero-size array to reduction operation maximum which has no identity 100%|███████████████████████████████████████████| 16/16 [00:04<00:00, 3.89it/s] 100%|███████████████████████████████████████████| 16/16 [00:04<00:00, 3.69it/s] 100%|███████████████████████████████████████████| 16/16 [00:04<00:00, 3.88it/s] 100%|███████████████████████████████████████████| 16/16 [00:04<00:00, 3.88it/s] sending off prediction to background worker for resampling and export done with case_00676 Traceback (most recent call last): File "/home/siw669/anaconda3/envs/nnunet/lib/python3.12/multiprocessing/resource_sharer.py", line 138, in _serve Traceback (most recent call last): File "/home/siw669/anaconda3/envs/nnunet/bin/nnUNetv2_predict", line 8, in with self._listener.accept() as conn: ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/siw669/anaconda3/envs/nnunet/lib/python3.12/multiprocessing/connection.py", line 481, in accept sys.exit(predict_entry_point()) ^^^^^^^^^^^^^^^^^^^^^ File "/home/siw669/nnunet/nnunetv2/inference/predict_from_raw_data.py", line 841, in predict_entry_point predictor.predict_from_files(args.i, args.o, save_probabilities=args.save_probabilities, File "/home/siw669/nnunet/nnunetv2/inference/predict_from_raw_data.py", line 250, in predict_from_files deliver_challenge(c, self._authkey) File "/home/siw669/anaconda3/envs/nnunet/lib/python3.12/multiprocessing/connection.py", line 938, in deliver_challenge return self.predict_from_data_iterator(data_iterator, save_probabilities, num_processes_segmentation_export) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/siw669/nnunet/nnunetv2/inference/predict_from_raw_data.py", line 343, in predict_from_data_iterator response = connection.recv_bytes(256) # reject large message ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/siw669/anaconda3/envs/nnunet/lib/python3.12/multiprocessing/connection.py", line 216, in recv_bytes for preprocessed in data_iterator: File "/home/siw669/nnunet/nnunetv2/inference/data_iterators.py", line 109, in preprocessing_iterator_fromfiles buf = self._recv_bytes(maxlength) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/siw669/anaconda3/envs/nnunet/lib/python3.12/multiprocessing/connection.py", line 430, in _recv_bytes raise RuntimeError('Background workers died. Look for the error message further up! If there is ' RuntimeError: Background workers died. Look for the error message further up! If there is none then your RAM was full and the worker was killed by the OS. Use fewer workers or get more RAM in that case! buf = self._recv(4) ^^^^^^^^^^^^^ File "/home/siw669/anaconda3/envs/nnunet/lib/python3.12/multiprocessing/connection.py", line 395, in _recv chunk = read(handle, remaining) ^^^^^^^^^^^^^^^^^^^^^^^ ConnectionResetError: [Errno 104] Connection reset by peer

lolawang22 avatar Apr 26 '24 21:04 lolawang22

Hey @lolawang22

This seems very odd at first and should not happen on KiTS2023. Could you visually inspect case_00676 and see if everything seems normal, as well as the data type etc? Does it work on the other cases?

mrokuss avatar Apr 30 '24 19:04 mrokuss

Hi @mrokuss

Thank you for replying. I trained the model with KiTS2023 data but used it to predict images from other data sources. I did visually inspect that case_00676 might have too few slices and the rotation might not be correct. This happened from time to time and I wonder if there's a way to skip abnormal images when doing prediction? I also wonder if there are any filtering criteria for the images I could add before doing prediction to avoid this kind of error. Thanks!

lolawang22 avatar Apr 30 '24 19:04 lolawang22

Hey @lolawang22

Generally this should not happen that's why there is no such filtering by default. If you want so set up a filtering (e.g. by image size or spacing) then you would have to write your own sanity check script beforehand. Of course you could also include a try-except block inside the predictor but i regard this as a rather hacky solution. Hope this still helps!

mrokuss avatar May 10 '24 12:05 mrokuss

Hi @mrokuss

Thank you for the helpful suggestion! I'll explore around.

lolawang22 avatar May 21 '24 19:05 lolawang22

Hey @lolawang22

Could you resolve your issue in the mean time?

mrokuss avatar May 28 '24 09:05 mrokuss