model.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  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. """Returns a dictionary mapping segment task to corresponding predictor and validator classes."""
  25. return {"segment": {"predictor": FastSAMPredictor, "validator": FastSAMValidator}}