Image Segmentation
PyTorch
sam2
English
computer-vision
segmentation
few-shot-learning
zero-shot-learning
clip
Instructions to use ParallelLLC/Segmentation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sam2
How to use ParallelLLC/Segmentation with sam2:
# Use SAM2 with images import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained(ParallelLLC/Segmentation) with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): predictor.set_image(<your_image>) masks, _, _ = predictor.predict(<input_prompts>)# Use SAM2 with videos import torch from sam2.sam2_video_predictor import SAM2VideoPredictor predictor = SAM2VideoPredictor.from_pretrained(ParallelLLC/Segmentation) with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): state = predictor.init_state(<your_video>) # add new prompts and instantly get the output on the same frame frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>): # propagate the prompts to get masklets throughout the video for frame_idx, object_ids, masks in predictor.propagate_in_video(state): ... - Notebooks
- Google Colab
- Kaggle
SAM 2 Few-Shot/Zero-Shot Segmentation Research
This repository contains research on combining Segment Anything Model 2 (SAM 2) with minimal supervision for domain-specific segmentation tasks.
Research Overview
The goal is to study how SAM 2 can be adapted to new object categories in specific domains (satellite imagery, fashion, robotics) using:
- Few-shot learning: 1-10 labeled examples per class
- Zero-shot learning: No labeled examples, using text prompts and visual similarity
Key Research Areas
1. Domain Adaptation
- Satellite Imagery: Buildings, roads, vegetation, water bodies
- Fashion: Clothing items, accessories, patterns
- Robotics: Industrial objects, tools, safety equipment
2. Learning Paradigms
- Prompt Engineering: Optimizing text prompts for SAM 2
- Visual Similarity: Using CLIP embeddings for zero-shot transfer
- Meta-learning: Learning to adapt quickly to new domains
3. Evaluation Metrics
- IoU (Intersection over Union)
- Dice Coefficient
- Boundary Accuracy
- Domain-specific metrics
Project Structure
βββ data/ # Dataset storage
βββ models/ # Model implementations
βββ experiments/ # Experiment configurations
βββ utils/ # Utility functions
βββ notebooks/ # Jupyter notebooks for analysis
βββ results/ # Experiment results and visualizations
βββ requirements.txt # Dependencies
Quick Start
Install dependencies:
pip install -r requirements.txtDownload SAM 2:
python scripts/download_sam2.pyRun few-shot experiment:
python experiments/few_shot_satellite.pyRun zero-shot experiment:
python experiments/zero_shot_fashion.py
Research Papers
This work builds upon:
- SAM 2: Segment Anything Model 2
- CLIP: Learning Transferable Visual Representations
- Few-shot Learning for Semantic Segmentation
Contributing
Please read our contributing guidelines and code of conduct before submitting pull requests.
License
MIT License - see LICENSE file for details.