Skip to content

Commit

Permalink
Merge pull request #88 from BiAPoL/stardist-napari-2025
Browse files Browse the repository at this point in the history
Stardist napari 2025
  • Loading branch information
haesleinhuepf authored Jan 21, 2025
2 parents b49054c + a51b8f3 commit aca02ea
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ parts:
- caption: Blog Posts
chapters:
# Add new chapters here (recent first)
- file: stefan_hahmann/stardist_gpu_2025/readme
- file: johannes_mueller/yolo_from_omero/train_yolo
- file: mara_lampert/getting_started_with_miniforge_and_python/readme
- file: stefan_hahmann/elephant_server_installation_windows/readme
Expand Down
15 changes: 5 additions & 10 deletions docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ If you have feedback or suggestions, if spotted a typo, broken link or misleadin

## Recent blog posts

### [Using StarDist in napari with GPU-support in Windows (2025)](stefan_hahmann/stardist_gpu_2025/readme)

<small>[Stefan Hahmann](stefan_hahmann/readme), January 20th, 2025</small><br>
<img src="images/yolo_dataset.PNG" width=10% align="right"><p>This blog post documents how to setup a Windows 10 system such that it can run the StarDist 2D and 3D plugin for Napari.</p>

### [Training a yolo model on an OMERO dataset](ref:yolo_omero)

<small>[Johannes Soltwedel](johannes_mueller/readme), August 12th, 2024</small><br>
Expand All @@ -25,16 +30,6 @@ If you have feedback or suggestions, if spotted a typo, broken link or misleadin
<small>[Stefan Hahmann](stefan_hahmann/readme), April 24th, 2024</small><br>
<img src="images/elephant-logo.png" width="100" align="right"><p>ELEPHANT is a platform for 3D cell tracking, based on incremental and interactive deep learning. This post will show you how to install the ELEPHANT server component on a Windows machine.</p>

### [Running bio image analysis workflows on your machine](stefan_hahmann/github_desktop_jupyter_notebook/readme)

<small>[Stefan Hahmann](stefan_hahmann/readme), December 21st, 2023</small><br>
<img src="images/jupyter_logo.png" width="100" align="right"><p>Jupyter Notebooks may be used to run bio image analysis workflows on your machine with your own data. They are a great tool to share workflows with others. This post will show you how to run workflows that have been shared via GitHub. </p>

### [Best of both worlds: Combining Qt Designer and magicgui](johannes_mueller/qtdesigner_and_magicgui/readme)

