Error While using 'Total Segmentator'

hey all,

I’m having an error while trying to use the ‘total segmentator’ module.

Traceback (most recent call last):
File “C:\Users\dror\AppData\Local\NA-MIC\Slicer 5.2.1\bin\Python\slicer\util.py”, line 2961, in tryWithErrorDisplay
yield
File “C:/Users/dror/AppData/Local/NA-MIC/Slicer 5.2.1/NA-MIC/Extensions-31317/TotalSegmentator/lib/Slicer-5.2/qt-scripted-modules/TotalSegmentator.py”, line 248, in onApplyButton
self.logic.setupPythonRequirements()
File “C:/Users/dror/AppData/Local/NA-MIC/Slicer 5.2.1/NA-MIC/Extensions-31317/TotalSegmentator/lib/Slicer-5.2/qt-scripted-modules/TotalSegmentator.py”, line 532, in setupPythonRequirements
slicer.util.pip_install(totalSegmentatorPackage + " --no-deps" + (" --upgrade" if upgrade else “”))
File “C:\Users\dror\AppData\Local\NA-MIC\Slicer 5.2.1\bin\Python\slicer\util.py”, line 3571, in pip_install
_executePythonModule(‘pip’, args)
File “C:\Users\dror\AppData\Local\NA-MIC\Slicer 5.2.1\bin\Python\slicer\util.py”, line 3533, in _executePythonModule
logProcessOutput(proc)
File “C:\Users\dror\AppData\Local\NA-MIC\Slicer 5.2.1\bin\Python\slicer\util.py”, line 3502, in logProcessOutput
raise CalledProcessError(retcode, proc.args, output=proc.stdout, stderr=proc.stderr)
subprocess.CalledProcessError: Command ‘[‘C:/Users/dror/AppData/Local/NA-MIC/Slicer 5.2.1/bin/…/bin\PythonSlicer.EXE’, ‘-m’, ‘pip’, ‘install’, ‘git+https://github.com/wasserth/TotalSegmentator.git’, ‘–no-deps’]’ returned non-zero exit status 1.

Does anyone know how to fix it?

Totalsegmentator is downloaded using git (revision control tool), therefore you need to have git installed on your system. If you update the extension to the latest version then it automatically offers to install it. If this does not work for you for any reason then you can install git manually from here. After git installation, restart your computer and TotalSegmentator installation should succeed. If there is still problem then let me know and I send further instructions.

Thank you very much, it’s working.

I got the exact same error message while using the TotalSegmentator module. I did already install git (git version 2.39.0.windows.2), restarted Slicer and my laptop, but still get the same message when pressing “Apply” in the module. What could be other possibilities to fix this error?

Thanks in advance for thinking along!

If you are on Windows, could you try to install TotalSegmentator from the command line:

"C:\Users\yourname\AppData\Local\NA-MIC\Slicer 5.2.1\bin/PythonSlicer.EXE" -m pip install git+https://github.com/wasserth/TotalSegmentator.git --no-deps

and post eventual error messages?

I do not get an error message when entering the command line and installing TotalSegmentator, the installation is fully successful. Unfortunately, I still get the same error when applying the module in Slicer.

Are you getting any messages here?

image

Could you specify your hardware and run 3D Slicer in admin mode for a test?
Please use the CTChest demo dataset from “Sample Data”

image

This is what I get when running in admin mode.

I have Windows 10 Home on a Lenovo Thinkpad T460s with the following processor: Intel(R) Core™ i5-6200U CPU @ 2.30GHz, 2400 Mhz, 2 Core(s), 4 Logical Processor(s)

What happens if you go to the “PyTorch” extension and press the button “Install PyTorch”? Probably the same?

Yes that is correct, then I get the same error

@lassoan has just made a helpful update of the PyTorch extension:

image

you may want to uninstall and reinstall PyTorch after updating. Please bear in mind that your laptop will run TotalSegmentator in CPU mode.

@lassoan it would be great if you could add a “Check CUDA” button

Thanks, I indeed read it somewhere else as well. This update fixed the first error I had, @lassoan thank you for that!

With the reinstalled PyTorch I got some errors for missing modules, which I pip installed. My access got denied when installing xvfbwrapper and it mentioned that I got a too new version of ITK-snap as well for totalsegmentator. In Slicer I currently get the following error:

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

with

Traceback (most recent call last):
File “C:\Users\schra\AppData\Local\NA-MIC\Slicer 5.2.1\bin\Python\slicer\util.py”, line 2961, in tryWithErrorDisplay
yield
File “C:/Users/schra/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/schra/AppData/Local/NA-MIC/Slicer 5.2.1/NA-MIC/Extensions-31317/TotalSegmentator/lib/Slicer-5.2/qt-scripted-modules/TotalSegmentator.py”, line 714, in process
proc = slicer.util.launchConsoleProcess(totalSegmentatorCommand + options)
File “C:\Users\schra\AppData\Local\NA-MIC\Slicer 5.2.1\bin\Python\slicer\util.py”, line 3463, in launchConsoleProcess
proc = subprocess.Popen(args, env=startupEnv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, startupinfo=info, cwd=cwd)
File “C:\Users\schra\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\subprocess.py”, line 951, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File “C:\Users\schra\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\subprocess.py”, line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application

Was installing the separate missing modules not the correct thing to do? And what can I do to overrule the denial of the missing xvfbwrapper module? Or is this not the way to go?

Again, thanks a lot for thinking along!

I managed to install the xvfbwrapper and right ITK-snap version. Everything seems to work now!

Thanks for the help!

1 Like

Hi there,

I installed Git etc. I ininstalled PyTorch and got a message that it was installed. I then tried install PyTorch, but nothing happens, even not messages…is there any additional package I need such that pytorch wil be installed?

Thnx
Ronald

Hi Ronald,

Have you been using the PyTorch extension for uninstalling and then installing PyTorch as outlined above?

Dear Rudolf

I tried several times and finally I disconnected my PC and used wifi with eduroam and now it was able to unistall and install pytorch. But I encountered the next error "Processing started

Writing input file to C:/Users/Ronald/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-28_17+14+28.271/total-segmentator-input.nii

Creating segmentations with TotalSegmentator AI…

Total Segmentator arguments: [‘-i’, ‘C:/Users/Ronald/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-28_17+14+28.271/total-segmentator-input.nii’, ‘-o’, ‘C:/Users/Ronald/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-28_17+14+28.271/segmentation’, ‘–ml’, ‘–task’, ‘total’, ‘–fast’]

Traceback (most recent call last):

File “C:\Users\Ronald\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Scripts\TotalSegmentator”, line 10, in

import nibabel as nib

ModuleNotFoundError: No module named ‘nibabel’

"

So, it seems i need to install the nibabel package. Should I do so within slider using the python window or do you recommend to do so thru cmd window.

Thnx
Ronald

Outlook-cid_image0.png

Please “Upgrade” the Totalsegmentator package first from the extension, now with running public WLAN.

image

If that does not help, you could pip install missing packages from the Python Interactor like this:

slicer.util.pip_install("nibabel")

Some steps further:-)

