跳至内容

参考资料 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)