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

**URL:** <https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081>\
**Category:** Support\
**Tags:** segmentation, lungctanalyzer, ai, lung, ml\
**Created:** [September 4, 2022, 5:10pm UTC](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081 "2022-09-04T17:10:55Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [January 24, 2024, 5:25pm UTC](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081/22 "2024-01-24T17:25:47Z")

</div>

This seems to be a torch problem.  
Could you install 3D Slicer 5.6.1 into a new directory and just install Pytorch, LungCTAnalyzer and TotalSegmentator extensions ?  
And determine the version of torch as shown here ?

[https://www.youtube.com/watch?v=s2lB6MLBVeE](https://www.youtube.com/watch?v=s2lB6MLBVeE)

Best  
Rudolf

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [January 24, 2024, 5:26pm UTC](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081/23 "2024-01-24T17:26:51Z")

</div>

@rsalkin If you switch to the “PyTorch Utils” module in Slicer, what version of Torch does it show that is currently installed?

@rbumm What is the minimum torch version requirement to use your LungCTSegmenter module? I see that [your code](https://github.com/rbumm/SlicerLungCTAnalyzer/blob/a98033d8437f54106592982c9cbc4f331a3580cf/LungCTSegmenter/LungCTSegmenter.py#L2296-L2319) checks if `torch` is present and that CUDA support is available, but it doesn’t check a specific `torch` version requirement?

Below is example usage of SlicerTotalSegmentator enforcing a minimum `torch` version.

> <https://github.com/lassoan/SlicerTotalSegmentator/blob/a716dd36e2afaf20cc5648204823ad1c6a8a0e8b/TotalSegmentator/TotalSegmentator.py#L703-L708>

It appears that [`lungmask`](https://github.com/JoHof/lungmask) specifies no torch version which can result in incompatibilities of an older torch version not working.

---

<div class="post-metadata">

**Author:** ![rsalkin](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@rsalkin](https://discourse.slicer.org/u/rsalkin)\
**Post date:** [January 24, 2024, 5:42pm UTC](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081/24 "2024-01-24T17:42:00Z")

</div>

@rbumm I did a fresh install into a new directory with the modules as you suggested and get the same error.

@jamesobutler The current version of Torch is 1.8.1. I don’t know if it matters but TorchVision is 0.9.1.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [January 24, 2024, 6:21pm UTC](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081/25 "2024-01-24T18:21:53Z")

</div>

Uninstall Pytorch again.  
Then install it with cu118.  
For that press "show all compatible and select cu118.  
Press Install Pytorch.

Any changes?

![image.png](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/f/ffb9637e50b55e96802d906d1087f0b473521ffa.png)

---

<div class="post-metadata">

**Author:** ![rsalkin](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@rsalkin](https://discourse.slicer.org/u/rsalkin)\
**Post date:** [January 24, 2024, 7:38pm UTC](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081/26 "2024-01-24T19:38:26Z")

</div>

The Pytorch Utils module only let me install up to version 1.8.1+cpu but I was able to manually install version 2.1.2+cpu via the python console ([Pytorch extension installation](https://discourse.slicer.org/t/pytorch-extension-installation/30929)) and now the segmenter is working.

Thanks Dr. Bumm for answering my question. The module has been extremely helpful.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [January 24, 2024, 8:04pm UTC](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081/27 "2024-01-24T20:04:19Z")

</div>

Great, but there seems to be a bug in Pytorch …

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [January 25, 2024, 10:47am UTC](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081/28 "2024-01-25T10:47:01Z")

</div>

Could you describe in detail what you had to do to install the torch version that finally worked?

---

<div class="post-metadata">

**Author:** ![rsalkin](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@rsalkin](https://discourse.slicer.org/u/rsalkin)\
**Post date:** [January 25, 2024, 2:45pm UTC](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081/29 "2024-01-25T14:45:27Z")

</div>

This is just for the CPU version as my computer does not have a capable GPU for PyTorch.

You first have to go to the PyTorch Utils module (see below) in slicer then select uninstall PyTorch (if you uninstall via the python console `slicer.util.pip_uninstall("torch")` it doesn’t work and crashes when you try to uninstall via the Utils module afterwards, assuming the original PyTorch installation used the Utils module).

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/9/d9792d31a46785b35774ec93720bb81c2940d733.png)

Restart Slicer after removing PyTorch then run the line:

```auto
slicer.util.pip_install("torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu")

```

Restart the application one more time after PyTorch has been re-downloaded and you should be good to go.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 26, 2024, 7:02pm UTC](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081/30 "2024-01-26T19:02:09Z")

</div>

For some reason, on some computers these ancient PyTorch 1.x versions are installed by default.

We added the “torch version requirement” field to PyTorch Utils module to make it very easy to install a more recent version. For example, you can type `>2` in that field and click `Install PyTorch`.

@rsalkin Do you have any recommendation of how to make it more clear that the required pytorch version can be specified in Pytorch Utils module? Maybe changing the placeholder text from “default” to something like “specify version requirement here” would help?

@rbumm I would recommend to copy the PyTorch version check that @jamesobutler highlighted from TotalSegmentator module to the LungCTSegmenter module.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [January 27, 2024, 1:03pm UTC](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081/31 "2024-01-27T13:03:11Z")

</div>

Now check the Pytorch version in LungCTSegmenter.

---

<div class="post-metadata">

**Author:** ![rsalkin](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@rsalkin](https://discourse.slicer.org/u/rsalkin)\
**Post date:** [January 29, 2024, 3:47pm UTC](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081/32 "2024-01-29T15:47:03Z")

</div>

Hi Andras, I think that could be good, otherwise it might be simpler to have a drop down menu and select either latest stable version, system default version, or a specify system version where you can then type which one you want, i.e. x.x. That way its easy for someone not to have to look up the first two and give the optionality if a module is very specific for the last option.

[Previous page](https://discourse.slicer.org/t/lung-ct-segmenter-now-supports-lungmask-ai-for-lung-and-lobe-segmentation/25081.md?page=1)
