์ฝ˜ํ…์ธ ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

์ฐธ์กฐ ultralytics/models/nas/model.py

์ฐธ๊ณ 

์ด ํŒŒ์ผ์€ https://github.com/ultralytics/ ultralytics/blob/main/ ultralytics/models/nas/model .py์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฌธ์ œ๋ฅผ ๋ฐœ๊ฒฌํ•˜๋ฉด ํ’€ ๋ฆฌํ€˜์ŠคํŠธ (๐Ÿ› ๏ธ)๋ฅผ ์ œ์ถœํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋„๋ก ๋„์™€์ฃผ์„ธ์š”. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ™!



ultralytics.models.nas.model.NAS

๊ธฐ์ง€: Model

YOLO ๋ฌผ์ฒด ๊ฐ์ง€๋ฅผ ์œ„ํ•œ NAS ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.

์ด ํด๋ž˜์Šค๋Š” YOLO-NAS ๋ชจ๋ธ์— ๋Œ€ํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•˜๊ณ  Model Ultralytics ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”. ์ด ํด๋ž˜์Šค๋Š” ์‚ฌ์ „ ํ•™์Šต ๋˜๋Š” ์‚ฌ์šฉ์ž ์ง€์ • ํ•™์Šต๋œ YOLO-NAS ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ์ฒด ๊ฐ์ง€ ์ž‘์—…์„ ์šฉ์ดํ•˜๊ฒŒ ํ•˜๋„๋ก ์„ค๊ณ„๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์ œ
from ultralytics import NAS

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

์†์„ฑ:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช…
model str

์‚ฌ์ „ ํ•™์Šต๋œ ๋ชจ๋ธ ๋˜๋Š” ๋ชจ๋ธ ์ด๋ฆ„์˜ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ 'yolo_nas_s.pt'์ž…๋‹ˆ๋‹ค.

์ฐธ๊ณ 

YOLO-NAS ๋ชจ๋ธ์€ ์‚ฌ์ „ ํ•™์Šต๋œ ๋ชจ๋ธ๋งŒ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. YAML ๊ตฌ์„ฑ ํŒŒ์ผ์„ ์ œ๊ณตํ•˜์ง€ ๋งˆ์„ธ์š”.

์˜ ์†Œ์Šค ์ฝ”๋“œ 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

์‚ฌ์ „ ๋งคํ•‘ ์ž‘์—…์„ ๊ฐ๊ฐ์˜ ์˜ˆ์ธก์ž ๋ฐ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๊ธฐ ํด๋ž˜์Šค๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

__init__(model='yolo_nas_s.pt')

์ œ๊ณต๋˜๊ฑฐ๋‚˜ ๊ธฐ๋ณธ๊ฐ’์ธ 'yolo_nas_s.pt' ๋ชจ๋ธ๋กœ NAS ๋ชจ๋ธ์„ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ 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)

๋ชจ๋ธ ์ •๋ณด๋ฅผ ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค.

๋งค๊ฐœ๋ณ€์ˆ˜:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช… ๊ธฐ๋ณธ๊ฐ’
detailed bool

๋ชจ๋ธ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

False
verbose bool

์žฅํ™ฉํ•จ์„ ์ œ์–ดํ•ฉ๋‹ˆ๋‹ค.

True
์˜ ์†Œ์Šค ์ฝ”๋“œ 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)





์ƒ์„ฑ๋จ 2023-11-12, ์—…๋ฐ์ดํŠธ๋จ 2023-11-25
์ž‘์„ฑ์ž: glenn-jocher (3)