Skillpedia
تعلّم الآلة260k · #517

segment-anything-model

ما الذي تفعله

يستخدم نموذج Segment Anything من Meta لإيجاد الأجسام في الصور وتحديد حدودها، بتوجيه من نقاط أو مستطيلات. وهو للباحثين والمطورين الذين يحتاجون إلى أقنعة للأجسام دون تدريب نموذج مخصص.

متى تستخدمها

  • ✓عندما تحتاج إلى اقتطاع أجسام في صور أو تحديد حدودها دون تدريب نموذج.
  • ✓عندما تريد بناء أداة تعليق بتوجيه بالنقاط أو المستطيلات.
  • ✓عندما تحتاج إلى أقنعة لصور متخصصة مثل الطبية أو الفضائية.

رابط المهارة

https://github.com/NousResearch/hermes-agent/blob/main/optional-skills/mlops/models/segment-anything-model/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/NousResearch/hermes-agent/blob/main/optional-skills/mlops/models/segment-anything-model/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“قسّم الزجاجات في هذه الصورة، مستخدمًا مستطيلًا حول زجاجة واحدة لتوجيه النموذج.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يحمّل وكيلك نموذج SAM، ويمرر له نقاطًا أو مستطيلات أو أقنعة سابقة كتوجيهات، ويعيد الأقنعة. ويمكنه أيضًا توليد أقنعة كل الأجسام تلقائيًا.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

Segment Anything Model (SAM)

Guide to using Meta AI's Segment Anything Model for zero-shot image segmentation.

When to use SAM

Use SAM when:

  • Need to segment any object in images without task-specific training
  • Building interactive annotation tools with point/box prompts
  • Generating training data for other vision models
  • Need zero-shot transfer to new image domains
  • Building object detection/segmentation pipelines
  • Processing medical, satellite, or domain-specific images

Key features:

  • Zero-shot segmentation: Works on any image domain without fine-tuning
  • Flexible prompts: Points, bounding boxes, or previous masks
  • Automatic segmentation: Generate all object masks automatically
  • High quality: Trained on 1.1 billion masks from 11 million images
  • Multiple model sizes: ViT-B (fastest), ViT-L, ViT-H (most accurate)
  • ONNX export: Deploy in browsers and edge devices

Use alternatives instead:

  • YOLO/Detectron2: For real-time object detection with classes
  • Mask2Former: For semantic/panoptic segmentation with categories
  • GroundingDINO + SAM: For text-prompted segmentation
  • SAM 2: For video segmentation tasks

Quick start

Installation

# From GitHub
pip install git+https://github.com/facebookresearch/segment-anything.git

# Optional dependencies
pip install opencv-python pycocotools matplotlib

# Or use HuggingFace transformers
pip install transformers

Download checkpoints

# ViT-H (largest, most accurate) - 2.4GB
wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth

# ViT-L (medium) - 1.2GB
wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_l_0b3195.pth

# ViT-B (smallest, fastest) - 375MB
wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth

Basic usage with SamPredictor

import numpy as np
from segment_anything import sam_model_registry, SamPredictor

# Load model
sam = sam_model_registry["vit_h"](checkpoint="sam_vit_h_4b8939.pth")
sam.to(device="cuda")

# Create predictor
predictor = SamPredictor(sam)

# Set image (computes embeddings once)
image = cv2.imread("image.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
predictor.set_image(image)

# Predict with point prompts
input_point = np.array([[500, 375]])  # (x, y) coordinates
input_label = np.array([1])  # 1 = foreground, 0 = background

masks, scores, logits = predictor.predict(
    point_coords=input_point,
    point_labels=input_label,
    multimask_output=True  # Returns 3 mask options
)

# Select best mask
best_mask = masks[np.argmax(scores)]

HuggingFace Transformers

import torch
from PIL import Image
from transformers import SamModel, SamProcessor

# Load model and processor
model = SamModel.from_pretrained("facebook/sam-vit-huge")
processor = SamProcessor.from_pretrained("facebook/sam-vit-huge")
model.to("cuda")

# Process image with point prompt
image = Image.open("image.jpg")
input_points = [[[450, 600]]]  # Batch of points

inputs = processor(image, input_points=input_points, return_tensors="pt")
inputs = {k: v.to("cuda") for k, v in inputs.items()}

# Generate masks
with torch.no_grad():
    outputs = model(**inputs)

# Post-process masks to original size
masks = processor.image_processor.post_process_masks(
    outputs.pred_masks.cpu(),
    inputs["original_sizes"].cpu(),
    inputs["reshaped_input_sizes"].cpu()
)

Core concepts

Model architecture

<!-- ascii-guard-ignore -->
SAM Architecture:
┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│  Image Encoder  │────▶│ Prompt Encoder  │────▶│  Mask Decoder   │
│     (ViT)       │     │ (Points/Boxes)  │     │ (Transformer)   │
└─────────────────┘     └─────────────────┘     └─────────────────┘
        │                       │                       │
   Image Embeddings      Prompt Embeddings         Masks + IoU
   (computed once)       (per prompt)             predictions
<!-- ascii-guard-ignore-end -->

Model variants

Model Checkpoint Size Speed Accuracy
ViT-H vit_h 2.4 GB Slowest Best
ViT-L vit_l 1.2 GB Medium Good
ViT-B vit_b 375 MB Fastest Good

Prompt types

Prompt Description Use Case
Point (foreground) Click on object Single object selection
Point (background) Click outside object Exclude regions
الأسئلة الشائعة

هل يحتاج إلى تدريب؟

لا. تصف المهارة تقسيمًا بلا تدريب مسبق يعمل دون ضبط دقيق.

ما أحجام النماذج المتاحة؟

تذكر المهارة ViT-B كأسرع نموذج، وViT-L وViT-H كأكثر دقة.

هل توجد نسخة للفيديو؟

تقترح المهارة SAM 2 لمهام تقسيم الفيديو.

التفاصيل

الوصف الأصلي من المؤلف

SAM: zero-shot image segmentation via points, boxes, masks.

repo: NousResearch/hermes-agent

الشعبية

نجوم GitHub
260k
الترتيب
#517
الترخيص
MIT
آخر تحديث
2‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة