Python μ¬μ©λ²
YOLO11 Python μ¬μ© μ€λͺ μμ μ€μ κ²μ νμν©λλ€! μ΄ κ°μ΄λλ 물체 κ°μ§, μΈλΆν λ° λΆλ₯λ₯Ό μν΄ Python νλ‘μ νΈμ YOLO11 μ μννκ² ν΅ν©νλ λ° λμμ΄ λλλ‘ μ€κ³λμμ΅λλ€. μ¬κΈ°μμλ μ¬μ νμ΅λ λͺ¨λΈμ λ‘λ λ° μ¬μ©νκ³ , μ λͺ¨λΈμ νμ΅μν€κ³ , μ΄λ―Έμ§μ λν μμΈ‘μ μννλ λ°©λ²μ λ°°μλλ€. μ¬μ©νκΈ° μ¬μ΄ Python μΈν°νμ΄μ€λ YOLO11 μ Python νλ‘μ νΈμ ν΅ν©νμ¬ κ³ κΈ κ°μ²΄ κ°μ§ κΈ°λ₯μ λΉ λ₯΄κ² ꡬννλ €λ λͺ¨λ μ¬λμκ² μ μ©ν 리μμ€μ λλ€. μ§κΈ μμν΄λ³΄μΈμ!
Watch: λ§μ€ν°νκΈ° Ultralytics YOLO11 : Python
μλ₯Ό λ€μ΄, μ¬μ©μλ λͺ μ€μ μ½λλ§μΌλ‘ λͺ¨λΈμ λ‘λνκ³ , νμ΅νκ³ , μ ν¨μ± κ²μ¬ μΈνΈμμ μ±λ₯μ νκ°νκ³ , ONNX νμμΌλ‘ λ΄λ³΄λΌ μλ μμ΅λλ€.
Python
from ultralytics import YOLO
# Create a new YOLO model from scratch
model = YOLO("yolo11n.yaml")
# Load a pretrained YOLO model (recommended for training)
model = YOLO("yolo11n.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")
κΈ°μ°¨
νλ ¨ λͺ¨λλ μ¬μ©μ μ§μ λ°μ΄ν° μΈνΈμμ YOLO11 λͺ¨λΈμ νλ ¨νλ λ° μ¬μ©λ©λλ€. μ΄ λͺ¨λμμλ μ§μ λ λ°μ΄ν° μΈνΈμ νμ΄νΌνλΌλ―Έν°λ₯Ό μ¬μ©νμ¬ λͺ¨λΈμ νμ΅μν΅λλ€. νλ ¨ κ³Όμ μλ μ΄λ―Έμ§μμ κ°μ²΄μ ν΄λμ€μ μμΉλ₯Ό μ ννκ² μμΈ‘ν μ μλλ‘ λͺ¨λΈμ 맀κ°λ³μλ₯Ό μ΅μ ννλ μμ μ΄ ν¬ν¨λ©λλ€.
κΈ°μ°¨
Val
Val λͺ¨λλ YOLO11 λͺ¨λΈμ νμ΅ν ν κ²μ¦νλ λ° μ¬μ©λ©λλ€. μ΄ λͺ¨λμμλ μ ν¨μ± κ²μ¬ μΈνΈμμ λͺ¨λΈμ νκ°νμ¬ μ νλμ μΌλ°ν μ±λ₯μ μΈ‘μ ν©λλ€. μ΄ λͺ¨λλ λͺ¨λΈμ νμ΄νΌνλΌλ―Έν°λ₯Ό μ‘°μ νμ¬ μ±λ₯μ κ°μ νλ λ° μ¬μ©ν μ μμ΅λλ€.
Val
μμΈ‘
μμΈ‘ λͺ¨λλ μλ‘μ΄ μ΄λ―Έμ§ λλ λμμμ λν΄ νμ΅λ YOLO11 λͺ¨λΈμ μ¬μ©νμ¬ μμΈ‘νλ λ° μ¬μ©λ©λλ€. μ΄ λͺ¨λμμλ 체ν¬ν¬μΈνΈ νμΌμμ λͺ¨λΈμ΄ λ‘λλλ©°, μ¬μ©μλ μΆλ‘ μ μνν μ΄λ―Έμ§ λλ λμμμ μ 곡ν μ μμ΅λλ€. λͺ¨λΈμ μ λ ₯λ μ΄λ―Έμ§ λλ λμμμμ κ°μ²΄μ ν΄λμ€ λ° μμΉλ₯Ό μμΈ‘ν©λλ€.
μμΈ‘
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])
# results would be a list of Results object including all the predictions by default
# but be careful as it could occupy a lot memory when there're many images,
# especially the task is segmentation.
# 1. return as a list
results = model.predict(source="folder")
# results would be a generator which is more friendly to memory by setting stream=True
# 2. return as a generator
results = model.predict(source=0, stream=True)
for result in results:
# Detection
result.boxes.xyxy # box with xyxy format, (N, 4)
result.boxes.xywh # box with xywh format, (N, 4)
result.boxes.xyxyn # box with xyxy format but normalized, (N, 4)
result.boxes.xywhn # box with xywh format but normalized, (N, 4)
result.boxes.conf # confidence score, (N, 1)
result.boxes.cls # cls, (N, 1)
# Segmentation
result.masks.data # masks, (N, H, W)
result.masks.xy # x,y segments (pixels), List[segment] * N
result.masks.xyn # x,y segments (normalized), List[segment] * N
# Classification
result.probs # cls prob, (num_class, )
# Each result is composed of torch.Tensor by default,
# in which you can easily use following functionality:
result = result.cuda()
result = result.cpu()
result = result.to("cpu")
result = result.numpy()
λ΄λ³΄λ΄κΈ°
λ΄λ³΄λ΄κΈ° λͺ¨λλ YOLO11 λͺ¨λΈμ λ°°ν¬μ μ¬μ©ν μ μλ νμμΌλ‘ λ΄λ³΄λ΄λ λ° μ¬μ©λ©λλ€. μ΄ λͺ¨λμμλ λͺ¨λΈμ΄ λ€λ₯Έ μννΈμ¨μ΄ μ ν리μΌμ΄μ μ΄λ νλμ¨μ΄ μ₯μΉμμ μ¬μ©ν μ μλ νμμΌλ‘ λ³νλ©λλ€. μ΄ λͺ¨λλ λͺ¨λΈμ νλ‘λμ νκ²½μ λ°°ν¬ν λ μ μ©ν©λλ€.
λ΄λ³΄λ΄κΈ°
λμ λ°°μΉ ν¬κΈ°μ μ΄λ―Έμ§ ν¬κΈ°λ₯Ό μ¬μ©νμ¬ κ³΅μ YOLO11n λͺ¨λΈμ ONNX μΌλ‘ λ΄λ³΄λ λλ€.
νΈλ
μΆμ λͺ¨λλ YOLO11 λͺ¨λΈμ μ¬μ©νμ¬ μ€μκ°μΌλ‘ κ°μ²΄λ₯Ό μΆμ νλ λ° μ¬μ©λ©λλ€. μ΄ λͺ¨λμμλ 체ν¬ν¬μΈνΈ νμΌμμ λͺ¨λΈμ λ‘λνκ³ μ¬μ©μκ° μ€μκ° λΉλμ€ μ€νΈλ¦Όμ μ 곡νμ¬ μ€μκ° κ°μ²΄ μΆμ μ μνν μ μμ΅λλ€. μ΄ λͺ¨λλ κ°μ μμ€ν μ΄λ μμ¨ μ£Όν μ°¨λκ³Ό κ°μ μ ν리μΌμ΄μ μ μ μ©ν©λλ€.
νΈλ
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11n.pt") # load an official detection model
model = YOLO("yolo11n-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")
λ²€μΉλ§ν¬
λ²€μΉλ§ν¬ λͺ¨λλ YOLO11 μ λν λ€μν λ΄λ³΄λ΄κΈ° νμμ μλμ μ νλλ₯Ό νλ‘νμΌλ§νλ λ° μ¬μ©λ©λλ€. λ²€μΉλ§ν¬λ λ΄λ³΄λΈ νμμ ν¬κΈ°, λ΄λ³΄λΈ νμμ λν μ 보λ₯Ό μ 곡ν©λλ€. mAP50-95
λ©νΈλ¦(κ°μ²΄ κ°μ§ λ° μΈλΆνμ©) λλ accuracy_top5
λ©νΈλ¦(λΆλ₯μ©)κ³Ό ONNX, OpenVINO, TensorRT λ±κ³Ό κ°μ λ€μν λ΄λ³΄λ΄κΈ° νμμμ μ΄λ―Έμ§λΉ λ°λ¦¬μ΄ λ¨μμ μΆλ‘ μκ°μ νμΈν μ μμ΅λλ€. μ΄ μ 보λ μ¬μ©μκ° μλμ μ νμ±μ λν μꡬ μ¬νμ λ°λΌ νΉμ μ¬μ© μ¬λ‘μ λ§λ μ΅μ μ λ΄λ³΄λ΄κΈ° νμμ μ ννλ λ° λμμ΄ λ μ μμ΅λλ€.
λ²€μΉλ§ν¬
νΈλ μ΄λ μ¬μ©
YOLO
λͺ¨λΈ ν΄λμ€λ νΈλ μ΄λ ν΄λμ€μ μμ λ 벨 λνΌμ
λλ€. κ° YOLO μμ
μλ λ€μμ μμνλ μ체 νΈλ μ΄λκ° μμ΅λλ€. BaseTrainer
.
νμ§ νΈλ μ΄λ μμ
from ultralytics.models.yolo 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 = detect.DetectionTrainer(overrides=overrides)
νΈλ μ΄λλ₯Ό μ½κ² μ¬μ©μ μ§μ νμ¬ λ§μΆ€ν μμ
μ μ§μνκ±°λ R&D μμ΄λμ΄λ₯Ό νμν μ μμ΅λλ€. μ¬μ©μ μ§μ μ λν΄ μμΈν μμ보기 Trainers
, Validators
κ·Έλ¦¬κ³ Predictors
μ¬μ©μ μ§μ μΉμ
μμ νλ‘μ νΈ μꡬ μ¬νμ λ§κ² μ‘°μ ν μ μμ΅λλ€.
μμ£Ό 묻λ μ§λ¬Έ
κ°μ²΄ κ°μ§λ₯Ό μν΄ Python νλ‘μ νΈμ YOLO11 μ ν΅ν©νλ €λ©΄ μ΄λ»κ² ν΄μΌ νλμ?
Ultralytics YOLO11 μ Python νλ‘μ νΈμ ν΅ν©νλ λ°©λ²μ κ°λ¨ν©λλ€. 미리 νμ΅λ λͺ¨λΈμ λ‘λνκ±°λ μ²μλΆν° μ λͺ¨λΈμ νμ΅μν¬ μ μμ΅λλ€. μμνλ λ°©λ²μ λ€μκ³Ό κ°μ΅λλ€:
from ultralytics import YOLO
# Load a pretrained YOLO model
model = YOLO("yolo11n.pt")
# Perform object detection on an image
results = model("https://ultralytics.com/images/bus.jpg")
# Visualize the results
for result in results:
result.show()
μμΈ‘ λͺ¨λ μΉμ μμ λ μμΈν μμλ₯Ό νμΈνμΈμ.
YOLO11 μμ μ¬μ©ν μ μλ λ€μν λͺ¨λμλ μ΄λ€ κ²μ΄ μλμ?
Ultralytics YOLO11 λ λ€μν λ¨Έμ λ¬λ μν¬νλ‘μ°μ λ§λ λ€μν λͺ¨λλ₯Ό μ 곡ν©λλ€. μ¬κΈ°μλ λ€μμ΄ ν¬ν¨λ©λλ€:
- κΈ°μ°¨: μ¬μ©μ μ§μ λ°μ΄ν° μΈνΈλ₯Ό μ¬μ©νμ¬ λͺ¨λΈμ νμ΅ν©λλ€.
- Val: μ ν¨μ± κ²μ¬ μΈνΈμμ λͺ¨λΈ μ±λ₯μ κ²μ¦ν©λλ€.
- μμΈ‘: μλ‘μ΄ μ΄λ―Έμ§ λλ λΉλμ€ μ€νΈλ¦Όμ μμΈ‘ν©λλ€.
- λ΄λ³΄λ΄κΈ°: λ΄λ³΄λ΄κΈ° : ONNX, TensorRT κ³Ό κ°μ λ€μν νμμΌλ‘ λͺ¨λΈμ λ΄λ³΄λ λλ€.
- νΈλ: λΉλμ€ μ€νΈλ¦Όμμ μ€μκ° κ°μ²΄ μΆμ .
- λ²€μΉλ§ν¬: λ€μν ꡬμ±μμ λͺ¨λΈ μ±λ₯μ λ²€μΉλ§ν¬ν©λλ€.
κ° λͺ¨λλ λͺ¨λΈ κ°λ° λ° λ°°ν¬μ λ€μν λ¨κ³λ₯Ό μν ν¬κ΄μ μΈ κΈ°λ₯μ μ 곡νλλ‘ μ€κ³λμμ΅λλ€.
λ΄ λ°μ΄ν° μ§ν©μ μ¬μ©νμ¬ μ¬μ©μ μ§μ YOLO11 λͺ¨λΈμ νμ΅νλ €λ©΄ μ΄λ»κ² νλμ?
μ¬μ©μ μ§μ YOLO11 λͺ¨λΈμ νμ΅νλ €λ©΄ λ°μ΄ν° μΈνΈ λ° κΈ°ν νμ΄νΌνλΌλ―Έν°λ₯Ό μ§μ ν΄μΌ ν©λλ€. λ€μμ κ°λ¨ν μμμ λλ€:
from ultralytics import YOLO
# Load the YOLO model
model = YOLO("yolo11n.yaml")
# Train the model with custom dataset
model.train(data="path/to/your/dataset.yaml", epochs=10)
κ΅μ‘μ λν μμΈν λ΄μ©κ³Ό μμ μ¬μ©λ²μ λν νμ΄νΌλ§ν¬λ κ΅μ‘ λͺ¨λ νμ΄μ§λ₯Ό μ°Έμ‘°νμΈμ.
λ°°ν¬λ₯Ό μν΄ YOLO11 λͺ¨λΈμ λ΄λ³΄λ΄λ €λ©΄ μ΄λ»κ² νλμ?
λ°°ν¬μ μ ν©ν νμμΌλ‘ YOLO11 λͺ¨λΈμ λ΄λ³΄λ΄λ κ²μ λ€μκ³Ό κ°μ΄ κ°λ¨ν©λλ€. export
ν¨μλ₯Ό μ¬μ©νμΈμ. μλ₯Ό λ€μ΄ λͺ¨λΈμ ONNX νμμΌλ‘ λ΄λ³΄λΌ μ μμ΅λλ€:
from ultralytics import YOLO
# Load the YOLO model
model = YOLO("yolo11n.pt")
# Export the model to ONNX format
model.export(format="onnx")
λ€μν λ΄λ³΄λ΄κΈ° μ΅μ μ λν΄μλ λ΄λ³΄λ΄κΈ° λͺ¨λ λ¬Έμλ₯Ό μ°Έμ‘°νμΈμ.
λ€λ₯Έ λ°μ΄ν° μΈνΈμμ YOLO11 λͺ¨λΈμ μ ν¨μ±μ κ²μ¬ν μ μλμ?
μ, λ€λ₯Έ λ°μ΄ν° μΈνΈμμ YOLO11 λͺ¨λΈμ κ²μ¦ν μ μμ΅λλ€. νμ΅ ν μ ν¨μ± κ²μ¬ λͺ¨λλ₯Ό μ¬μ©νμ¬ μ±λ₯μ νκ°ν μ μμ΅λλ€:
from ultralytics import YOLO
# Load a YOLO11 model
model = YOLO("yolo11n.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 λͺ¨λ νμ΄μ§μμ νμΈνμΈμ.