─░├žeri─če ge├ž

Referans i├žin ultralytics/models/sam/model.py

Not

Bu dosya https://github.com/ultralytics/ultralytics/blob/main/ ultralytics/models/ sam/model .py adresinde mevcuttur. Bir sorun tespit ederseniz l├╝tfen bir ├çekme ─░ste─či ­čŤá´ŞĆ ile katk─▒da bulunarak d├╝zeltilmesine yard─▒mc─▒ olun. Te┼čekk├╝rler ­čÖĆ!



ultralytics.models.sam.model.SAM

├ťsler: Model

SAM (Segment Anything Model) aray├╝z s─▒n─▒f─▒.

SAM istenebilir ger├žek zamanl─▒ g├Âr├╝nt├╝ segmentasyonu i├žin tasarlanm─▒┼čt─▒r. A┼ča─č─▒dakiler gibi ├že┼čitli istemlerle kullan─▒labilir s─▒n─▒rlay─▒c─▒ kutular, noktalar veya etiketler. Model s─▒f─▒r at─▒┼č performans─▒ i├žin yeteneklere sahiptir ve SA-1B ├╝zerinde e─čitilmi┼čtir veri k├╝mesi.

Kaynak kodu ultralytics/models/sam/model.py
class SAM(Model):
    """
    SAM (Segment Anything Model) interface class.

    SAM is designed for promptable real-time image segmentation. It can be used with a variety of prompts such as
    bounding boxes, points, or labels. The model has capabilities for zero-shot performance and is trained on the SA-1B
    dataset.
    """

    def __init__(self, model="sam_b.pt") -> None:
        """
        Initializes the SAM model with a pre-trained model file.

        Args:
            model (str): Path to the pre-trained SAM model file. File should have a .pt or .pth extension.

        Raises:
            NotImplementedError: If the model file extension is not .pt or .pth.
        """
        if model and Path(model).suffix not in {".pt", ".pth"}:
            raise NotImplementedError("SAM prediction requires pre-trained *.pt or *.pth model.")
        super().__init__(model=model, task="segment")

    def _load(self, weights: str, task=None):
        """
        Loads the specified weights into the SAM model.

        Args:
            weights (str): Path to the weights file.
            task (str, optional): Task name. Defaults to None.
        """
        self.model = build_sam(weights)

    def predict(self, source, stream=False, bboxes=None, points=None, labels=None, **kwargs):
        """
        Performs segmentation prediction on the given image or video source.

        Args:
            source (str): Path to the image or video file, or a PIL.Image object, or a numpy.ndarray object.
            stream (bool, optional): If True, enables real-time streaming. Defaults to False.
            bboxes (list, optional): List of bounding box coordinates for prompted segmentation. Defaults to None.
            points (list, optional): List of points for prompted segmentation. Defaults to None.
            labels (list, optional): List of labels for prompted segmentation. Defaults to None.

        Returns:
            (list): The model predictions.
        """
        overrides = dict(conf=0.25, task="segment", mode="predict", imgsz=1024)
        kwargs.update(overrides)
        prompts = dict(bboxes=bboxes, points=points, labels=labels)
        return super().predict(source, stream, prompts=prompts, **kwargs)

    def __call__(self, source=None, stream=False, bboxes=None, points=None, labels=None, **kwargs):
        """
        Alias for the 'predict' method.

        Args:
            source (str): Path to the image or video file, or a PIL.Image object, or a numpy.ndarray object.
            stream (bool, optional): If True, enables real-time streaming. Defaults to False.
            bboxes (list, optional): List of bounding box coordinates for prompted segmentation. Defaults to None.
            points (list, optional): List of points for prompted segmentation. Defaults to None.
            labels (list, optional): List of labels for prompted segmentation. Defaults to None.

        Returns:
            (list): The model predictions.
        """
        return self.predict(source, stream, bboxes, points, labels, **kwargs)

    def info(self, detailed=False, verbose=True):
        """
        Logs information about the SAM model.

        Args:
            detailed (bool, optional): If True, displays detailed information about the model. Defaults to False.
            verbose (bool, optional): If True, displays information on the console. Defaults to True.

        Returns:
            (tuple): A tuple containing the model's information.
        """
        return model_info(self.model, detailed=detailed, verbose=verbose)

    @property
    def task_map(self):
        """
        Provides a mapping from the 'segment' task to its corresponding 'Predictor'.

        Returns:
            (dict): A dictionary mapping the 'segment' task to its corresponding 'Predictor'.
        """
        return {"segment": {"predictor": Predictor}}

task_map property

'Segment' g├Ârevinden kar┼č─▒l─▒k gelen 'Tahmin Edici'ye bir e┼čleme sa─člar.

─░ade:

Tip A├ž─▒klama
dict

'Segment' g├Ârevini kar┼č─▒l─▒k gelen 'Tahmin Edici' ile e┼čleyen bir s├Âzl├╝k.

__call__(source=None, stream=False, bboxes=None, points=None, labels=None, **kwargs)

'Tahmin' y├Ântemi i├žin takma ad.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
source str

G├Âr├╝nt├╝ veya video dosyas─▒n─▒n yolu veya bir PIL.Image nesnesi ya da bir numpy.ndarray nesnesi.

None
stream bool

True ise, ger├žek zamanl─▒ ak─▒┼č─▒ etkinle┼čtirir. Varsay─▒lan de─čer False'dir.

False
bboxes list

