# Develop a slicer extension with Deep Learning

**URL:** <https://discourse.slicer.org/t/develop-a-slicer-extension-with-deep-learning/9109>\
**Category:** Support\
**Created:** [November 12, 2019, 1:45am UTC](https://discourse.slicer.org/t/develop-a-slicer-extension-with-deep-learning/9109 "2019-11-12T01:45:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikecsu](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@mikecsu](https://discourse.slicer.org/u/mikecsu)\
**Post date:** [November 12, 2019, 1:45am UTC](https://discourse.slicer.org/t/develop-a-slicer-extension-with-deep-learning/9109/1 "2019-11-12T01:45:18Z")

</div>

Operating system: win 10  
Slicer version:4.11.0  
Expected behavior:  
Actual behavior:

Hi, everyone. I am doing some investigations to know about if it is possible to develop a slicer extension with Deep Learning on the current version slicer 4.11.0.

Also，Deep Learning Framework, such as tensorflow, Keras and Pytorch. Which one is better or more compatiable for a slicer extension development ?

Any references or examples are welcome.

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![ungi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ungi/32/78573_2.png) [@ungi](https://discourse.slicer.org/u/ungi)\
**Post date:** [November 12, 2019, 3:42am UTC](https://discourse.slicer.org/t/develop-a-slicer-extension-with-deep-learning/9109/2 "2019-11-12T03:42:46Z")

</div>

Hi,

We made a tutorial that guides you through how to train a deep learning model with data exported from Slicer, and how to use the trained model in a Slicer module for predictions:  
[http://www.slicerigt.org/wp/cars-2019-tutorial/](http://www.slicerigt.org/wp/cars-2019-tutorial/)  
This example uses webcam images, but you can use 99% of the examples for any medical image type.

You will find some example code in this project too, mostly on ultrasound segmentation:

> **[SlicerIGT/aigt](https://github.com/SlicerIGT/aigt)**
>
> Deep learning software modules for image-guided medical procedures - SlicerIGT/aigt

Slicer can use TensorFlow, so I suggest you use Keras (now officially part of TensorFlow). I couldn’t figure out how to use PyTorch in Slicer, but it must be possible somehow. Keras seems to be more popular anyway.

I hope this helps,  
Tamas

---

<div class="post-metadata">

**Author:** ![mholden8](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mholden8/32/1112_2.png) [@mholden8](https://discourse.slicer.org/u/mholden8)\
**Post date:** [November 12, 2019, 4:21pm UTC](https://discourse.slicer.org/t/develop-a-slicer-extension-with-deep-learning/9109/3 "2019-11-12T16:21:46Z")

</div>

Thanks @ungi for the great resources! I will check them out too.

I would just like to add that I use PyTorch from Slicer sometimes, so I can explain how I have gotten it to work…

If you go to [pytorch.org](http://pytorch.org), it will provide the proper install command for your configuration.  
Then you can install PyTorch in Slicer’s Python via:

```auto
C:\path\to\Slicer\bin\PythonSlicer -m <install-command>

```

For example, I use Windows 10 and do not have GPU, so I used the command:

```auto
C:\path\to\Slicer\bin\PythonSlicer -m pip install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html

```

Once installed, you can import PyTorch into Slicer’s Python interactor with the standard command:

```auto
import torch
import torchvision

```
