Note
This is a work in progress as part of a live project within the SEAI (Software Engineering & AI) STP. If you come across this repo and are interested please contact Cameron Shand or Fiona Young.
A plugin for interactive use of SAM2 for segmentation and tracking.
This napari plugin was generated with copier using the napari-plugin-template.
- SAM2 improvements:
- Low-memory mode allows easier use of SAM2 for longer videos/larger stacks by avoiding GPU memory accumulation issue
- No hard CUDA/GPU requirement (though recommended!)
- Intuitive usage, utilizing keybinds to speed up annotation
- Includes proper resetting of model state when adding/removing prompts for existing objects
- Prompt import/export for working across sessions
While we include napari in the requirements, it is recommended to first install Napari in the best way for your system, for which the official documentation has some pointers.
You can install napari-sam2 from this repo via:
pip install git+https://github.com/FrancisCrickInstitute/napari_sam2.git
If you're at the Crick, and want to use napari-sam2 (before it's been handily wrapped into a premade app), here's what you need to do.
- Start an OnDemand Nemo Desktop session on the GPU partition
- Create a conda environment and install what's needed (first time only)
conda create -n napari_sam2 python=3.11conda activate napari_sam2conda install nvidia/label/cuda-12.6.0::cuda-toolkitpip install 'napari[all]'pip install git+https://github.com/FrancisCrickInstitute/napari_sam2.git
- Load modules we need (every time)
ml cuDNN/9.5.0.50-CUDA-12.6.0 VirtualGL
- Run napari:
vglrun napari
If you have any issues with the above, likely a Disk quota exceeded, you need to ensure that your .conda and .cache folders in your home directory are symlinked somewhere with more space. Ask HPC if you are unsure how to do this.
Any other issues, Crick users can email/Slack us or join the #sam2-napari-plugin Slack channel.
For guidance on best usage and further detail on features such as the "low-memory mode", please see the Usage Guide.
- Add support for bounding box prompt input
- Add support for adding masks to guide prompts (low priority)
- Tutorial video on usage
- Completed documentation and usage guide
Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
Distributed under the terms of the MIT license, "napari-sam2" is free and open source software
If you encounter any problems, please file an issue along with a detailed description.