[Go to site: main page, start]

엔터프라이즈급 보안: ISO 27001 및 SOC 2 Type I 준수.

Python 사용법#

Ultralytics YOLO Python 사용법 문서에 오신 것을 환영합니다! 이 가이드는 Ultralytics YOLO를 object detection, instance segmentation, semantic segmentation, depth estimation, 및 classification을 위한 Python 프로젝트에 원활하게 통합할 수 있도록 설계되었습니다. 여기서는 사전 학습된 모델을 로드하고 사용하는 방법, 새 모델을 학습시키는 방법, 이미지에 대해 예측을 수행하는 방법을 배울 수 있습니다. 사용하기 쉬운 Python 인터페이스는 Python 프로젝트에 YOLO를 통합하여 고급 객체 검출 기능을 빠르게 구현하려는 모든 이에게 유용한 리소스입니다. 시작하겠습니다!



Watch: Mastering Ultralytics YOLO: Python

예를 들어, 사용자는 단 몇 줄의 코드로 모델을 로드하고, 학습시키고, 검증 세트에서 성능을 평가하며, export it to ONNX format할 수도 있습니다.

Python
from ultralytics import YOLO

# Create a new YOLO model from scratch
model = YOLO("yolo26n.yaml")

# Load a pretrained YOLO model (recommended for training)
model = YOLO("yolo26n.pt")

# Train the model using the 'coco8.yaml' dataset for 3 epochs
results = model.train(data="coco8.yaml", epochs=3)

# Evaluate the model's performance on the validation set
results = model.val()

# Perform object detection on an image using the model
results = model("https://ultralytics.com/images/bus.jpg")

# Export the model to ONNX format
success = model.export(format="onnx")

학습(Train)#

Train mode는 커스텀 데이터셋으로 YOLO 모델을 학습시키는 데 사용됩니다. 이 모드에서는 지정된 데이터셋과 하이퍼파라미터를 사용하여 모델이 학습됩니다. 학습 과정에는 이미지 내 객체의 클래스와 위치를 정확하게 예측할 수 있도록 모델의 파라미터를 최적화하는 작업이 포함됩니다.

학습(Train)
from ultralytics import YOLO

model = YOLO("yolo26n.pt")  # pass any model type
results = model.train(epochs=5)

학습 예제

검증(Val)#

Val mode는 학습이 완료된 후 YOLO 모델을 검증하는 데 사용됩니다. 이 모드에서는 검증 세트에서 모델을 평가하여 accuracy와 일반화 성능을 측정합니다. 이 모드를 사용하면 모델의 하이퍼파라미터를 튜닝하여 성능을 향상시킬 수 있습니다.

검증(Val)
from ultralytics import YOLO

# Load a YOLO model
model = YOLO("yolo26n.yaml")

# Train the model
model.train(data="coco8.yaml", epochs=5)

# Validate on training data
model.val()

검증 예제

추론(Predict)#

Predict mode는 학습된 YOLO 모델을 사용하여 새로운 이미지나 비디오에서 예측을 수행하는 데 사용됩니다. 이 모드에서는 체크포인트 파일에서 모델이 로드되며, 사용자는 이미지나 비디오를 제공하여 인퍼런스를 수행할 수 있습니다. 모델은 입력된 이미지나 비디오 내 객체의 클래스와 위치를 예측합니다.

추론(Predict)
import cv2
from PIL import Image

from ultralytics import YOLO

model = YOLO("model.pt")
# accepts all formats - image/dir/Path/URL/video/PIL/ndarray. 0 for webcam
results = model.predict(source="0")
results = model.predict(source="folder", show=True)  # Display preds. Accepts all YOLO predict arguments

# from PIL
im1 = Image.open("bus.jpg")
results = model.predict(source=im1, save=True)  # save plotted images

# from ndarray
im2 = cv2.imread("bus.jpg")
results = model.predict(source=im2, save=True, save_txt=True)  # save predictions as labels

# from list of PIL/ndarray
results = model.predict(source=[im1, im2])

예측 예제

내보내기(Export)#

Export mode는 배포에 사용할 수 있는 포맷으로 YOLO 모델을 내보내는 데 사용됩니다. 이 모드에서는 다른 소프트웨어 애플리케이션이나 하드웨어 장치에서 사용할 수 있는 포맷으로 모델이 변환됩니다. 이 모드는 모델을 프로덕션 환경에 배포할 때 유용합니다.

내보내기(Export)

동적 배치 크기 및 이미지 크기로 공식 YOLO 모델을 ONNX로 내보냅니다.

from ultralytics import YOLO

model = YOLO("yolo26n.pt")
model.export(format="onnx", dynamic=True)

내보내기 예제

추적(Track)#

Track mode는 YOLO 모델을 사용하여 실시간으로 객체를 추적하는 데 사용됩니다. 이 모드에서는 체크포인트 파일에서 모델이 로드되며, 사용자는 라이브 비디오 스트림을 제공하여 실시간 객체 추적을 수행할 수 있습니다. 이 모드는 감시 시스템이나 self-driving cars 같은 애플리케이션에 유용합니다.

추적(Track)
from ultralytics import YOLO

# Load a model
model = YOLO("yolo26n.pt")  # load an official detection model
model = YOLO("yolo26n-seg.pt")  # load an official segmentation model
model = YOLO("path/to/best.pt")  # load a custom model

# Track with the model
results = model.track(source="https://youtu.be/LNwODJXcvt4", show=True)
results = model.track(source="https://youtu.be/LNwODJXcvt4", show=True, tracker="bytetrack.yaml")

추적 예제

벤치마크#

