Build an automated image segmentation pipeline using Segment Anything Model 2 with prompt engineering, batch processing, and export.
You are a computer vision engineer. Build a SAM 2 segmentation automation pipeline. ## Configuration - **Model**: [MODEL e.g. sam2-hiera-large / sam2-hiera-base+] - **Input**: [INPUT e.g. directory of images / video frames / webcam stream] - **Prompt Type**: [PROMPT e.g. point prompts / box prompts / text prompts / automatic] - **Output Format**: [OUTPUT e.g. COCO JSON / binary masks / colored overlays / polygon coordinates] - **Use Case**: [USE_CASE e.g. medical imaging / autonomous driving / quality inspection / agriculture] ## Pipeline Components ### 1. Model Setup (`model/`) - Load SAM 2 with [MODEL] weights - GPU memory optimization with model quantization - Batch inference configuration - ONNX export for edge deployment ### 2. Prompt Generation (`prompts/`) - **Automatic mode**: Generate point grid prompts across image - **Interactive mode**: Accept click/box prompts from UI - **Text mode**: Use CLIP-based text-to-point mapping - **Object detection mode**: Use YOLO detections as box prompts - Smart prompt selection: identify optimal prompt points based on edge detection ### 3. Segmentation Engine (`segment/`) - Single image segmentation with multiple masks per prompt - Batch processing with multi-GPU support - Video segmentation with temporal consistency - Mask refinement: morphological operations, hole filling, smoothing - Mask filtering: area threshold, confidence threshold, IoU deduplication ### 4. Post-Processing (`postprocess/`) - Convert masks to [OUTPUT] format - Mask-to-polygon conversion with simplification - Instance separation and labeling - Mask composition and visualization - Area and perimeter measurement - Export annotations for training other models ### 5. Application Layer (`app/`) - Streamlit UI for interactive segmentation - REST API for programmatic access - Webhook notifications for batch completion - Result gallery with side-by-side comparison Provide complete code with example images and performance benchmarks.
Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Gemini 2.5 Pro.
Download SAM 2 weights and set the model path. Prepare your input images in a directory. Choose your prompt type based on use case. Run batch processing and review results in the Streamlit UI.
Initial release
Sign in and download this prompt to leave a review.