<small>[Johannes Soltwedel](johannes_mueller/readme), Mai 12th, 2023</small><br>
<img src="images/qt_logo.png" width="100" align="right"><p>This blog post will give you a quick introduction on how to combine two great tools for the creation of graphical user interfaces in napari: The [Qt Designer](https://doc.qt.io/qt-6/qtdesigner-manual.html) and [magicgui](https://pyapp-kit.github.io/magicgui/). </p>

Find more blog posts on the left sidebar.
Enjoy reading!

Expand Down
2 changes: 2 additions & 0 deletions docs/robert_haase/stardist_gpu/readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Using StarDist in napari with GPU-support in Windows
[Robert Haase](../readme), June 19th 2021

> **_NOTE:_** The instructions in this blog post are outdated. [Read the updated instructions](https://biapol.github.io/blog/stefan_hahmann/stardist_gpu_2025/readme.html).
3D segmentation using deep learning is computationally costly, it might be necessary from a practical perspective to do it on computers
with powerful graphics processing units (GPUs). One option is to do this in the cloud via Google Colab and for that it is recommended to take a look at [ZeroCostDeepLearning4Microscopy](https://github.com/HenriquesLab/ZeroCostDL4Mic/wiki).
If you are greedy, as I am, and want to run everything on your own Windows computer, you can follow the instructions provided here.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
207 changes: 207 additions & 0 deletions docs/stefan_hahmann/stardist_gpu_2025/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# Using StarDist in napari with GPU-support in Windows (2025)
[Stefan Hahmann](../readme), January 20th 2025

> **_Note:_** This is an update of a [previous Blogpost](https://biapol.github.io/blog/robert_haase/stardist_gpu/readme.html).
3D segmentation using deep learning is computationally costly, it might be necessary from a practical perspective to do it on computers
with powerful graphics processing units (GPUs). One option is to do this in the cloud via Google Colab and for that it is recommended to take a look at [ZeroCostDeepLearning4Microscopy](https://github.com/HenriquesLab/ZeroCostDL4Mic/wiki).
If you would like to run everything on your own Windows computer, you can follow the instructions provided here.

The [StarDist](https://github.com/stardist/stardist/) developers Uwe Schmidt and Martin Weigert recently released a
[napari plugin](https://github.com/napari/napari) named [stardist-napari](https://github.com/stardist/stardist-napari).
This puts 3D nuclei segmentation using StarDist into the hands of end-users.
You can see it in action in this [Youtube video](https://www.youtube.com/watch?v=Km1_TnUQ4FM&list=PLilvrWT8aLuZCaOkjucLjvDu2YRtCS-JT&index=5).

Under the hood StarDist uses
[Tensorflow](https://www.tensorflow.org/),
[CUDA](https://developer.nvidia.com/cuda-toolkit)
and [cuDNN](https://developer.nvidia.com/cudnn). As installation of these is not trivial, I took some notes while setting up a Windows computer with these recently (i.e. January 2025) and share the steps here.
If you know tricks or short-cuts, please [get in touch](https://github.com/BiAPoL/blog/issues) and share them!

See also:
* [Stardist Napari Windows conda environment](https://forum.image.sc/t/stardist-napari-windows-conda-environment/97149)
* [Stackoverflow: How to tell if tensorflow is using gpu acceleration from inside python shell?](https://stackoverflow.com/questions/38009682/how-to-tell-if-tensorflow-is-using-gpu-acceleration-from-inside-python-shell)


## Overview
Before you start, you will need administrative privileges on your computer.
If you don't have them, please contact your IT department.

In the following procedure, we will install
* CUDA 11.2.0
* CUDNN 8.1.0.77 for CUDA 11.2
* tensorflow-gpu 2.10.0
* stardist 0.8.5
* napari 0.5.5
* stardist-napari 2024.8.6.1

## CUDA installation
To install CUDA, download this file from [the website](https://developer.nvidia.com/cuda-11.2.0-download-archive?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal) and install them in this order.
Follow the instructions. This may take a while.

* `cuda_11.2.0_460.89_win10.exe`

Note: There is a newer version of CUDA available (>=12), but it is not compatible with the current version of tensorflow-gpu. Thus, we need to stick to CUDA 11.2.0.
For more information see [Install tensorflow](https://www.tensorflow.org/install/source_windows).

There is a table, which shows the compatibility of different versions of CUDA and tensorflow-gpu.

![tensorflow-gpu-table.png](images/tensorflow-gpu-table.png)


## cuDNN Library installation

For downloading the cuDNN library you need an NVidia developer account.
[Sign up](https://developer.nvidia.com/login) and [download CUDNN from this page](https://developer.nvidia.com/rdp/cudnn-archive):

![cudnn_download.png](images/cudnn_download.png)

Installation of cuDNN basically means unzipping the archive you downloaded and navigating into it. You can then copy these files:

![](images/install_cudnn1.png)

Into the installation directory of CUDA, e.g. `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2`:

![](images/install_cudnn2.png)

At that point, you may need administrator privileges to click on `Continue` in this dialog:

![](images/install_cudnn3.png)

After CUDA and cuDNN have been installed, it may make sense to restart the computer.

### Checking CUDA and cuDNN installation

If the installation worked correctly, you will find some entries in the Environment Variables of your computer.
To read them, click the Start Menu and enter "enviro". When the Windows Search suggests "Edit Environment Variables" hit enter:

![](images/check_env1.png)

A dialog will open, click on "Edit Environment Variables":

![](images/check_env2.png)

In the upcoming dialog, two entries should exist and point to the path were you just installed CUDNN:

![](images/check_env3.png)

If these entries don't exist, you can enter them by hand. However, it is recommended to go back and install CUDA and cuDNN again.

## Installing Mamba, Python and Tensorflow

In order to make Tensorflow use the GPU, we need to install tensorflow libraries.
As there are some conflicts between different versions of CUDA, Tensorflow, Python and others, I recommend installing specifically the versions, I'm using here:
If you don't have conda installed yet, I recommend installing [miniforge](https://github.com/conda-forge/miniforge). The installer can be downloaded [here](https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Windows-x86_64.exe).
This blog post contains an [installation instruction](https://biapol.github.io/blog/mara_lampert/getting_started_with_miniforge_and_python/readme.html).

Assuming miniforge is set up, we start by creating a new environment and specifically installing python 3.10, cudutoolkit 11.2 and cudnn 8.1.0:
```shell
mamba create --name napari-stardist-gpu python=3.10 cudatoolkit=11.2 cudnn=8.1.0
```

Afterwards, you can activate this environment:
```shell
conda activate napari-stardist-gpu
```

We install tensorflow and more precisely, its GPU version:
```shell
pip install tensorflow-gpu==2.10.0
```

To check if tensorflow is installed correctly and uses the GPU, we start a python console
```shell
python
```
and enter:
```python
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
```

The output should be some technical details ending with something like:
```
Num GPUs Available: 1
```

You can also ask for more details, by entering:
```python
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
```
This will tell you which GPU is available and also some details about your CPU, which could also run tensorflow:
```
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 6777841064378058334
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 3040739328
locality {
bus_id: 1
links {
}
}
incarnation: 317304344239135289
physical_device_desc: "device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6"
]
```

You can leave the python console by entering `quit()`.

## StarDist installation

To install StarDist, you can use pip:
```shell
pip install stardist==0.8.5
```

## Napari + StarDist plugin installation
Napari can be installed using pip using this command:

```shell
pip install napari[all]
```

You can then start napari from the command line:
```shell
napari
```

For installing the StarDist plugin, click on the menu `Plugins > Install/Uninstall packages...`.
This dialog will open, where you can just search for the plugin and click the `Install` button next to it:

![](images/install_stardist.png)

You then need to restart napari. Afterwards, a new menu entry will show up under `Plugins`:

![](images/install_stardist2.png)

## Testing the StarDist napari plugin

For testing the plugin, you can use example data StarDist provides. You can find it in the menu `File > Open Samples... > StarDist > Nuclei (3D)`.

![](images/use_stardist1.png)

Then you should be able to activate the plugin from the menu `Plugins > StarDist : StarDist`.
As the default-values fit to the example data, you can just click on `Run` in the bottom right:

![](images/use_stardist2.png)

To make sure that the installation of the GPU-related software worked, you can check if the GPU is indeed used, by looking at the command line window in the background :

![](images/use_stardist3.png)

Furthermore, after a moment of waiting the segmented nuclei should show up:

![](images/use_stardist4.png)

Also use the 3D view on the bottom left:

![](images/use_stardist5.gif)

Last but not least, please keep in mind that training your own model for your own data can be beneficial for segmentation quality.
Check out the [StarDist website](https://github.com/stardist/stardist) and [example notebooks](https://github.com/stardist/stardist/tree/master/examples) to learn more.

0 comments on commit aca02ea

Please sign in to comment.