Still an error:
Processing started
Writing input file to C:/Users/Ronald/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-28_17+54+58.904/total-segmentator-input.nii
Creating segmentations with TotalSegmentator AI…
Total Segmentator arguments: [‘-i’, ‘C:/Users/Ronald/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-28_17+54+58.904/total-segmentator-input.nii’, ‘-o’, ‘C:/Users/Ronald/AppData/Local/Temp/Slicer/__SlicerTemp__2022-12-28_17+54+58.904/segmentation’, ‘–ml’, ‘–task’, ‘total’, ‘–fast’]

Please cite the following paper when using nnUNet:

Isensee, F., Jaeger, P.F., Kohl, S.A.A. et al. “nnU-Net: a self-configuring method for deep learning-based biomedical image segmentation.” Nat Methods (2020). nnU-Net: a self-configuring method for deep learning-based biomedical image segmentation | Nature Methods

If you have questions or suggestions, feel free to open an issue at GitHub - MIC-DKFZ/nnUNet

preprocessing C:\Users\Ronald\AppData\Local\Temp\nnunet_tmp_8pv33ag1\s01.nii.gz
using preprocessor GenericPreprocessor
before crop: (1, 293, 200, 200) after crop: (1, 293, 200, 200) spacing: [3. 3. 3.]

