Skip to content

Reference for ultralytics/models/fastsam/model.py

Note

Full source code for this file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/fastsam/model.py. Help us fix any issues you see by submitting a Pull Request 🛠️. Thank you 🙏!


ultralytics.models.fastsam.model.FastSAM

Bases: Model

FastSAM model interface.

Example
from ultralytics import FastSAM

model = FastSAM('last.pt')
results = model.predict('ultralytics/assets/bus.jpg')
Source code in 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):
        return {'segment': {'predictor': FastSAMPredictor, 'validator': FastSAMValidator}}

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

Call the init method of the parent class (YOLO) with the updated default model

Source code in 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')




Created 2023-07-16, Updated 2023-08-07
Authors: glenn-jocher (5), Laughing-q (1)