TriSAM is a 3D segmentation pipeline built around the Segment Anything Model (SAM). This repository contains a single entry point (model/main.py) that loads a 3D HDF5 volume, generates initial seeds, computes SAM embeddings, and produces 3D segmentations.
- Python 3.9+
- CUDA-capable GPU (recommended)
Install dependencies with pip (use a virtual environment or conda if desired):
pip install numpy h5py torch scipy scikit-image opencv-python cc3d
pip install git+https://github.com/facebookresearch/segment-anything.gitIf you already have SAM installed, you can skip the second line.
Set the following environment variables so the script can find your data and SAM checkpoint:
export TRISAM_DATA_ROOT=/path/to/data
export TRISAM_SAM_CHECKPOINT=/path/to/checkpoints/sam_vit_h_4b8939.pth
export TRISAM_OUTPUT_DIR=/path/to/outputDefaults (if not set):
TRISAM_DATA_ROOT:./dataTRISAM_SAM_CHECKPOINT:./checkpoints/sam_vit_h_4b8939.pthTRISAM_OUTPUT_DIR:./outputs
Place the macaque dataset at:
${TRISAM_DATA_ROOT}/macaque_mpi_176-240nm.h5
The HDF5 file is expected to contain a dataset named main.
From the repo root:
python model/main.py macaque 0.98 0.8 "point+bbox" 0Arguments:
dataset: one ofmacaque,mouse_border,mouse_patcheta: initial segmentation threshold (float)tau: SAM probability threshold (float)prompt: prompt type, e.g.point,box, orpoint+bboxplane: plane index used formouse_border(ignored formacaque)
Outputs are written under TRISAM_OUTPUT_DIR (default: ./outputs).
CUDA_VISIBLE_DEVICESdefaults to0; override it if you want to target a different GPU.- Large volumes can take a long time to process; consider running on a dedicated GPU server.