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:

2 Likes

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

may the weights pre-downloaded by googledrive or somewhere else. Use this plugin downing weights would be terriable for me .cause I can’t download the weights file because of some ssl or network error.

Have you really tried it yet?
What were the configuration, data, machine, and network, what did you expect to happen, and what did not work?
Can you provide a log from the TotalSegmentator extension output textbox?

Please avoid posting the same problem in different threads.
Thank you.

Sorry for submitting duplicate questions many times.
here is the logs

Downloading pretrained weights for Task 251 (~230MB) ...
Traceback (most recent call last):
  File "C:\Users\someone\AppData\Local\NA-MIC\Slicer 5.3.0-2023-01-13\lib\Python\Lib\site-packages\urllib3\connection.py", line 159, in _new_conn
    conn = connection.create_connection(
  File "C:\Users\someone\AppData\Local\NA-MIC\Slicer 5.3.0-2023-01-13\lib\Python\Lib\site-packages\urllib3\util\connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "C:\Users\someone\AppData\Local\NA-MIC\Slicer 5.3.0-2023-01-13\lib\Python\Lib\socket.py", line 954, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\someone\AppData\Local\NA-MIC\Slicer 5.3.0-2023-01-13\lib\Python\Lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\someone\AppData\Local\NA-MIC\Slicer 5.3.0-2023-01-13\lib\Python\Lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "C:\Users\someone\AppData\Local\NA-MIC\Slicer 5.3.0-2023-01-13\lib\Python\Lib\site-packages\urllib3\connectionpool.py", line 978, in _validate_conn
    conn.connect()
  File "C:\Users\someone\AppData\Local\NA-MIC\Slicer 5.3.0-2023-01-13\lib\Python\Lib\site-packages\urllib3\connection.py", line 309, in connect
    conn = self._new_conn()
  File "C:\Users\someone\AppData\Local\NA-MIC\Slicer 5.3.0-2023-01-13\lib\Python\Lib\site-packages\urllib3\connection.py", line 171, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x00000287DC4D9D60>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\someone\AppData\Local\NA-MIC\Slicer 5.3.0-2023-01-13\lib\Python\Lib\site-packages\requests\adapters.py", line 489, in send
    resp = conn.urlopen(
  File "C:\Users\someone\AppData\Local\NA-MIC\Slicer 5.3.0-2023-01-13\lib\Python\Lib\site-packages\urllib3\connectionpool.py", line 726, in urlopen
    retries = retries.increment(
  File "C:\Users\someone\AppData\Local\NA-MIC\Slicer 5.3.0-2023-01-13\lib\Python\Lib\site-packages\urllib3\util\retry.py", line 446, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='zenodo.org', port=443): Max retries exceeded with url: /record/6802342/files/Task251_TotalSegmentator_part1_organs_1139subj.zip?download=1 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000287DC4D9D60>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed'))

Sorry for submitting duplicate questions many times again
the questions are following:

  1. can I load weights manually, without using slicer to download weights in case of bad network situation
  2. can I use my own trained weight and model to infer the segmentation with your code framework
    thank you

Thanks for the details. Please allow some time for checking this out with the developer of TotalSegmentator and on our own systems.

Just tested this with a fresh 3D Slicer 5.3.0.
PyTorch and TotalSegmentator installed fine with no problems.

Please understand that the TotalSegmentator extension wraps the program for ease of use in 3D Slicer, and the original code is maintained here.
Your problem indicates a maybe regional network issue during access to Zenodo and similar problems have already been reported in the TotalSegmentator issue tracker on GitHub.

Please try installing Slicer and TS on a different machine or in a different network.

You can download the weights manually and put them in the folder where 3D Slicer needs them. @lassoan can tell you where the weights are stored for the TotalSegmentator 3D Slicer extension.

The links to the weights can be seen here:

You could also replace those weights by your own trained weights. But you might easily run into problems doing this. You should be familiar with python when you do this.

2 Likes