─░stenen segmentasyon i├žin s─▒n─▒rlay─▒c─▒ kutu koordinatlar─▒n─▒n listesi. Varsay─▒lan de─čer Yok'tur.

None
points list

─░stenen segmentasyon i├žin noktalar─▒n listesi. Varsay─▒lan de─čer Yok'tur.

None
labels list

─░stenen segmentasyon i├žin etiketlerin listesi. Varsay─▒lan de─čer Yok'tur.

None

─░ade:

Tip A├ž─▒klama
list

Model tahminleri.

Kaynak kodu ultralytics/models/sam/model.py
def __call__(self, source=None, stream=False, bboxes=None, points=None, labels=None, **kwargs):
    """
    Alias for the 'predict' method.

    Args:
        source (str): Path to the image or video file, or a PIL.Image object, or a numpy.ndarray object.
        stream (bool, optional): If True, enables real-time streaming. Defaults to False.
        bboxes (list, optional): List of bounding box coordinates for prompted segmentation. Defaults to None.
        points (list, optional): List of points for prompted segmentation. Defaults to None.
        labels (list, optional): List of labels for prompted segmentation. Defaults to None.

    Returns:
        (list): The model predictions.
    """
    return self.predict(source, stream, bboxes, points, labels, **kwargs)

__init__(model='sam_b.pt')

SAM modelini ├Ânceden e─čitilmi┼č bir model dosyas─▒ ile ba┼člat─▒r.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
model str

├ľnceden e─čitilmi┼č SAM model dosyas─▒n─▒n yolu. Dosya .pt veya .pth uzant─▒s─▒na sahip olmal─▒d─▒r.

'sam_b.pt'

Zamlar:

Tip A├ž─▒klama
NotImplementedError

Model dosya uzant─▒s─▒ .pt veya .pth de─čilse.

Kaynak kodu ultralytics/models/sam/model.py
def __init__(self, model="sam_b.pt") -> None:
    """
    Initializes the SAM model with a pre-trained model file.

    Args:
        model (str): Path to the pre-trained SAM model file. File should have a .pt or .pth extension.

    Raises:
        NotImplementedError: If the model file extension is not .pt or .pth.
    """
    if model and Path(model).suffix not in {".pt", ".pth"}:
        raise NotImplementedError("SAM prediction requires pre-trained *.pt or *.pth model.")
    super().__init__(model=model, task="segment")

info(detailed=False, verbose=True)

SAM modeli hakk─▒ndaki bilgileri g├╝nl├╝─če kaydeder.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
detailed bool

True ise, model hakk─▒nda ayr─▒nt─▒l─▒ bilgi g├Âr├╝nt├╝ler. Varsay─▒lan de─čer False'dir.

False
verbose bool

True ise, bilgileri konsolda g├Âr├╝nt├╝ler. Varsay─▒lan de─čer True'dur.

True

─░ade:

Tip A├ž─▒klama
tuple

Modelin bilgilerini i├žeren bir tuple.

Kaynak kodu ultralytics/models/sam/model.py
def info(self, detailed=False, verbose=True):
    """
    Logs information about the SAM model.

    Args:
        detailed (bool, optional): If True, displays detailed information about the model. Defaults to False.
        verbose (bool, optional): If True, displays information on the console. Defaults to True.

    Returns:
        (tuple): A tuple containing the model's information.
    """
    return model_info(self.model, detailed=detailed, verbose=verbose)

predict(source, stream=False, bboxes=None, points=None, labels=None, **kwargs)

Verilen g├Âr├╝nt├╝ veya video kayna─č─▒ ├╝zerinde segmentasyon tahmini ger├žekle┼čtirir.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
source str

G├Âr├╝nt├╝ veya video dosyas─▒n─▒n yolu veya bir PIL.Image nesnesi ya da bir numpy.ndarray nesnesi.

gerekli
stream bool

True ise, ger├žek zamanl─▒ ak─▒┼č─▒ etkinle┼čtirir. Varsay─▒lan de─čer False'dir.

False
bboxes list

─░stenen segmentasyon i├žin s─▒n─▒rlay─▒c─▒ kutu koordinatlar─▒n─▒n listesi. Varsay─▒lan de─čer Yok'tur.

None
points list

─░stenen segmentasyon i├žin noktalar─▒n listesi. Varsay─▒lan de─čer Yok'tur.

None
labels list

─░stenen segmentasyon i├žin etiketlerin listesi. Varsay─▒lan de─čer Yok'tur.

None

─░ade:

Tip A├ž─▒klama
list

Model tahminleri.

Kaynak kodu ultralytics/models/sam/model.py
def predict(self, source, stream=False, bboxes=None, points=None, labels=None, **kwargs):
    """
    Performs segmentation prediction on the given image or video source.

    Args:
        source (str): Path to the image or video file, or a PIL.Image object, or a numpy.ndarray object.
        stream (bool, optional): If True, enables real-time streaming. Defaults to False.
        bboxes (list, optional): List of bounding box coordinates for prompted segmentation. Defaults to None.
        points (list, optional): List of points for prompted segmentation. Defaults to None.
        labels (list, optional): List of labels for prompted segmentation. Defaults to None.

    Returns:
        (list): The model predictions.
    """
    overrides = dict(conf=0.25, task="segment", mode="predict", imgsz=1024)
    kwargs.update(overrides)
    prompts = dict(bboxes=bboxes, points=points, labels=labels)
    return super().predict(source, stream, prompts=prompts, **kwargs)





Created 2023-11-12, Updated 2024-06-02
Authors: glenn-jocher (5), Burhan-Q (1)