Bỏ để qua phần nội dung

Tài liệu tham khảo cho ultralytics/models/nas/model.py

Ghi

Tệp này có sẵn tại https://github.com/ultralytics/ultralytics/blob/main/ultralytics/mô hình/nas/model.py. Nếu bạn phát hiện ra một vấn đề, vui lòng giúp khắc phục nó bằng cách đóng góp Yêu cầu 🛠️ kéo. Cảm ơn bạn 🙏 !



ultralytics.models.nas.model.NAS

Căn cứ: Model

YOLO Mô hình NAS để phát hiện đối tượng.

Lớp này cung cấp một giao diện cho YOLO-Mô hình NAS và mở rộng Model lớp học từ Ultralytics động cơ. Nó được thiết kế để tạo điều kiện thuận lợi cho nhiệm vụ phát hiện đối tượng bằng cách sử dụng được đào tạo trước hoặc đào tạo tùy chỉnh YOLO-Mô hình NAS.

Ví dụ
from ultralytics import NAS

model = NAS('yolo_nas_s')
results = model.predict('ultralytics/assets/bus.jpg')

Thuộc tính:

Tên Kiểu Sự miêu tả
model str

Đường dẫn đến mô hình hoặc tên mô hình được đào tạo trước. Mặc định là 'yolo_nas_s.pt'.

Ghi

YOLO-Mô hình NAS chỉ hỗ trợ các mô hình được đào tạo trước. Không cung cấp tệp cấu hình YAML.

Mã nguồn trong ultralytics/models/nas/model.py
class NAS(Model):
    """
    YOLO NAS model for object detection.

    This class provides an interface for the YOLO-NAS models and extends the `Model` class from Ultralytics engine.
    It is designed to facilitate the task of object detection using pre-trained or custom-trained YOLO-NAS models.

    Example:
        ```python
        from ultralytics import NAS

        model = NAS('yolo_nas_s')
        results = model.predict('ultralytics/assets/bus.jpg')
        ```

    Attributes:
        model (str): Path to the pre-trained model or model name. Defaults to 'yolo_nas_s.pt'.

    Note:
        YOLO-NAS models only support pre-trained models. Do not provide YAML configuration files.
    """

    def __init__(self, model="yolo_nas_s.pt") -> None:
        """Initializes the NAS model with the provided or default 'yolo_nas_s.pt' model."""
        assert Path(model).suffix not in {".yaml", ".yml"}, "YOLO-NAS models only support pre-trained models."
        super().__init__(model, task="detect")

    @smart_inference_mode()
    def _load(self, weights: str, task: str):
        """Loads an existing NAS model weights or creates a new NAS model with pretrained weights if not provided."""
        import super_gradients

        suffix = Path(weights).suffix
        if suffix == ".pt":
            self.model = torch.load(weights)
        elif suffix == "":
            self.model = super_gradients.training.models.get(weights, pretrained_weights="coco")
        # Standardize model
        self.model.fuse = lambda verbose=True: self.model
        self.model.stride = torch.tensor([32])
        self.model.names = dict(enumerate(self.model._class_names))
        self.model.is_fused = lambda: False  # for info()
        self.model.yaml = {}  # for info()
        self.model.pt_path = weights  # for export()
        self.model.task = "detect"  # for export()

    def info(self, detailed=False, verbose=True):
        """
        Logs model info.

        Args:
            detailed (bool): Show detailed information about model.
            verbose (bool): Controls verbosity.
        """
        return model_info(self.model, detailed=detailed, verbose=verbose, imgsz=640)

    @property
    def task_map(self):
        """Returns a dictionary mapping tasks to respective predictor and validator classes."""
        return {"detect": {"predictor": NASPredictor, "validator": NASValidator}}

task_map property

Trả về các tác vụ ánh xạ từ điển cho các lớp dự đoán và xác thực tương ứng.

__init__(model='yolo_nas_s.pt')

Khởi tạo mô hình NAS với được cung cấp hoặc mặc định 'yoloMô hình _nas_s.pt'.

Mã nguồn trong ultralytics/models/nas/model.py
def __init__(self, model="yolo_nas_s.pt") -> None:
    """Initializes the NAS model with the provided or default 'yolo_nas_s.pt' model."""
    assert Path(model).suffix not in {".yaml", ".yml"}, "YOLO-NAS models only support pre-trained models."
    super().__init__(model, task="detect")

info(detailed=False, verbose=True)

Ghi nhật ký thông tin mô hình.

Thông số:

Tên Kiểu Sự miêu tả Mặc định
detailed bool

Hiển thị thông tin chi tiết về mô hình.

False
verbose bool

Kiểm soát độ chi tiết.

True
Mã nguồn trong ultralytics/models/nas/model.py
def info(self, detailed=False, verbose=True):
    """
    Logs model info.

    Args:
        detailed (bool): Show detailed information about model.
        verbose (bool): Controls verbosity.
    """
    return model_info(self.model, detailed=detailed, verbose=verbose, imgsz=640)





Đã tạo 2023-11-12, Cập nhật 2024-05-08
Tác giả: Burhan-Q (1), glenn-jocher (3)