๋ฒ ์ด์ค: 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)
|