### Install SAMExporter from Source Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Installs PyTorch for CPU and then clones the SAMExporter repository. It proceeds to install the package in editable mode after navigating into the cloned directory. ```bash pip install torch==2.10.0 torchvision==0.25.0 --index-url https://download.pytorch.org/whl/cpu git clone --recurse-submodules https://github.com/vietanhdev/samexporter cd samexporter pip install -e . ``` -------------------------------- ### Install SAMExporter and Dependencies Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Installs the necessary PyTorch version for CPU and the SAMExporter package. For Windows users needing model simplification, it shows how to install optional dependencies. ```bash pip install torch==2.10.0 torchvision==0.25.0 --index-url https://download.pytorch.org/whl/cpu pip install samexporter ``` ```bash pip install "samexporter[export]" ``` -------------------------------- ### Install SAMExporter and Dependencies Source: https://context7.com/vietanhdev/samexporter/llms.txt Installs the necessary PyTorch environment and the SAMExporter library via pip. ```bash pip install torch==2.10.0 torchvision==0.25.0 --index-url https://download.pytorch.org/whl/cpu pip install samexporter ``` -------------------------------- ### Install SAM2 PyTorch Dependencies Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Installs the official Segment Anything 2 package from the Facebook Research repository via pip. ```bash pip install git+https://github.com/facebookresearch/segment-anything-2.git ``` -------------------------------- ### Image Segmentation with Geometric Prompt Source: https://context7.com/vietanhdev/samexporter/llms.txt Example of using a geometric prompt, specifically a rectangle, to guide the mask prediction process in SAM. This snippet shows how to define the prompt and pass it to the model for segmentation. ```python # Optional: refine with geometric prompt (point or rectangle) prompt = [ {"type": "rectangle", "data": [100, 200, 600, 500]} ] # Predict masks with confidence threshold masks = model.predict_masks(embedding, prompt, confidence_threshold=0.5) # masks shape: (N, 1, H, W) - N detected instances, boolean masks # Visualize all detected instances mask_overlay = np.zeros_like(image) for i in range(masks.shape[0]): mask_overlay[masks[i, 0]] = [255, 0, 0] result = cv2.addWeighted(image, 0.5, mask_overlay, 0.5, 0) cv2.imwrite("sam3_output.png", result) ``` -------------------------------- ### Export SAM3 Models to ONNX Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Clones the SAM3 source, installs dependencies, and exports the model into three separate ONNX components: image encoder, language encoder, and decoder. ```bash git submodule update --init sam3 pip install osam python -m samexporter.export_sam3 --output_dir output_models/sam3 --opset 18 ``` -------------------------------- ### Run SAM3 Inference Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Executes inference for SAM3 using text, rectangle, or point prompts to guide the segmentation process. ```bash python -m samexporter.inference --sam_variant sam3 --encoder_model output_models/sam3/sam3_image_encoder.onnx --decoder_model output_models/sam3/sam3_decoder.onnx --language_encoder_model output_models/sam3/sam3_language_encoder.onnx --image images/truck.jpg --prompt images/truck_sam3.json --text_prompt "truck" --output output_images/truck_sam3.png --show ``` -------------------------------- ### Download SAM2 Checkpoints Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Downloads the required SAM2 model checkpoints into the original_models directory using a provided shell script. ```bash cd original_models && bash download_sam2.sh ``` -------------------------------- ### Run SAM/MobileSAM Inference Source: https://context7.com/vietanhdev/samexporter/llms.txt Demonstrates how to perform interactive segmentation using point and rectangle prompts with the SegmentAnythingONNX class. Requires pre-exported encoder and decoder ONNX models. ```bash python -m samexporter.inference \ --encoder_model output_models/sam_vit_h_4b8939.encoder.onnx \ --decoder_model output_models/sam_vit_h_4b8939.decoder.onnx \ --image images/truck.jpg \ --prompt images/truck_prompt.json \ --output output_images/truck.png \ --show ``` ```python import cv2 import numpy as np from samexporter.sam_onnx import SegmentAnythingONNX model = SegmentAnythingONNX( encoder_model_path="output_models/sam_vit_h_4b8939.encoder.onnx", decoder_model_path="output_models/sam_vit_h_4b8939.decoder.onnx" ) image = cv2.imread("images/truck.jpg") prompt = [ {"type": "point", "data": [575, 750], "label": 1}, {"type": "rectangle", "data": [425, 600, 700, 875]} ] embedding = model.encode(image) masks = model.predict_masks(embedding, prompt) mask_overlay = np.zeros((masks.shape[2], masks.shape[3], 3), dtype=np.uint8) for m in masks[0]: mask_overlay[m > 0.0] = [255, 0, 0] result = cv2.addWeighted(image, 0.5, mask_overlay, 0.5, 0) cv2.imwrite("output.png", result) ``` -------------------------------- ### Execute Batch Model Conversion Scripts Source: https://context7.com/vietanhdev/samexporter/llms.txt A collection of shell commands to trigger the conversion of various SAM model variants, including Meta SAM, MobileSAM, SAM2, and SAM3, into optimized ONNX formats. ```bash # Convert all Meta SAM models (ViT-B, ViT-L, ViT-H) bash convert_all_meta_sam.sh # Convert MobileSAM bash convert_mobile_sam.sh # Convert all SAM2 and SAM2.1 variants bash convert_all_meta_sam2.sh # Convert SAM3 bash convert_sam3.sh # Convert all models bash convert_all_models.sh ``` -------------------------------- ### Batch Convert All Meta SAM Models Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Executes shell scripts to batch convert all supported Meta SAM models to ONNX format. ```bash bash convert_all_meta_sam.sh ``` -------------------------------- ### Perform Inference with SegmentAnything3ONNX Source: https://context7.com/vietanhdev/samexporter/llms.txt This snippet demonstrates how to initialize the SAM3 ONNX model, encode an image with a text prompt, and predict segmentation masks. It covers both text-only detection and refinement using bounding box prompts. ```python from samexporter.sam3_onnx import SegmentAnything3ONNX import cv2 import numpy as np model = SegmentAnything3ONNX( "output_models/sam3/sam3_image_encoder.onnx", "output_models/sam3/sam3_decoder.onnx", "output_models/sam3/sam3_language_encoder.onnx" ) image = cv2.imread("street.jpg") # Detect all "person" instances embedding = model.encode(image, text_prompt="person") masks = model.predict_masks(embedding, [], confidence_threshold=0.6) print(f"Detected {masks.shape[0]} person(s)") # Refine with bounding box embedding = model.encode(image, text_prompt="car") prompt = [{"type": "rectangle", "data": [200, 150, 500, 400]}] car_masks = model.predict_masks(embedding, prompt) ``` -------------------------------- ### Run SAM2 Inference Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Executes inference using exported SAM2 ONNX models with a specified image and prompt file. ```bash python -m samexporter.inference --encoder_model output_models/sam2_hiera_tiny.encoder.onnx --decoder_model output_models/sam2_hiera_tiny.decoder.onnx --image images/truck.jpg --prompt images/truck_prompt.json --sam_variant sam2 --output output_images/sam2_truck.png --show ``` -------------------------------- ### Prompt JSON Format for SAM Inference Source: https://context7.com/vietanhdev/samexporter/llms.txt Illustrates the JSON structure for defining prompts used in SAM inference. It specifies the format for point, rectangle, and text prompts, including their data structures and usage notes. ```json [ {"type": "point", "data": [575, 750], "label": 1}, {"type": "point", "data": [200, 300], "label": 0}, {"type": "rectangle", "data": [425, 600, 700, 875]}, {"type": "text", "data": "object description"} ] ``` -------------------------------- ### Export SAM2 and SAM2.1 to ONNX Source: https://context7.com/vietanhdev/samexporter/llms.txt Converts SAM2/SAM2.1 models to ONNX. These models offer improved accuracy and hierarchical feature support. ```bash # Export SAM2 Tiny (fastest, good for CPU) python -m samexporter.export_sam2 \ --checkpoint original_models/sam2_hiera_tiny.pt \ --output_encoder output_models/sam2_hiera_tiny.encoder.onnx \ --output_decoder output_models/sam2_hiera_tiny.decoder.onnx \ --model_type sam2_hiera_tiny # Export SAM2 Large (most accurate) python -m samexporter.export_sam2 \ --checkpoint original_models/sam2_hiera_large.pt \ --output_encoder output_models/sam2_hiera_large.encoder.onnx \ --output_decoder output_models/sam2_hiera_large.decoder.onnx \ --model_type sam2_hiera_large # Export SAM2.1 (improved version) python -m samexporter.export_sam2 \ --checkpoint original_models/sam2.1_hiera_tiny.pt \ --output_encoder output_models/sam2.1_hiera_tiny.encoder.onnx \ --output_decoder output_models/sam2.1_hiera_tiny.decoder.onnx \ --model_type sam2.1_hiera_tiny # Export with ONNX simplification python -m samexporter.export_sam2 \ --checkpoint original_models/sam2_hiera_small.pt \ --output_encoder output_models/sam2_hiera_small.encoder.onnx \ --output_decoder output_models/sam2_hiera_small.decoder.onnx \ --model_type sam2_hiera_small \ --simplify ``` -------------------------------- ### Run SAM3 Text-Prompted Inference Source: https://context7.com/vietanhdev/samexporter/llms.txt Utilizes the SegmentAnything3ONNX class for open-vocabulary segmentation based on natural language text prompts. Requires image, decoder, and language encoder models. ```bash python -m samexporter.inference \ --sam_variant sam3 \ --encoder_model output_models/sam3/sam3_image_encoder.onnx \ --decoder_model output_models/sam3/sam3_decoder.onnx \ --language_encoder_model output_models/sam3/sam3_language_encoder.onnx \ --image images/truck.jpg \ --prompt images/truck_sam3.json \ --text_prompt "truck" \ --output output_images/truck_sam3.png \ --show ``` ```python import cv2 import numpy as np from samexporter.sam3_onnx import SegmentAnything3ONNX model = SegmentAnything3ONNX( image_encoder_path="output_models/sam3/sam3_image_encoder.onnx", decoder_model_path="output_models/sam3/sam3_decoder.onnx", language_encoder_path="output_models/sam3/sam3_language_encoder.onnx" ) image = cv2.imread("images/truck.jpg") embedding = model.encode(image, text_prompt="truck") ``` -------------------------------- ### Batch Convert Mobile SAM Model Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Executes a shell script to batch convert the Mobile SAM model to ONNX format. ```bash bash convert_mobile_sam.sh ``` -------------------------------- ### SegmentAnythingONNX: Image Encoding and Mask Prediction Source: https://context7.com/vietanhdev/samexporter/llms.txt Demonstrates how to initialize the SegmentAnythingONNX model, encode an image to generate embeddings, and predict segmentation masks using different prompt types like points and rectangles. The model supports multiple prompts for a single encoding. ```python from samexporter.sam_onnx import SegmentAnythingONNX import cv2 import numpy as np # Usage example model = SegmentAnythingONNX( "output_models/sam_vit_b_01ec64.encoder.onnx", "output_models/sam_vit_b_01ec64.decoder.onnx" ) image = cv2.imread("photo.jpg") embedding = model.encode(image) # Multiple prompt types in one call prompts = [ {"type": "point", "data": [100, 200], "label": 1}, # Foreground point {"type": "point", "data": [50, 50], "label": 0}, # Background point ] masks = model.predict_masks(embedding, prompts) # Different prompt for same image (no re-encoding needed) box_prompt = [{"type": "rectangle", "data": [50, 50, 300, 300]}] masks2 = model.predict_masks(embedding, box_prompt) ``` -------------------------------- ### Batch Model Conversion Scripts Source: https://context7.com/vietanhdev/samexporter/llms.txt Shell scripts provided for converting various Segment Anything model variants to ONNX format in batch. ```APIDOC ## Batch Model Conversion Scripts ### Description Shell scripts for converting all model variants at once. ### Scripts - **Convert all Meta SAM models (ViT-B, ViT-L, ViT-H)** ```bash bash convert_all_meta_sam.sh ``` - **Convert MobileSAM** ```bash bash convert_mobile_sam.sh ``` - **Convert all SAM2 and SAM2.1 variants** ```bash bash convert_all_meta_sam2.sh ``` - **Convert SAM3** ```bash bash convert_sam3.sh ``` - **Convert all models** ```bash bash convert_all_models.sh ``` ``` -------------------------------- ### Run SAM2/SAM2.1 Inference Source: https://context7.com/vietanhdev/samexporter/llms.txt Performs segmentation using the SegmentAnything2ONNX class, which leverages hierarchical features for improved accuracy. Supports point and bounding box prompts. ```bash python -m samexporter.inference \ --encoder_model output_models/sam2_hiera_tiny.encoder.onnx \ --decoder_model output_models/sam2_hiera_tiny.decoder.onnx \ --image images/truck.jpg \ --prompt images/truck_prompt.json \ --sam_variant sam2 \ --output output_images/sam2_truck.png \ --show ``` ```python import cv2 import numpy as np from samexporter.sam2_onnx import SegmentAnything2ONNX model = SegmentAnything2ONNX( encoder_model_path="output_models/sam2_hiera_tiny.encoder.onnx", decoder_model_path="output_models/sam2_hiera_tiny.decoder.onnx" ) image = cv2.imread("images/plants.png") prompt = [ {"type": "point", "data": [300, 400], "label": 1}, {"type": "rectangle", "data": [200, 300, 500, 600]} ] embedding = model.encode(image) masks = model.predict_masks(embedding, prompt) mask_overlay = np.zeros_like(image) mask_overlay[masks[0, 0] > 0.0] = [0, 255, 0] result = cv2.addWeighted(image, 0.6, mask_overlay, 0.4, 0) cv2.imwrite("sam2_output.png", result) ``` -------------------------------- ### Prompt JSON Schema Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Defines the structure for prompt files used during inference, supporting point, rectangle, and text types. ```json [ {"type": "point", "data": [x, y], "label": 1}, {"type": "rectangle", "data": [x1, y1, x2, y2]}, {"type": "text", "data": "object description"} ] ``` -------------------------------- ### Export SAM2 Models to ONNX Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Exports SAM2 or SAM2.1 PyTorch checkpoints into separate encoder and decoder ONNX models. ```bash python -m samexporter.export_sam2 --checkpoint original_models/sam2_hiera_tiny.pt --output_encoder output_models/sam2_hiera_tiny.encoder.onnx --output_decoder output_models/sam2_hiera_tiny.decoder.onnx --model_type sam2_hiera_tiny python -m samexporter.export_sam2 --checkpoint original_models/sam2.1_hiera_tiny.pt --output_encoder output_models/sam2.1_hiera_tiny.encoder.onnx --output_decoder output_models/sam2.1_hiera_tiny.decoder.onnx --model_type sam2.1_hiera_tiny ``` -------------------------------- ### Run SAM Inference with ONNX Models Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Performs image segmentation inference using exported ONNX encoder and decoder models. It takes an image, prompt data, and outputs the segmented image, with an option to display the result. ```bash python -m samexporter.inference \ --encoder_model output_models/sam_vit_h_4b8939.encoder.onnx \ --decoder_model output_models/sam_vit_h_4b8939.decoder.onnx \ --image images/truck.jpg \ --prompt images/truck_prompt.json \ --output output_images/truck.png \ --show ``` ```bash python -m samexporter.inference \ --encoder_model output_models/sam_vit_h_4b8939.encoder.onnx \ --decoder_model output_models/sam_vit_h_4b8939.decoder.onnx \ --image images/plants.png \ --prompt images/plants_prompt1.json \ --output output_images/plants_01.png \ --show ``` -------------------------------- ### Export SAM Decoder to ONNX Source: https://context7.com/vietanhdev/samexporter/llms.txt Converts the prompt encoder and mask decoder to ONNX. The decoder uses image embeddings and user prompts to generate segmentation masks. ```bash # Export decoder with single mask output (faster for high-res images) python -m samexporter.export_decoder \ --checkpoint original_models/sam_vit_h_4b8939.pth \ --output output_models/sam_vit_h_4b8939.decoder.onnx \ --model-type vit_h \ --quantize-out output_models/sam_vit_h_4b8939.decoder.quant.onnx \ --return-single-mask # Export decoder with multiple mask proposals python -m samexporter.export_decoder \ --checkpoint original_models/sam_vit_h_4b8939.pth \ --output output_models/sam_vit_h_4b8939.decoder.onnx \ --model-type vit_h \ --quantize-out output_models/sam_vit_h_4b8939.decoder.quant.onnx # Export with stability score instead of predicted quality python -m samexporter.export_decoder \ --checkpoint original_models/sam_vit_h_4b8939.pth \ --output output_models/sam_vit_h_4b8939.decoder.onnx \ --model-type vit_h \ --use-stability-score ``` -------------------------------- ### Export SAM Decoder to ONNX Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Exports the decoder component of a SAM model to ONNX format. This script allows for quantization and can be configured to return a single mask or multiple mask proposals. ```bash python -m samexporter.export_decoder \ --checkpoint original_models/sam_vit_h_4b8939.pth \ --output output_models/sam_vit_h_4b8939.decoder.onnx \ --model-type vit_h \ --quantize-out output_models/sam_vit_h_4b8939.decoder.quant.onnx \ --return-single-mask ``` -------------------------------- ### Export SAM3 to ONNX Source: https://context7.com/vietanhdev/samexporter/llms.txt Converts SAM3 models to ONNX. SAM3 supports text-driven open-vocabulary segmentation. ```bash # Basic SAM3 export (image encoder, language encoder, decoder) python -m samexporter.export_sam3 \ --output_dir output_models/sam3 \ --opset 18 # Export with ONNX simplification python -m samexporter.export_sam3 \ --output_dir output_models/sam3 \ --opset 18 \ --simplify ``` -------------------------------- ### SegmentAnything2ONNX: Hierarchical Feature Mask Prediction Source: https://context7.com/vietanhdev/samexporter/llms.txt Shows the usage of the SegmentAnything2ONNX class for image segmentation with SAM2 models. It covers initializing the model, encoding images to obtain hierarchical features, and predicting masks using rectangle prompts. The output can be converted to a binary mask. ```python from samexporter.sam2_onnx import SegmentAnything2ONNX import cv2 import numpy as np # Usage example model = SegmentAnything2ONNX( "output_models/sam2_hiera_tiny.encoder.onnx", "output_models/sam2_hiera_tiny.decoder.onnx" ) image = cv2.imread("scene.jpg") embedding = model.encode(image) prompt = [{"type": "rectangle", "data": [100, 100, 400, 400]}] masks = model.predict_masks(embedding, prompt) # Binary mask from logits binary_mask = masks[0, 0] > 0.0 ``` -------------------------------- ### Export SAM Encoder to ONNX Source: https://github.com/vietanhdev/samexporter/blob/main/README.md Exports the encoder component of a SAM model (e.g., ViT-H or ViT-B) to ONNX format. It supports quantization and preprocessing options, taking the original checkpoint and output paths as arguments. ```bash python -m samexporter.export_encoder \ --checkpoint original_models/sam_vit_h_4b8939.pth \ --output output_models/sam_vit_h_4b8939.encoder.onnx \ --model-type vit_h \ --quantize-out output_models/sam_vit_h_4b8939.encoder.quant.onnx \ --use-preprocess ``` ```bash python -m samexporter.export_encoder \ --checkpoint original_models/sam_vit_b_01ec64.pth \ --output output_models/sam_vit_b_01ec64.encoder.onnx \ --model-type vit_b \ --quantize-out output_models/sam_vit_b_01ec64.encoder.quant.onnx \ --use-preprocess ``` -------------------------------- ### Export SAM Image Encoder to ONNX Source: https://context7.com/vietanhdev/samexporter/llms.txt Converts the SAM image encoder to ONNX format. This process generates embeddings from images, which can be reused for multiple prompt-based segmentation tasks. ```bash # Export SAM ViT-H encoder (most accurate) python -m samexporter.export_encoder \ --checkpoint original_models/sam_vit_h_4b8939.pth \ --output output_models/sam_vit_h_4b8939.encoder.onnx \ --model-type vit_h \ --quantize-out output_models/sam_vit_h_4b8939.encoder.quant.onnx \ --use-preprocess # Export SAM ViT-B encoder (fastest) python -m samexporter.export_encoder \ --checkpoint original_models/sam_vit_b_01ec64.pth \ --output output_models/sam_vit_b_01ec64.encoder.onnx \ --model-type vit_b \ --quantize-out output_models/sam_vit_b_01ec64.encoder.quant.onnx \ --use-preprocess # Export MobileSAM encoder (lightweight, fast on CPU) python -m samexporter.export_encoder \ --checkpoint original_models/mobile_sam.pt \ --output output_models/mobile_sam.encoder.onnx \ --model-type mobile \ --quantize-out output_models/mobile_sam.encoder.quant.onnx \ --use-preprocess ``` -------------------------------- ### SegmentAnything2ONNX API Source: https://context7.com/vietanhdev/samexporter/llms.txt The SegmentAnything2ONNX class provides inference capabilities for SAM2 models, utilizing hierarchical features for improved segmentation. ```APIDOC ## SegmentAnything2ONNX.encode ### Description Encodes an image into hierarchical features specifically for SAM2 models. ### Method Python Method ### Parameters - **cv_image** (np.ndarray) - Required - BGR image array. ### Response - **dict** - Contains keys: high_res_feats_0, high_res_feats_1, image_embedding, original_size ## SegmentAnything2ONNX.predict_masks ### Description Predicts masks using hierarchical features for high-quality segmentation. ### Method Python Method ### Parameters - **embedding** (dict) - Required - Hierarchical feature dictionary from encode. - **prompt** (list) - Required - List of prompt dictionaries. ### Response - **np.ndarray** - Best mask array of shape (1, 1, H, W). ``` -------------------------------- ### SegmentAnything3ONNX Class Source: https://context7.com/vietanhdev/samexporter/llms.txt Inference class for SAM3 with text-driven open-vocabulary segmentation capabilities. This class allows encoding images and text prompts, and then predicting segmentation masks based on embeddings and various prompt types. ```APIDOC ## SegmentAnything3ONNX Class ### Description Inference class for SAM3 with text-driven open-vocabulary segmentation capabilities. ### Class Definition ```python from samexporter.sam3_onnx import SegmentAnything3ONNX import cv2 import numpy as np class SegmentAnything3ONNX: """Segmentation model using Segment Anything 3 (SAM3)""" def __init__( self, image_encoder_path: str, decoder_model_path: str, language_encoder_path: str = None ) -> None: """Initialize with image encoder, decoder, and optional language encoder.""" def encode(self, cv_image: np.ndarray, text_prompt: str = None) -> dict: """ Encode image and optional text prompt. Args: cv_image: BGR image from cv2.imread() text_prompt: Natural language description (e.g., "red car") Returns: dict with vision features, backbone features, and language features """ def predict_masks( self, embedding: dict, prompt: list, confidence_threshold: float = 0.5 ) -> np.ndarray: """ Predict masks for detected objects. Returns: Boolean mask array of shape (N, 1, H, W) for N detected objects """ ``` ### Usage Example - Text-Only Detection ```python # Usage example - text-only detection model = SegmentAnything3ONNX( "output_models/sam3/sam3_image_encoder.onnx", "output_models/sam3/sam3_decoder.onnx", "output_models/sam3/sam3_language_encoder.onnx" ) image = cv2.imread("street.jpg") # Detect all "person" instances embedding = model.encode(image, text_prompt="person") masks = model.predict_masks(embedding, [], confidence_threshold=0.6) print(f"Detected {masks.shape[0]} person(s)") ``` ### Usage Example - Refine with Bounding Box ```python # Refine with bounding box embedding = model.encode(image, text_prompt="car") prompt = [{"type": "rectangle", "data": [200, 150, 500, 400]}] car_masks = model.predict_masks(embedding, prompt) ``` ``` -------------------------------- ### SegmentAnythingONNX API Source: https://context7.com/vietanhdev/samexporter/llms.txt The SegmentAnythingONNX class handles image encoding and mask prediction for standard SAM models. ```APIDOC ## SegmentAnythingONNX.encode ### Description Encodes a BGR image into embeddings required for mask prediction. ### Method Python Method ### Parameters - **cv_image** (np.ndarray) - Required - BGR image array from cv2.imread() ### Response - **dict** - Contains keys: image_embedding, original_size, transform_matrix ## SegmentAnythingONNX.predict_masks ### Description Predicts segmentation masks based on provided prompts and pre-computed embeddings. ### Method Python Method ### Parameters - **embedding** (dict) - Required - The output from the encode method. - **prompt** (list) - Required - List of prompt dictionaries (type, data, label). ### Response - **np.ndarray** - Mask array of shape (1, 3, H, W) containing raw logits. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.