Benchmark mode는 다양한 YOLO 내보내기 포맷의 속도와 정확도를 프로파일링하는 데 사용됩니다. 벤치마크는 내보낸 포맷의 크기, 객체 검출 및 세그먼트를 위한 mAP50-95 메트릭 또는 분류를 위한 accuracy_top1 메트릭, 그리고 ONNX, OpenVINO, TensorRT 등 다양한 내보내기 포맷에 따른 이미지당 밀리초 단위의 인퍼런스 시간을 제공합니다. 이 정보는 사용자가 속도 및 정확도 요구사항에 따라 특정 유스케이스에 최적의 내보내기 포맷을 선택하는 데 도움을 줍니다.

벤치마크

모든 내보내기 형식에 걸쳐 공식 YOLO 모델을 벤치마킹합니다.

from ultralytics.utils.benchmarks import benchmark

# Benchmark
benchmark(model="yolo26n.pt", data="coco8.yaml", imgsz=640, device=0)

벤치마크 예제

Trainer 사용하기#

YOLO 모델 클래스는 Trainer 클래스를 위한 고수준 래퍼 역할을 합니다. 각 YOLO 태스크에는 BaseTrainer을 상속하는 고유한 트레이너가 있습니다. 이 아키텍처는 machine learning workflows에서 더 큰 유연성과 커스터마이징을 가능하게 합니다.

탐지(Detection) Trainer 예제
from ultralytics.models.yolo.detect import DetectionPredictor, DetectionTrainer, DetectionValidator

# trainer
trainer = DetectionTrainer(overrides={})
trainer.train()
trained_model = trainer.best

# Validator
val = DetectionValidator(args=...)
val(model=trained_model)

# predictor
pred = DetectionPredictor(overrides={})
pred(source=SOURCE, model=trained_model)

# resume from last weight
overrides["resume"] = trainer.last
trainer = DetectionTrainer(overrides=overrides)

트레이너를 쉽게 커스터마이징하여 커스텀 태스크를 지원하거나 연구 개발 아이디어를 탐색할 수 있습니다. Ultralytics YOLO의 모듈식 설계를 통해 새로운 computer vision 태스크를 작업하거나 더 나은 성능을 위해 기존 모델을 미세 조정할 때 프레임워크를 특정 요구에 맞게 조정할 수 있습니다.

사용자 정의 튜토리얼

FAQ#

객체 탐지를 위해 Python 프로젝트에 YOLO를 어떻게 통합할 수 있나요?#

Ultralytics YOLO를 Python 프로젝트에 통합하는 것은 간단합니다. 사전 학습된 모델을 로드하거나 처음부터 모델을 학습시킬 수 있습니다. 시작 방법은 다음과 같습니다:

from ultralytics import YOLO

# Load a pretrained YOLO model
model = YOLO("yolo26n.pt")

# Perform object detection on an image
results = model("https://ultralytics.com/images/bus.jpg")

# Visualize the results
for result in results:
    result.show()

자세한 예시는 Predict Mode 섹션에서 확인하세요.

YOLO에서 사용 가능한 다양한 모드에는 어떤 것이 있나요?#

Ultralytics YOLO는 다양한 machine learning 워크플로우에 맞추기 위해 다양한 모드를 제공합니다. 여기에는 다음이 포함됩니다:

  • Train: 커스텀 데이터셋을 사용하여 모델을 학습시킵니다.
  • Val: 검증 세트에서 모델 성능을 검증합니다.
  • Predict: 새 이미지나 비디오 스트림에 대해 예측을 수행합니다.
  • Export: ONNX 및 TensorRT와 같은 다양한 포맷으로 모델을 내보냅니다.
  • Track: 비디오 스트림에서 실시간 객체 추적을 수행합니다.
  • Benchmark: 다양한 구성에서 모델 성능을 벤치마킹합니다.

각 모드는 model development and deployment의 다양한 단계를 위한 포괄적인 기능을 제공하도록 설계되었습니다.

내 데이터셋을 사용하여 커스텀 YOLO 모델을 어떻게 학습시키나요?#

커스텀 YOLO 모델을 학습시키려면 데이터셋과 기타 hyperparameters를 지정해야 합니다. 간단한 예시는 다음과 같습니다:

from ultralytics import YOLO

# Load the YOLO model
model = YOLO("yolo26n.yaml")

# Train the model with custom dataset
model.train(data="path/to/your/dataset.yaml", epochs=10)

학습에 대한 자세한 내용과 사용 예시 링크는 Train Mode 페이지를 방문해 주세요.

배포를 위해 YOLO 모델을 어떻게 내보내나요?#

배포에 적합한 포맷으로 YOLO 모델을 내보내는 것은 export 함수를 사용하면 간단합니다. 예를 들어, 모델을 ONNX 포맷으로 내보낼 수 있습니다:

from ultralytics import YOLO

# Load the YOLO model
model = YOLO("yolo26n.pt")

# Export the model to ONNX format
model.export(format="onnx")

다양한 내보내기 옵션에 대해서는 Export Mode 문서를 참조하세요.

다른 데이터셋에서 YOLO 모델을 검증할 수 있나요?#

네, 다른 데이터셋에서 YOLO 모델을 검증할 수 있습니다. 학습 후 검증 모드를 사용하여 성능을 평가할 수 있습니다:

from ultralytics import YOLO

# Load a YOLO model
model = YOLO("yolo26n.yaml")

# Train the model
model.train(data="coco8.yaml", epochs=5)

# Validate the model on a different dataset
model.val(data="path/to/separate/data.yaml")

상세한 예시와 사용법은 Val Mode 페이지를 확인하세요.

댓글