### Install Supervoxel Module (Subdirectory) Source: https://github.com/mic-dkfz/nninteractive/blob/master/AGENTS.md Navigate to the supervoxel subdirectory and perform an editable installation. ```bash cd nnInteractive/supervoxel/src/sam2 && pip install -e . ``` -------------------------------- ### Install nnInteractive Repository Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Installs the nnInteractive repository either via pip or by cloning and installing from source. ```bash pip install nninteractive ``` ```bash git clone https://github.com/MIC-DKFZ/nnInteractive cd nnInteractive pip install -e . ``` -------------------------------- ### Install SAM 2 with Notebook Support Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md Use this command to install SAM 2 and its dependencies for notebook usage. Ensure Python and PyTorch are installed beforehand. ```bash pip install -e ".[notebooks]" ``` -------------------------------- ### Install Supervoxel Module (Top-level) Source: https://github.com/mic-dkfz/nninteractive/blob/master/AGENTS.md Navigate to the supervoxel directory and perform an editable installation. ```bash cd nnInteractive/supervoxel && pip install -e . ``` -------------------------------- ### Install SAM 2 Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/README.md Clone the SAM 2 repository and install it using pip. Ensure you have Python 3.10+ and PyTorch 2.5.1+ installed. ```bash git clone https://github.com/facebookresearch/sam2.git && cd sam2 pip install -e . ``` -------------------------------- ### Editable Install with Dev Tools Source: https://github.com/mic-dkfz/nninteractive/blob/master/AGENTS.md Install the core package along with formatter and linter tooling for development. ```bash pip install -e ".[dev]" ``` -------------------------------- ### Editable Install Core Package Source: https://github.com/mic-dkfz/nninteractive/blob/master/AGENTS.md Use this command for editable installation of the core package during development. ```bash pip install -e . ``` -------------------------------- ### Install nnInteractive SuperVoxel Dependencies Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/README.md Install the modified SAM2 and the SuperVoxel repository. Ensure you are in the correct directories before running pip install. ```bash cd src/sam2/ pip install -e . cd ../.. pip install -e . ``` -------------------------------- ### Install SAM 2 Without Build Isolation Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md Use the `--no-build-isolation` flag with pip if installation fails even after verifying CUDA setup. This can sometimes resolve issues related to build environments. ```bash pip install --no-build-isolation -e . ``` -------------------------------- ### Verify PyTorch CUDA Setup Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md Confirm that PyTorch can detect your CUDA installation and that the CUDA_HOME variable is correctly set. This check is essential before proceeding with CUDA-dependent installations. ```python import torch; from torch.utils.cpp_extension import CUDA_HOME; print(torch.cuda.is_available(), CUDA_HOME) ``` -------------------------------- ### Launch Multi-Node Training with SLURM Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/training/README.md Initiate multi-node training on a cluster using SLURM. This example configures training across 2 nodes, each with 8 GPUs, and includes optional SLURM parameters. ```python python training/train.py \ -c configs/sam2.1_training/sam2.1_hiera_b+_MOSE_finetune.yaml \ --use-cluster 1 \ --num-gpus 8 \ --num-nodes 2 --partition $PARTITION \ --qos $QOS \ --account $ACCOUNT ``` -------------------------------- ### Install PyTorch with CUDA Support Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Installs PyTorch with CUDA support for Ubuntu systems with Nvidia GPUs. Adjust CUDA version based on your drivers. ```bash pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu126 ``` -------------------------------- ### Load SAM 2 Video Predictor from Hugging Face Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/README.md Loads the SAM 2 video predictor directly from Hugging Face. Requires the `huggingface_hub` library to be installed. ```python import torch from sam2.sam2_video_predictor import SAM2VideoPredictor predictor = SAM2VideoPredictor.from_pretrained("facebook/sam2-hiera-large") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): state = predictor.init_state() # add new prompts and instantly get the output on the same frame frame_idx, object_ids, masks = predictor.add_new_points_or_box(state, ): # propagate the prompts to get masklets throughout the video for frame_idx, object_ids, masks in predictor.propagate_in_video(state): ... ``` -------------------------------- ### Load SAM 2 Image Predictor from Hugging Face Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/README.md Loads the SAM 2 image predictor directly from Hugging Face. Requires the `huggingface_hub` library to be installed. ```python import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained("facebook/sam2-hiera-large") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): predictor.set_image() masks, _, _ = predictor.predict() ``` -------------------------------- ### Create Conda Virtual Environment Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Creates and activates a new Conda virtual environment for nnInteractive. Ensure Python 3.10+ is installed. ```bash conda create -n nnInteractive python=3.12 conda activate nnInteractive ``` -------------------------------- ### Force Build SAM 2 CUDA Extension Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md Reinstall SAM 2 and force the build of the CUDA extension by setting SAM2_BUILD_ALLOW_ERRORS to 0. This will raise errors if the build fails. Ensure PyTorch and matching CUDA toolkits are installed first. ```bash pip uninstall -y SAM-2 && \ rm -f ./sam2/*.so && \ SAM2_BUILD_ALLOW_ERRORS=0 pip install -v -e ".[notebooks]" ``` -------------------------------- ### Install SAM 2 Skipping CUDA Extension Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md Install SAM 2 without building the CUDA extension by setting the SAM2_BUILD_CUDA environment variable to 0. This skips the post-processing step at runtime. ```bash SAM2_BUILD_CUDA=0 pip install -e ".[notebooks]" ``` -------------------------------- ### Verify SAM 2 Base Module Path Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md Check if the `sam2_base.py` file is up-to-date by printing its path and comparing it with the latest version in the repository. This helps identify if an outdated installation is causing errors. ```python from sam2.modeling import sam2_base print(sam2_base.__file__) ``` -------------------------------- ### SAM 2 Image Prediction Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/README.md Initialize the SAM2ImagePredictor with a specified model configuration and checkpoint, then set an image and perform prediction with input prompts. This example requires PyTorch and runs in inference mode with CUDA and bfloat16 precision. ```python import torch from sam2.build_sam import build_sam2 from sam2.sam2_image_predictor import SAM2ImagePredictor checkpoint = "./checkpoints/sam2.1_hiera_large.pt" model_cfg = "configs/sam2.1/sam2.1_hiera_l.yaml" predictor = SAM2ImagePredictor(build_sam2(model_cfg, checkpoint)) with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): predictor.set_image() masks, _, _ = predictor.predict() ``` -------------------------------- ### Specify CUDA Capability for Compilation Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md Use this command to manually specify the CUDA capability when compiling to match your GPU, especially if the installation environment differs from the runtime environment. ```bash export TORCH_CUDA_ARCH_LIST=9.0 8.0 8.6 8.9 7.0 7.2 7.5 6.0 ``` -------------------------------- ### Set CUDA Home Environment Variable Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md Explicitly set the CUDA_HOME environment variable to the path of your CUDA toolkit installation if the build process cannot find it. This is crucial for compiling CUDA kernels. ```bash export CUDA_HOME=/usr/local/cuda # change to your CUDA toolkit path ``` -------------------------------- ### Initialize nnInteractive Inference Session Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Sets up an nnInteractive inference session, downloads model weights, and loads the trained model. Ensure the download directory exists and has sufficient space. ```python import os import torch import SimpleITK as sitk from huggingface_hub import snapshot_download # Install huggingface_hub if not already installed # --- Download Trained Model Weights (~400MB) --- # License reminder: The official nnInteractive checkpoint is licensed under # Creative Commons Attribution Non Commercial Share Alike 4.0 (CC BY-NC-SA 4.0). # See the License section of this readme!. REPO_ID = "nnInteractive/nnInteractive" MODEL_NAME = "nnInteractive_v1.0" # Updated models may be available in the future DOWNLOAD_DIR = "/home/isensee/temp" # Specify the download directory download_path = snapshot_download( repo_id=REPO_ID, allow_patterns=[f"{MODEL_NAME}/*"], local_dir=DOWNLOAD_DIR ) # The model is now stored in DOWNLOAD_DIR/MODEL_NAME. # --- Initialize Inference Session --- from nnInteractive.inference.inference_session import nnInteractiveInferenceSession session = nnInteractiveInferenceSession( device=torch.device("cuda:0"), # Set inference device use_torch_compile=False, # Experimental: Not tested yet verbose=False, torch_n_threads=os.cpu_count(), # Use available CPU cores do_autozoom=True, # Enables AutoZoom for better patching use_pinned_memory=True, # Optimizes GPU memory transfers ) # Load the trained model model_path = os.path.join(DOWNLOAD_DIR, MODEL_NAME) session.initialize_from_trained_model_folder(model_path) # --- Load Input Image (Example with SimpleITK) --- # DO NOT preprocess the image in any way. Give it to nnInteractive as it is! DO NOT apply level window, DO NOT normalize # intensities and never ever convert an image with higher precision (float32, uint16, etc) to uint8! # The ONLY instance where some preprocesing makes sense is if your original image is too large to be reasonably used. # This may be the case, for example, for some microCT images. In this case you can consider downsampling. input_image = sitk.ReadImage("FILENAME") img = sitk.GetArrayFromImage(input_image)[None] # Ensure shape (1, x, y, z) # Validate input dimensions if img.ndim != 4: raise ValueError("Input image must be 4D with shape (1, x, y, z)") session.set_image(img) ``` -------------------------------- ### Generate nnUNet-Compatible Foreground Prompts Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/README.md Create .pkl files containing foreground locations from generated supervoxels for nnUNet training. Specify the supervoxel mask folder and the number of parallel processes. ```bash SuperVoxel_save_fg_location \ -supervoxel_folder /path/to/supervoxel/masks \ -np 4 # number of parallel processes ``` -------------------------------- ### Initialize and Use Video Predictor Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/README.md This snippet shows how to initialize the SAM 2 video predictor, add prompts, and propagate masks throughout a video. ```APIDOC ## Initialize and Use Video Predictor ### Description This example demonstrates initializing the SAM 2 video predictor, setting up the inference state, adding new prompts (points or boxes) to a frame, and then propagating these prompts to generate masks throughout the video. ### Usage ```python import torch from sam2.build_sam import build_sam2_video_predictor checkpoint = "./checkpoints/sam2.1_hiera_large.pt" model_cfg = "configs/sam2.1/sam2.1_hiera_l.yaml" predictor = build_sam2_video_predictor(model_cfg, checkpoint) with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): # Initialize the state with your video data state = predictor.init_state() # Add new prompts (points or boxes) to the current frame and get immediate output frame_idx, object_ids, masks = predictor.add_new_points_or_box(state, ) # Propagate the prompts to generate masklets throughout the video for frame_idx, object_ids, masks in predictor.propagate_in_video(state): # Process the masks for each frame ... ``` ### Parameters - `state`: The inference state object, initialized by `init_state`. - ``: Placeholder for the video data to be processed. - ``: Placeholder for the user-provided prompts (e.g., points, boxes). ``` -------------------------------- ### Run All Pre-commit Hooks Source: https://github.com/mic-dkfz/nninteractive/blob/master/AGENTS.md Execute all configured pre-commit hooks locally to ensure code quality and consistency before committing. ```bash pre-commit run --all-files ``` -------------------------------- ### Launch Single-Node Training Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/training/README.md Execute the training script for single-node fine-tuning on the MOSE dataset using 8 GPUs. The '--use-cluster 0' flag indicates non-cluster execution. ```python python training/train.py \ -c configs/sam2.1_training/sam2.1_hiera_b+_MOSE_finetune.yaml \ --use-cluster 0 \ --num-gpus 8 ``` -------------------------------- ### Initialize SAM 2 Video Predictor from Checkpoint Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/README.md Initializes the SAM 2 video predictor using a local checkpoint and configuration file. Ensure you have the necessary checkpoint and model configuration files. ```python import torch from sam2.build_sam import build_sam2_video_predictor checkpoint = "./checkpoints/sam2.1_hiera_large.pt" model_cfg = "configs/sam2.1/sam2.1_hiera_l.yaml" predictor = build_sam2_video_predictor(model_cfg, checkpoint) ``` -------------------------------- ### Set New Image and Target Buffer Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Load a new image and set a corresponding target buffer. The new target buffer must match the shape of the new image. ```python session.set_image(NEW_IMAGE) session.set_target_buffer(torch.zeros(NEW_IMAGE.shape[1:], dtype=torch.uint8)) ``` -------------------------------- ### Configure Mixed Image and Video Datasets for Training Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/training/README.md Use this configuration to train on a mix of image and video datasets. Ensure SA-V videos are extracted to JPEG frames beforehand. Adjust paths and parameters as needed. ```yaml data: train: _target_: training.dataset.sam2_datasets.TorchTrainMixedDataset phases_per_epoch: ${phases_per_epoch} # Chunks a single epoch into smaller phases batch_sizes: # List of batch sizes corresponding to each dataset - ${bs1} # Batch size of dataset 1 - ${bs2} # Batch size of dataset 2 datasets: # SA1B as an example of an image dataset - _target_: training.dataset.vos_dataset.VOSDataset training: true video_dataset: _target_: training.dataset.vos_raw_dataset.SA1BRawDataset img_folder: ${path_to_img_folder} gt_folder: ${path_to_gt_folder} file_list_txt: ${path_to_train_filelist} # Optional sampler: _target_: training.dataset.vos_sampler.RandomUniformSampler num_frames: 1 max_num_objects: ${max_num_objects_per_image} transforms: ${image_transforms} # SA-V as an example of a video dataset - _target_: training.dataset.vos_dataset.VOSDataset training: true video_dataset: _target_: training.dataset.vos_raw_dataset.JSONRawDataset img_folder: ${path_to_img_folder} gt_folder: ${path_to_gt_folder} file_list_txt: ${path_to_train_filelist} # Optional ann_every: 4 sampler: _target_: training.dataset.vos_sampler.RandomUniformSampler num_frames: 8 # Number of frames per video max_num_objects: ${max_num_objects_per_video} reverse_time_prob: ${reverse_time_prob} # probability to reverse video transforms: ${video_transforms} shuffle: True num_workers: ${num_train_workers} pin_memory: True drop_last: True collate_fn: _target_: training.utils.data_utils.collate_fn _partial_: true dict_key: all ``` -------------------------------- ### Download SAM 2 Checkpoints Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/README.md Download all model checkpoints for SAM 2 by running the provided shell script in the checkpoints directory. ```bash cd checkpoints && \ ./download_ckpts.sh && \ cd .. ``` -------------------------------- ### Configure MOSE Dataset Paths Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/training/README.md Set the paths for the MOSE dataset within the configuration file. Ensure 'img_folder' and 'gt_folder' point to the correct dataset locations. ```yaml dataset: # PATHS to Dataset img_folder: null # PATH to MOSE JPEGImages folder gt_folder: null # PATH to MOSE Annotations folder file_list_txt: null # Optional PATH to filelist containing a subset of videos to be used for training ``` -------------------------------- ### Rebuild SAM 2 Extensions In-Place Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md If you encounter import errors, try rebuilding the SAM 2 extensions in the repository root. This command compiles C++ extensions locally. ```bash python setup.py build_ext --inplace ``` -------------------------------- ### Configure Experiment Log Directory Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/training/README.md Specify a custom path for the experiment log directory. If set to null, logs default to './sam2_logs/${config_name}'. ```yaml experiment_log_dir: null # Path to log directory, defaults to ./sam2_logs/${config_name} ``` -------------------------------- ### Add -allow-unsupported-compiler Argument Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md Add the '-allow-unsupported-compiler' argument to `nvcc` in `setup.py` to fix compilation errors caused by incompatible CUDA and Visual Studio versions. ```python compile_args = { "cxx": [], "nvcc": [ "-DCUDA_HAS_FP16=1", "-D__CUDA_NO_HALF_OPERATORS__", "-D__CUDA_NO_HALF_CONVERSIONS__", "-D__CUDA_NO_HALF2_OPERATORS__", "-allow-unsupported-compiler" # Add this argument ], } ``` -------------------------------- ### Format Python Code Source: https://github.com/mic-dkfz/nninteractive/blob/master/AGENTS.md Format Python code in the nnInteractive directory using Black. ```bash black nnInteractive/ ``` -------------------------------- ### Add SAM 2 Repository to PYTHONPATH Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md Manually add the SAM 2 repository root to your PYTHONPATH environment variable if the `sam2` package is not found. This ensures Python can locate configuration files. ```bash export SAM2_REPO_ROOT=/path/to/sam2 # path to this repo export PYTHONPATH="${SAM2_REPO_ROOT}:${PYTHONPATH}" ``` -------------------------------- ### Generate SuperVoxels Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/README.md Command to generate supervoxels from input images. Specify input image directory, output folder, and configuration file path. This process is compute and VRAM intensive. ```bash SuperVoxel_generate \ -i /path/to/input/images \ -o /path/to/output/folder \ -c /path/to/config.yaml ``` -------------------------------- ### Video Prediction with Prompts and Propagation Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/README.md Performs video prediction by initializing state, adding prompts, and propagating masks throughout the video. Uses inference mode and autocast for performance. ```python with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): state = predictor.init_state() # add new prompts and instantly get the output on the same frame frame_idx, object_ids, masks = predictor.add_new_points_or_box(state, ): # propagate the prompts to get masklets throughout the video for frame_idx, object_ids, masks in predictor.propagate_in_video(state): ... ``` -------------------------------- ### Load Video Predictor from Hugging Face Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/README.md Load the SAM 2 video predictor directly from Hugging Face model repository. ```APIDOC ## Load Video Predictor from Hugging Face ### Description This example shows how to load a pre-trained SAM 2 video predictor model directly from the Hugging Face Hub using the `from_pretrained` method. This simplifies the process of getting started with video prediction. ### Usage ```python import torch from sam2.sam2_video_predictor import SAM2VideoPredictor # Load the predictor from Hugging Face predictor = SAM2VideoPredictor.from_pretrained("facebook/sam2-hiera-large") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): # Initialize the state with your video data state = predictor.init_state() # Add new prompts and propagate masks as shown in the previous example frame_idx, object_ids, masks = predictor.add_new_points_or_box(state, ) for frame_idx, object_ids, masks in predictor.propagate_in_video(state): ... ``` ### Parameters - `"facebook/sam2-hiera-large"`: The identifier for the SAM 2 model on Hugging Face Hub. ``` -------------------------------- ### Relax Attention Kernel Settings Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md Replace the line in `transformer.py` to relax attention kernel settings and use kernels other than Flash Attention, which can resolve 'RuntimeError: No available kernel' errors. ```python OLD_GPU, USE_FLASH_ATTN, MATH_KERNEL_ON = True, True, True ``` -------------------------------- ### Add Scribble Interaction Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Incorporate a scribble interaction using a 3D image where a single slice contains a hand-drawn scribble (background 0, scribble 1). Use session.preferred_scribble_thickness for optimal results. ```python session.add_scribble_interaction(SCRIBBLE_IMAGE, include_interaction=True) ``` -------------------------------- ### Lint and Auto-fix Python Code Source: https://github.com/mic-dkfz/nninteractive/blob/master/AGENTS.md Run Ruff lint checks on the nnInteractive directory and automatically fix issues where possible. ```bash ruff check nnInteractive/ --fix ``` -------------------------------- ### Retrieve Segmentation Results Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Obtain the segmentation results by cloning the target buffer. Cloning is necessary as the buffer will be reused for subsequent objects. ```python # The target buffer holds the segmentation result. results = session.target_buffer.clone() # OR (equivalent) results = target_tensor.clone() # Cloning is required because the buffer will be **reused** for the next object. # Alternatively, set a new target buffer for each object: session.set_target_buffer(torch.zeros(img.shape[1:], dtype=torch.uint8)) ``` -------------------------------- ### Define Output Buffer for Segmentation Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Initialize a zero-filled tensor with the same shape as the input image (excluding channels) and specify the data type as uint8. This tensor will serve as the target buffer for segmentation masks. ```python target_tensor = torch.zeros(img.shape[1:], dtype=torch.uint8) # Must be 3D (x, y, z) session.set_target_buffer(target_tensor) ``` -------------------------------- ### Check Spelling in Source/Docs Source: https://github.com/mic-dkfz/nninteractive/blob/master/AGENTS.md Use codespell to check for spelling errors in source code and documentation, skipping specified file types. ```bash codespell --skip='.git,*.pdf,*.svg' ``` -------------------------------- ### Add Lasso Interaction Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Incorporate a lasso interaction using a 3D image with a single slice containing a closed contour representing the selection. ```python session.add_lasso_interaction(LASSO_IMAGE, include_interaction=True) ``` -------------------------------- ### Modify PyTorch Version Restriction Source: https://github.com/mic-dkfz/nninteractive/blob/master/nnInteractive/supervoxel/src/sam2/INSTALL.md If facing dependency conflicts related to PyTorch versions, consider changing the version restriction in `pyproject.toml` and `setup.py` to `torch==2.1.0`. This may resolve issues caused by incompatible PyTorch versions. ```toml torch==2.1.0 ``` -------------------------------- ### Reset Interactions for New Object Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Clear the target buffer and reset all interactions to begin segmenting a new object. ```python session.reset_interactions() # Clears the target buffer and resets interactions ``` -------------------------------- ### Add Bounding Box Interaction Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Incorporate a bounding box interaction for segmentation refinement. BBOX_COORDINATES should be [[x1, x2], [y1, y2], [z1, z2]]. Note that current pre-trained models primarily support 2D bounding boxes, requiring one dimension to be [d, d+1]. ```python # Example of a 2D bounding box in the axial plane (XY slice at depth Z) # BBOX_COORDINATES = [[30, 80], [40, 100], [10, 11]] # X: 30-80, Y: 40-100, Z: slice 10 session.add_bbox_interaction(BBOX_COORDINATES, include_interaction=True) ``` -------------------------------- ### Add Negative Point Interaction Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Add a negative point interaction by setting include_interaction=False. This helps exclude areas from the segmentation. ```python session.add_point_interaction(POINT_COORDINATES, include_interaction=False) ``` -------------------------------- ### Add Positive Point Interaction Source: https://github.com/mic-dkfz/nninteractive/blob/master/readme.md Incorporate a positive point interaction to refine the segmentation mask. Ensure POINT_COORDINATES is a tuple (x, y, z) representing the point's location. ```python session.add_point_interaction(POINT_COORDINATES, include_interaction=True) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.