no resampling necessary
no resampling necessary
before: {‘spacing’: array([3., 3., 3.]), ‘spacing_transposed’: array([3., 3., 3.]), ‘data.shape (data is transposed)’: (1, 293, 200, 200)}
after: {‘spacing’: array([3., 3., 3.]), ‘data.shape (data is resampled)’: (1, 293, 200, 200)}

(1, 293, 200, 200)
This worker has ended successfully, no errors to report
Traceback (most recent call last):
File “C:\Users\Ronald\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Scripts\TotalSegmentator”, line 201, in
main()
File “C:\Users\Ronald\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Scripts\TotalSegmentator”, line 179, in main
seg = nnUNet_predict_image(args.input, args.output, task_id, model=model, folds=folds,
File “C:\Users\Ronald\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\totalsegmentator\nnunet.py”, line 232, in nnUNet_predict_image
nnUNet_predict(tmp_dir, tmp_dir, task_id, model, folds, trainer, tta)
File “C:\Users\Ronald\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\totalsegmentator\nnunet.py”, line 106, in nnUNet_predict
predict_from_folder(model_folder_name, dir_in, dir_out, folds, save_npz, num_threads_preprocessing,
File “C:\Users\Ronald\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\nnunet\inference\predict.py”, line 668, in predict_from_folder
return predict_cases_fastest(model, list_of_lists[part_id::num_parts], output_files[part_id::num_parts], folds,
File “C:\Users\Ronald\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\nnunet\inference\predict.py”, line 493, in predict_cases_fastest
res = trainer.predict_preprocessed_data_return_seg_and_softmax(d, do_mirroring=do_tta,
File “C:\Users\Ronald\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
ret = super().predict_preprocessed_data_return_seg_and_softmax(data,
File “C:\Users\Ronald\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
ret = self.network.predict_3D(data, do_mirroring=do_mirroring, mirror_axes=mirror_axes,
File “C:\Users\Ronald\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\nnunet\network_architecture\neural_network.py”, line 147, in predict_3D
res = self._internal_predict_3D_3Dconv_tiled(x, step_size, do_mirroring, mirror_axes, patch_size,
File “C:\Users\Ronald\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\nnunet\network_architecture\neural_network.py”, line 384, in _internal_predict_3D_3Dconv_tiled
predicted_patch = self._internal_maybe_mirror_and_pred_3D(
File “C:\Users\Ronald\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\nnunet\network_architecture\neural_network.py”, line 510, in _internal_maybe_mirror_and_pred_3D
result_torch = to_cuda(result_torch, gpu_id=self.get_device())
File “C:\Users\Ronald\AppData\Local\NA-MIC\Slicer 5.2.1\lib\Python\Lib\site-packages\nnunet\utilities\to_torch.py”, line 31, in to_cuda
data = data.cuda(gpu_id, non_blocking=non_blocking)
RuntimeError: CUDA out of memory. Tried to allocate 356.00 MiB (GPU 0; 6.00 GiB total capacity; 4.75 GiB already allocated; 0 bytes free; 4.78 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF
Exception ignored in: <totalsegmentator.libs.DummyFile object at 0x0000020E346E5250>
AttributeError: ‘DummyFile’ object has no attribute ‘flush’
Using ‘fast’ option: resampling to lower resolution (3mm)
Resampling…
Resampled in 4.12s
Predicting…

I got CUDA out of memory. Should I try to install the CPU pytorch version? I do have an nvidia card, but the amount of memory is very low…

Thnx
Ronald

No personal experience, but yes, you may want to try that, uninstall PyTorch with the extension and reinstall it in CPU mode:

image

Please let us know how it works.

1 Like

Dear Rudolf

It works! Many thanks for your help and suggestions. It is relatively fast (even with CPU) and worked quite well even for a low dose CT (done along with a PET scan)…so it generates quite well segmentations for a poor quality scan.

Regards
Ronald

2 Likes