TotalSegmentator error at first run: Command ...Python\Scripts\TotalSegmentator... returned non-zero exit status 120

In line with this error, i get a similar one and don’t know why:

Traceback (most recent call last):
File “C:\Users\Augusto\AppData\Local\NA-MIC\Slicer 5.2.1\bin\Python\slicer\util.py”, line 2961, in tryWithErrorDisplay
yield
File “C:/Users/Augusto/AppData/Local/NA-MIC/Slicer 5.2.1/NA-MIC/Extensions-31317/TotalSegmentator/lib/Slicer-5.2/qt-scripted-modules/TotalSegmentator.py”, line 258, in onApplyButton
self.logic.process(self.ui.inputVolumeSelector.currentNode(), self.ui.outputSegmentationSelector.currentNode(),
File “C:/Users/Augusto/AppData/Local/NA-MIC/Slicer 5.2.1/NA-MIC/Extensions-31317/TotalSegmentator/lib/Slicer-5.2/qt-scripted-modules/TotalSegmentator.py”, line 716, in process
self.logProcessOutput(proc)
File “C:/Users/Augusto/AppData/Local/NA-MIC/Slicer 5.2.1/NA-MIC/Extensions-31317/TotalSegmentator/lib/Slicer-5.2/qt-scripted-modules/TotalSegmentator.py”, line 625, in logProcessOutput
raise CalledProcessError(retcode, proc.args, output=proc.stdout, stderr=proc.stderr)
subprocess.CalledProcessError: Command ‘[‘C:/Users/Augusto/AppData/Local/NA-MIC/Slicer 5.2.1/bin/…/bin\PythonSlicer.EXE’, ‘C:\Users\Augusto\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Scripts\TotalSegmentator’, ‘-i’, ‘C:/Users/Augusto/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-15_14+38+59.132/total-segmentator-input.nii’, ‘-o’, ‘C:/Users/Augusto/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-15_14+38+59.132/segmentation’, ‘–ml’, ‘–task’, ‘total’, ‘–fast’]’ returned non-zero exit status 120.

Anyone can help?

I have tried this and the extension is properly installed.

1 Like

I have the same problem.
Tried installing Slicer several times, both 5.2.1 stable or 5.3.0 dev. version.
Installed Git.
Still same error, as Augusto mentioned.
Any help? :frowning:

Traceback (most recent call last):
File “C:\Users\rstando\AppData\Local\NA-MIC\Slicer\bin\Python\slicer\util.py”, line 2963, in tryWithErrorDisplay
yield
File “C:/Users/rstando/AppData/Local/NA-MIC/Slicer/NA-MIC/Extensions-31464/TotalSegmentator/lib/Slicer-5.3/qt-scripted-modules/TotalSegmentator.py”, line 258, in onApplyButton
self.logic.process(self.ui.inputVolumeSelector.currentNode(), self.ui.outputSegmentationSelector.currentNode(),
File “C:/Users/rstando/AppData/Local/NA-MIC/Slicer/NA-MIC/Extensions-31464/TotalSegmentator/lib/Slicer-5.3/qt-scripted-modules/TotalSegmentator.py”, line 715, in process
self.logProcessOutput(proc)
File “C:/Users/rstando/AppData/Local/NA-MIC/Slicer/NA-MIC/Extensions-31464/TotalSegmentator/lib/Slicer-5.3/qt-scripted-modules/TotalSegmentator.py”, line 624, in logProcessOutput
raise CalledProcessError(retcode, proc.args, output=proc.stdout, stderr=proc.stderr)
subprocess.CalledProcessError: Command ‘[‘C:/Users/rstando/AppData/Local/NA-MIC/Slicer/bin/…/bin\PythonSlicer.EXE’, ‘C:\Users\rstando\AppData\Local\NA-MIC\Slicer\lib\Python\Scripts\TotalSegmentator’, ‘-i’, ‘C:/Users/rstando/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-15_17+49+15.611/total-segmentator-input.nii’, ‘-o’, ‘C:/Users/rstando/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-15_17+49+15.611/segmentation’, ‘–ml’, ‘–task’, ‘total’, ‘–fast’]’ returned non-zero exit status 120.

Can you copy here the messages that are printed in the textbox below the Apply button?
Does it work if you segment with a Slicer sample data set?

I´m having the exact same problem trying to run totalsegmentator.

@octajuan I have the same questions to you, too:

  • Can you copy here the messages that are printed in the textbox below the Apply button?
  • Does it work if you segment with a Slicer sample data set?

For the time being, since i have slicer installed in a computer which, by default, has no internet acess, i cannot download the sample data set and test TotalSegmentator with it. As soon as i have acess to internet, i will try.

The messages that appear after the Apply button are as follows:

Processing started
Writing input file to C:/Users/Augusto/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-15_21+10+39.789/total-segmentator-input.nii
Creating segmentations with TotalSegmentator AI…
Total Segmentator arguments: [‘-i’, ‘C:/Users/Augusto/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-15_21+10+39.789/total-segmentator-input.nii’, ‘-o’, ‘C:/Users/Augusto/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-15_21+10+39.789/segmentation’, ‘–ml’, ‘–task’, ‘total’, ‘–fast’]

If you have questions or suggestions, feel free to open an issue at GitHub - MIC-DKFZ/nnUNet
preprocessing C:\Users\Augusto\AppData\Local\Temp\nnunet_tmp_kqifjdkf\s01.nii.gz
before crop: (1, 228, 171, 171) after crop: (1, 228, 171, 171) spacing: [3. 3. 3.]
no resampling necessary
before: {‘spacing’: array([3., 3., 3.]), ‘spacing_transposed’: array([3., 3., 3.]), ‘data.shape (data is transposed)’: (1, 228, 171, 171)}

This worker has ended successfully, no errors to report
File “C:\Users\Augusto\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Scripts\TotalSegmentator”, line 201, in
File “C:\Users\Augusto\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Scripts\TotalSegmentator”, line 179, in main
File “C:\Users\Augusto\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\totalsegmentator\nnunet.py”, line 232, in nnUNet_predict_image
File “C:\Users\Augusto\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\totalsegmentator\nnunet.py”, line 106, in nnUNet_predict
File “C:\Users\Augusto\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\nnunet\inference\predict.py”, line 668, in predict_from_folder
File “C:\Users\Augusto\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\nnunet\inference\predict.py”, line 493, in predict_cases_fastest
File “C:\Users\Augusto\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\nnunet\training\network_training\nnUNetTrainerV2.py”, line 211, in predict_preprocessed_data_return_seg_and_softmax
File “C:\Users\Augusto\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\nnunet\training\network_training\nnUNetTrainer.py”, line 516, in predict_preprocessed_data_return_seg_and_softmax
File “C:\Users\Augusto\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\nnunet\network_architecture\neural_network.py”, line 147, in predict_3D
File “C:\Users\Augusto\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\nnunet\network_architecture\neural_network.py”, line 356, in _internal_predict_3D_3Dconv_tiled
RuntimeError: CUDA out of memory. Tried to allocate 1.30 GiB (GPU 0; 2.00 GiB total capacity; 120.31 MiB already allocated; 1.17 GiB free; 150.00 MiB reserved in total by PyTorch)
AttributeError: ‘DummyFile’ object has no attribute ‘flush’
Resampling…
Predicting…

Thank you for the report, it contained a nice and clear description of the error: you have run out of memory. 2GB GPU RAM is not nearly enough to do anything related to image segmentation.

You need to use your CPU. The easiest is to install the CPU version of pytorch by exiting Slicer and typing this into the Windows terminal:

"%localappdata%\NA-MIC\Slicer 5.2.1\bin\PythonSlicer.EXE" -m pip install torch torchvision torchaudio --force-reinstall

We have been discussing in the TotalSegmentator issue tracker how we could avoid this workaround to make switching to CPU easier in case the computer has a GPU but not powerful enough:

1 Like

Ok, will do! Thank you very much!

My CPU is burning, but now it works perfect!
Thank you!

2 Likes

Hi all, I have just tried the extension in fast mode (because no GPU is detected) and it gives me a similar error:

Traceback (most recent call last):
File “/Applications/Slicer.app/Contents/bin/Python/slicer/util.py”, line 2961, in tryWithErrorDisplay
yield
File “/Applications/Slicer.app/Contents/Extensions-31317/TotalSegmentator/lib/Slicer-5.2/qt-scripted-modules/TotalSegmentator.py”, line 258, in onApplyButton
self.logic.process(self.ui.inputVolumeSelector.currentNode(), self.ui.outputSegmentationSelector.currentNode(),
File “/Applications/Slicer.app/Contents/Extensions-31317/TotalSegmentator/lib/Slicer-5.2/qt-scripted-modules/TotalSegmentator.py”, line 715, in process
self.logProcessOutput(proc)
File “/Applications/Slicer.app/Contents/Extensions-31317/TotalSegmentator/lib/Slicer-5.2/qt-scripted-modules/TotalSegmentator.py”, line 624, in logProcessOutput
raise CalledProcessError(retcode, proc.args, output=proc.stdout, stderr=proc.stderr)
subprocess.CalledProcessError: Command ‘[’/Applications/Slicer.app/Contents/bin/…/bin/PythonSlicer’, ‘/Applications/Slicer.app/Contents/lib/Python/bin/TotalSegmentator’, ‘-i’, ‘/private/var/folders/yg/g0dyz18s69dcy2q5jm2tgf340000gn/T/Slicer-francesco/__SlicerTemp__2022-12-17_15+59+32.173/total-segmentator-input.nii’, ‘-o’, ‘/private/var/folders/yg/g0dyz18s69dcy2q5jm2tgf340000gn/T/Slicer-francesco/__SlicerTemp__2022-12-17_15+59+32.173/segmentation’, ‘–ml’, ‘–task’, ‘total’, ‘–fast’]’ returned non-zero exit status 1.

I have already tried the workarounds suggested in previous posts, including the terminal command “%localappdata%\NA-MIC\Slicer 5.2.1\bin\PythonSlicer.EXE” -m pip install torch torchvision torchaudio --force-reinstall" and the command “%localappdata%\na-mic\Slicer 5.2.1\bin\PythonSlicer.exe” -m pip install git+https://github.com/wasserth/TotalSegmentator.git --no-deps. However, I always get the error.
I am working with Slicer 5.2.1 on macOS 11.4.

Thank you very much for the support!

Those commands were not all for fixing issues but for diagnosing issues. If you executed those then they may have messed up your environment. For figuring out what’s wrong on your system, please remove Slicer, reinstall from scratch, run the segmentation on a Slicer sample data set, and provide here the content of the textbox under the Apply button.

1 Like

I removed Slicer, reinstalled it and the TotalSegmentator extension, and tried it (fast mode) on a Slicer sample data. This time it asked me for updating PyTorch, then it ran smoothly performing the segmentations. Simple but effective advice. Thanks a lot!

2 Likes