As of QuPath 0.6.0, there is the possiblity to use InstanSeg to segment cells
On QuPath 0.6.0 only ! The installation procedure may changed for later QuPath.
conda environmentBased on this forum post.
conda create -n qupath-pytorch-251 python=3.12 pytorch=2.5.1 torchvision=0.20.1 torchaudio=2.5.1 pytorch-cuda=12.4 -c pytorch -c nvidia -y
conda activate qupath-pytorch-251
Here is the script to create, based on this forum post. This script, in combinaison with the above conda environment, make instanseg working with GPU.
:: Solution https://forum.image.sc/t/trouble-getting-gpu-to-work-with-instanseg-qupath/102042/46
:: Set your Pytorch version and conda environment path here:
set PYTORCH_VERSION=2.5.1
set PYTORCH_ENV=D:\conda\conda-envs\qupath-pytorch-251
:: This sets additional paths and sets the Pytorch flavour as per:
:: https://forum.image.sc/t/trouble-getting-gpu-to-work-with-instanseg-qupath/102042/26
set PYTORCH_LIBRARY_PATH=%PYTORCH_ENV%\lib\site-packages\torch\lib
set PATH=%PYTORCH_ENV%;%PYTORCH_ENV%\bin;%PYTORCH_ENV%\lib;%PYTORCH_ENV%\Library\bin;%PYTORCH_LIBRARY_PATH%;%PATH%
set PYTORCH_FLAVOR=cpu
:: Launch QuPath from this path:
"C:\QuPath-0.6.0\QuPath-0.6.0 (console).exe"
ENV variablesThis should limit duplication of downloads, hopefully. Documentation here.
| Environment Variable | Value |
|---|---|
DJL_CACHE_DIR |
D:\conda\extras\instanseg-engines |
ENGINE_CACHE_DIR |
D:\conda\extras\instanseg-engines |
Open QuPath in
.bat launch script created aboveGo under Extensions -> DeepJavaLibrary -> Manage DJL engines...
Under the Pytorch box, click on check/download engine. It should download the corresponding model (CPU or GPU) and turn to green when successfully finished.
Check in the D:\conda\extras\instanseg-engines that you indeed have the right models.
Extensions -> DeepJavaLibrary -> Manage DJL engines...Pytorch box, click on check/download engine. It should check that the corresponding model (CPU or GPU) is available and should turn to green.Extensions -> DeepJavaLibrary -> Manage DJL engines...Pytorch box, click on check/download engine. It should check that the corresponding model (CPU or GPU) is available and should turn to green.qupath.ext.instanseg.core.InstanSeg.builder()
.modelPath("/path/to/some/model")
.device("mps")
.nThreads(4)
.tileDims(512)
.interTilePadding(32)
.inputChannels([ColorTransforms.createChannelExtractor("Red"), ColorTransforms.createChannelExtractor("Green"), ColorTransforms.createChannelExtractor("Blue")])
.outputChannels()
.makeMeasurements(true)
.randomColors(false)
.build()
.detectObjects()
The main issue that can happen is that the GPU is not recognized by Instanseg. Try to check
The version of DJL extension. It needs a specific version of pytorch. You may need to adapt the version of pytorch in your environment.
Which version of cuda is supported by your GPU. For that, open a terminal and type nvidia-smi. It will list the different GPU available, with their version. It also shows a version of cuda, but you don't care about this one. From the GPU name (i.e. NVIDIA GeForce RTX 3090), go to the nvidia website and check what is the microarchitecture implemented in the GPU. Finally, check in this table which version of cuda is supported for the specific microachitecture.
Check that Pytorch recognizes correctly the GPU. For that, activate your environment and type the following commands, taken from that post
(D:\conda\conda-envs\qupath-pytorch) C:\Users\dornier>python
Python 3.12.11 | packaged by conda-forge | (main, Jun 4 2025, 14:29:09) [MSC v.1943 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True
>>> torch.cuda.device_count()
1
>>> torch.cuda.current_device()
0
>>> torch.cuda.device(0)
<torch.cuda.device object at 0x000001890740C080>
>>> torch.cuda.get_device_name(0)
'NVIDIA GeForce RTX 3090'
>>>
The last NVIDIA GeForce 5090 has a BlackWell architecture, which needs at least CUDA 12.8. The version of DJL, currently implemented in QuPath (0.33.0), is designed for CUDA 12.4. Thus, there is an incompatibility between hardware and software that cannot be solved at the moment. We need to wait the version 0.35.0 of DJL to be able to run instanseg GPU on those GPUs. You'll also have to check the required version of Pytorch necessary for version 0.35.0.