model.py 948 B

123456789101112131415161718192021222324252627282930313233
  1. # Ultralytics YOLO 🚀, AGPL-3.0 license
  2. from pathlib import Path
  3. from ultralytics.engine.model import Model
  4. from .predict import FastSAMPredictor
  5. from .val import FastSAMValidator
  6. class FastSAM(Model):
  7. """
  8. FastSAM model interface.
  9. Example:
  10. ```python
  11. from ultralytics import FastSAM
  12. model = FastSAM('last.pt')
  13. results = model.predict('ultralytics/assets/bus.jpg')
  14. ```
  15. """
  16. def __init__(self, model='FastSAM-x.pt'):
  17. """Call the __init__ method of the parent class (YOLO) with the updated default model"""
  18. if str(model) == 'FastSAM.pt':
  19. model = 'FastSAM-x.pt'
  20. assert Path(model).suffix not in ('.yaml', '.yml'), 'FastSAM models only support pre-trained models.'
  21. super().__init__(model=model, task='segment')
  22. @property
  23. def task_map(self):
  24. return {'segment': {'predictor': FastSAMPredictor, 'validator': FastSAMValidator}}