コンテンツへスキップ

参考 ultralytics/models/fastsam/model.py

このファイルはhttps://github.com/ultralytics/ultralytics/blob/main/ ultralytics/models/ fastsam/model .py にあります。もし問題を発見したら、Pull Request🛠️ を投稿して修正にご協力ください。ありがとうございました!



ultralytics.models.fastsam.model.FastSAM

ベース: Model

FastSAM モデルのインターフェース。

from ultralytics import FastSAM

model = FastSAM('last.pt')
results = model.predict('ultralytics/assets/bus.jpg')
ソースコード ultralytics/models/fastsam/model.py
class FastSAM(Model):
    """
    FastSAM model interface.

    Example:
        ```python
        from ultralytics import FastSAM

        model = FastSAM('last.pt')
        results = model.predict('ultralytics/assets/bus.jpg')
        ```
    """

    def __init__(self, model="FastSAM-x.pt"):
        """Call the __init__ method of the parent class (YOLO) with the updated default model."""
        if str(model) == "FastSAM.pt":
            model = "FastSAM-x.pt"
        assert Path(model).suffix not in {".yaml", ".yml"}, "FastSAM models only support pre-trained models."
        super().__init__(model=model, task="segment")

    @property
    def task_map(self):
        """Returns a dictionary mapping segment task to corresponding predictor and validator classes."""
        return {"segment": {"predictor": FastSAMPredictor, "validator": FastSAMValidator}}

task_map property

セグメントタスクを、対応する予測クラスと検証クラスにマッピングした辞書を返します。

__init__(model='FastSAM-x.pt')

更新されたデフォルト・モデルで親クラス(YOLO)のinitメソッドを呼び出します。

ソースコード ultralytics/models/fastsam/model.py
def __init__(self, model="FastSAM-x.pt"):
    """Call the __init__ method of the parent class (YOLO) with the updated default model."""
    if str(model) == "FastSAM.pt":
        model = "FastSAM-x.pt"
    assert Path(model).suffix not in {".yaml", ".yml"}, "FastSAM models only support pre-trained models."
    super().__init__(model=model, task="segment")





作成 2023-11-12 更新 2024-05-08
著者Burhan-Q(1),glenn-jocher(3)