Lung CT Segmenter now supports 'lungmask' AI for lung and lobe segmentation

We have a new “experimental AI” option in Lung CT Segmenter for creating lung and lobe segmentations with minimal effort (one tracheal markup) on the fly.

This feature involves Johannes Hofmanningers lungmask with permission.

A short YouTube demo is here:

In this setting, an Nvidia GPU (1060 +), 6 GB GPU memory and “CUDA enabled” are strongly recommended.

Real processing time on a desktop PC with RTX 3070Ti GPU (without the in-video speedup): 97.23 s.
Slicer extension: Lung CT Analyzer
Dataset: From MONAILabel Task06_lung with permission.


That is great. Is it possible to use cli and save labelmaps?

Yes, you can.

The Lung CT segmenter AI test function is a working example.

The only thing to note is the current necessity to define one tracheal markup in this code. If you want just lungs and lobes you could just freely define one, f.e. as in the test example, it is not really needed for AI.

1 Like

You would have to convert the output segmentation to a labelmap if you really needed to.

1 Like

thanks, i will do that

Hi Rudolf. Mine is not working. It is said no module name torch. How to get it and use the module torch? Thank you.

Please install the “Pytorch Utils” extension and restart Slicer.
Then it should typically install torch when you run the lung segmenter extension, but you could also install it from Pytorch Utils directly:


Please be patient during installation, it will take several minutes with no reaction or progress bar.

Which version of 3D Slicer and Lung CT Segmenter are you using?

Also note that you may need 20-30GB of free disk space for installing pytorch. If you run out of disk space then you may need to completely remove all remnants of pytorch and then install it again. I’ve found that in this case it is easier to reinstall Slicer than trying to clean up things manually.

All dependencies (SegmentEditorExtraEffects, SurfaceWrapSolidify, and PyTorch) are now included in Lung CT Analyzer’s CMakeList.txt for user convenience.

A fresh 3D Slicer 5.0.3 install on a Windows 11 system occupies 850 MB which grows to 7.4 GB after AI lung segmentations (mainly from Pytorch).

Hi everyone, thank you for guiding me. I have installed the Pytorch and still got the same message. Is there any way to fix it? Thank you.

I am using Macbook Pro, macOS Big Sur, 2.8GHz Dual-Core Intel Core i7, Memory 8 GB. 3D Slicer version 5.03.
I have installed PyTorch as I mentioned and the AI still not working. Thank you for your help Rudolf.

Unfortunately, I have no experience with using PyTorch in MacOS.

Have you been pressing this button in the PyTorch Utils extension?


If yes and you still got the error message you may want to refer to this page on how to install PyTorch from Slicer´s Python Interactor. See “Installing on MacOS” section.

import torch

should not throw an exception and

import torch
x = torch.rand(5, 3)

should show a result.

Following the steps to install and test pytorch that @rbumm suggested works for me on a mac (m2 macbook air) with Slicer 5.0.3.


I am using the Lung CT analyser for a research project involving analysis of chest CTs of severe COVID patients. I would like to be able to automatically segment the lung regions using the lungmask AI feature/dataset, however I consistently get the following error each time I try it;


  • Machine: MacBook Pro M1
  • OS: Mac OS Ventura Version 13.2.1 (22D68)
  • Slicer for Mac version 5.2.2

Python code for the error is;

I’m curious to know if this is an issue others have had with lungmask within 3D Slicer, and if so were there any solutions?


I just tested your issue and can confirm it on my systems too. Will try to find a solution.

Identified the error. The lungmask developers have introduced a different infer mode in their new program version 0.2.14. LungCTAnalyzer has been adopted (2.67) and has just been pushed to the project GitHub, so it will be available for updates tomorrow via the extension manager and no longer display the error message.

Hi Dr. Bumm,

Thanks very much for looking into this. I can confirm the lungmask AI model is working well within 3D slicer now and producing very nice segmentations.

Thanks again for the solution,


1 Like


I recently updated slicer and had to re-install the Lung CT Segmenter. I am now getting an error stating the module ‘torch’ has no attribute ‘inference_mode’ (see below). I tried to uninstall and re-install the module as well as pytorch.

Currently running windows 10 enterprise on a HP Z1 workstation, so using CUDA is not an option.

Any help would be appreciated, thanks!


sorry for the late response.
I can not reproduce the problem after the last 3 installations that I have done.
What do you see in the Python console when you experience this error?



Hello Dr. Bumm,

Thank you for the reply. I attached my python console output below. The problem persist even with a fresh re-install of everything.