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

๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋ธ ์˜ˆ์ธก Ultralytics YOLO

Ultralytics YOLO ์—์ฝ”์‹œ์Šคํ…œ ๋ฐ ํ†ตํ•ฉ

์†Œ๊ฐœ

๋จธ์‹ ๋Ÿฌ๋‹๊ณผ ์ปดํ“จํ„ฐ ๋น„์ „ ๋ถ„์•ผ์—์„œ ์‹œ๊ฐ์  ๋ฐ์ดํ„ฐ์—์„œ ์˜๋ฏธ๋ฅผ ์ฐพ์•„๋‚ด๋Š” ๊ณผ์ •์„ '์ถ”๋ก ' ๋˜๋Š” '์˜ˆ์ธก'์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. Ultralytics YOLOv8 ์€ ๊ด‘๋ฒ”์œ„ํ•œ ๋ฐ์ดํ„ฐ ์†Œ์Šค์— ๋Œ€ํ•œ ๊ณ ์„ฑ๋Šฅ ์‹ค์‹œ๊ฐ„ ์ถ”๋ก ์„ ์œ„ํ•ด ๋งž์ถคํ™”๋œ ์˜ˆ์ธก ๋ชจ๋“œ๋ผ๋Š” ๊ฐ•๋ ฅํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.



Watch: Ultralytics YOLOv8 ์—์„œ ์ถœ๋ ฅ์„ ์ถ”์ถœํ•˜๋Š” ๋ฐฉ๋ฒ• ์‚ฌ์šฉ์ž ์ง€์ • ํ”„๋กœ์ ํŠธ์šฉ ๋ชจ๋ธ.

์‹ค์ œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜

์ œ์กฐ ์Šคํฌ์ธ  ์•ˆ์ „
์ฐจ๋Ÿ‰ ์˜ˆ๋น„ ๋ถ€ํ’ˆ ๊ฐ์ง€ ์ถ•๊ตฌ ์„ ์ˆ˜ ๊ฐ์ง€ ์‚ฌ๋žŒ ๋‚™์ƒ ๊ฐ์ง€
์ฐจ๋Ÿ‰ ์˜ˆ๋น„ ๋ถ€ํ’ˆ ๊ฐ์ง€ ์ถ•๊ตฌ ์„ ์ˆ˜ ๊ฐ์ง€ ์‚ฌ๋žŒ ๋‚™์ƒ ๊ฐ์ง€

์ถ”๋ก ์— Ultralytics YOLO ์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?

๋‹ค์–‘ํ•œ ์ถ”๋ก  ์š”๊ตฌ์— ๋งž๋Š” YOLOv8 ์˜ ์˜ˆ์ธก ๋ชจ๋“œ๋ฅผ ๊ณ ๋ คํ•ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

  • ๋‹ค์šฉ๋„์„ฑ: ์ด๋ฏธ์ง€, ๋™์˜์ƒ, ๋ผ์ด๋ธŒ ์ŠคํŠธ๋ฆผ๊นŒ์ง€ ์ถ”๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์„ฑ๋Šฅ: ์ •ํ™•๋„ ์ €ํ•˜ ์—†์ด ์‹ค์‹œ๊ฐ„ ๊ณ ์† ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด ์„ค๊ณ„๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
  • ์‚ฌ์šฉ ํŽธ์˜์„ฑ: ์‹ ์†ํ•œ ๋ฐฐํฌ ๋ฐ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ์ง๊ด€์ ์ธ Python ๋ฐ CLI ์ธํ„ฐํŽ˜์ด์Šค.
  • ๊ณ ๋„์˜ ์‚ฌ์šฉ์ž ์ •์˜: ํŠน์ • ์š”๊ตฌ ์‚ฌํ•ญ์— ๋”ฐ๋ผ ๋ชจ๋ธ์˜ ์ถ”๋ก  ๋™์ž‘์„ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๋‹ค์–‘ํ•œ ์„ค์ • ๋ฐ ๋งค๊ฐœ๋ณ€์ˆ˜.

์˜ˆ์ธก ๋ชจ๋“œ์˜ ์ฃผ์š” ๊ธฐ๋Šฅ

YOLOv8์˜ ์˜ˆ์ธก ๋ชจ๋“œ๋Š” ๊ฐ•๋ ฅํ•˜๊ณ  ๋‹ค์šฉ๋„๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค๊ณ„๋˜์—ˆ์Šต๋‹ˆ๋‹ค:

  • ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ์†Œ์Šค ํ˜ธํ™˜์„ฑ: ๋ฐ์ดํ„ฐ๊ฐ€ ๊ฐœ๋ณ„ ์ด๋ฏธ์ง€, ์ด๋ฏธ์ง€ ๋ชจ์Œ, ๋™์˜์ƒ ํŒŒ์ผ, ์‹ค์‹œ๊ฐ„ ๋™์˜์ƒ ์ŠคํŠธ๋ฆผ ๋“ฑ ์–ด๋–ค ํ˜•ํƒœ์ด๋“  ์˜ˆ์ธก ๋ชจ๋“œ์—์„œ ๋ชจ๋‘ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
  • ์ŠคํŠธ๋ฆฌ๋ฐ ๋ชจ๋“œ: ์ŠคํŠธ๋ฆฌ๋ฐ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฉ”๋ชจ๋ฆฌ ํšจ์œจ์ ์ธ ์ œ๋„ˆ๋ ˆ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Results ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์„ค์ •ํ•˜์—ฌ ์ด ๊ธฐ๋Šฅ์„ ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค. stream=True ๋ฅผ ์˜ˆ์ธก์ž์˜ ํ˜ธ์ถœ ๋ฉ”์„œ๋“œ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
  • ์ผ๊ด„ ์ฒ˜๋ฆฌ: ์—ฌ๋Ÿฌ ์ด๋ฏธ์ง€ ๋˜๋Š” ๋น„๋””์˜ค ํ”„๋ ˆ์ž„์„ ํ•œ ๋ฒˆ์— ์ฒ˜๋ฆฌํ•˜๋Š” ๊ธฐ๋Šฅ์œผ๋กœ ์ถ”๋ก  ์‹œ๊ฐ„์„ ๋”์šฑ ๋‹จ์ถ•ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ํ†ตํ•ฉ ์นœํ™”์ : ์œ ์—ฐํ•œ API ๋•๋ถ„์— ๊ธฐ์กด ๋ฐ์ดํ„ฐ ํŒŒ์ดํ”„๋ผ์ธ ๋ฐ ๊ธฐํƒ€ ์†Œํ”„ํŠธ์›จ์–ด ๊ตฌ์„ฑ ์š”์†Œ์™€ ์‰ฝ๊ฒŒ ํ†ตํ•ฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Ultralytics YOLO ๋ชจ๋ธ์€ Python ๋ชฉ๋ก ์ค‘ ํ•˜๋‚˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. Results ๊ฐ์ฒด, ๋˜๋Š” ๋ฉ”๋ชจ๋ฆฌ ํšจ์œจ์ ์ธ Python ์ƒ์„ฑ๊ธฐ์˜ Results ๊ฐ์ฒด๋ฅผ stream=True ๋Š” ์ถ”๋ก  ์ค‘์— ๋ชจ๋ธ์— ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค:

์˜ˆ์ธก

from ultralytics import YOLO

# Load a model
model = YOLO('yolov8n.pt')  # pretrained YOLOv8n model

# Run batched inference on a list of images
results = model(['im1.jpg', 'im2.jpg'])  # return a list of Results objects

# Process results list
for result in results:
    boxes = result.boxes  # Boxes object for bounding box outputs
    masks = result.masks  # Masks object for segmentation masks outputs
    keypoints = result.keypoints  # Keypoints object for pose outputs
    probs = result.probs  # Probs object for classification outputs
    result.show()  # display to screen
    result.save(filename='result.jpg')  # save to disk
from ultralytics import YOLO

# Load a model
model = YOLO('yolov8n.pt')  # pretrained YOLOv8n model

# Run batched inference on a list of images
results = model(['im1.jpg', 'im2.jpg'], stream=True)  # return a generator of Results objects

# Process results generator
for result in results:
    boxes = result.boxes  # Boxes object for bounding box outputs
    masks = result.masks  # Masks object for segmentation masks outputs
    keypoints = result.keypoints  # Keypoints object for pose outputs
    probs = result.probs  # Probs object for classification outputs
    result.show()  # display to screen
    result.save(filename='result.jpg')  # save to disk

์ถ”๋ก  ์†Œ์Šค

YOLOv8 ๋Š” ์•„๋ž˜ ํ‘œ์™€ ๊ฐ™์ด ๋‹ค์–‘ํ•œ ์œ ํ˜•์˜ ์ž…๋ ฅ ์†Œ์Šค๋ฅผ ์ฒ˜๋ฆฌํ•˜์—ฌ ์ถ”๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์†Œ์Šค์—๋Š” ์ •์  ์ด๋ฏธ์ง€, ๋น„๋””์˜ค ์ŠคํŠธ๋ฆผ ๋ฐ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ํ˜•์‹์ด ํฌํ•จ๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ์ด ํ‘œ์—๋Š” ๊ฐ ์†Œ์Šค๋ฅผ ์ŠคํŠธ๋ฆฌ๋ฐ ๋ชจ๋“œ์—์„œ ์ธ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์—ฌ๋ถ€๋„ ํ‘œ์‹œ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. stream=True โœ…. ์ŠคํŠธ๋ฆฌ๋ฐ ๋ชจ๋“œ๋Š” ๋ชจ๋“  ํ”„๋ ˆ์ž„์„ ๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋“œํ•˜๋Š” ๋Œ€์‹  ๊ฒฐ๊ณผ ์ƒ์„ฑ๊ธฐ๋ฅผ ์ƒ์„ฑํ•˜๋ฏ€๋กœ ๋™์˜์ƒ ๋˜๋Š” ๋ผ์ด๋ธŒ ์ŠคํŠธ๋ฆผ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

ํŒ

์‚ฌ์šฉ stream=True ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ธด ๋™์˜์ƒ์ด๋‚˜ ๋Œ€์šฉ๋Ÿ‰ ๋ฐ์ดํ„ฐ ์„ธํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์–ธ์ œ stream=False๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ชจ๋“  ํ”„๋ ˆ์ž„ ๋˜๋Š” ๋ฐ์ดํ„ฐ ํฌ์ธํŠธ์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅ๋˜๋ฏ€๋กœ ๋น ๋ฅด๊ฒŒ ํ•ฉ์‚ฐ๋˜์–ด ํฐ ์ž…๋ ฅ๊ฐ’์˜ ๊ฒฝ์šฐ ๋ฉ”๋ชจ๋ฆฌ ๋ถ€์กฑ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ˜๋Œ€๋กœ stream=True ๋Š” ํ˜„์žฌ ํ”„๋ ˆ์ž„ ๋˜๋Š” ๋ฐ์ดํ„ฐ ํฌ์ธํŠธ์˜ ๊ฒฐ๊ณผ๋งŒ ๋ฉ”๋ชจ๋ฆฌ์— ๋ณด๊ด€ํ•˜๋Š” ์ œ๋„ˆ๋ ˆ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ ์†Œ๋น„๋ฅผ ํฌ๊ฒŒ ์ค„์ด๊ณ  ๋ฉ”๋ชจ๋ฆฌ ๋ถ€์กฑ ๋ฌธ์ œ๋ฅผ ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค.

์ถœ์ฒ˜ ์ธ์ˆ˜ ์œ ํ˜• ์ฐธ๊ณ  ์‚ฌํ•ญ
์ด๋ฏธ์ง€ 'image.jpg' str ๋˜๋Š” Path ๋‹จ์ผ ์ด๋ฏธ์ง€ ํŒŒ์ผ.
URL 'https://ultralytics.com/images/bus.jpg' str ์ด๋ฏธ์ง€์˜ URL์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
์Šคํฌ๋ฆฐ์ƒท 'screen' str ์Šคํฌ๋ฆฐ์ƒท์„ ์บก์ฒ˜ํ•ฉ๋‹ˆ๋‹ค.
PIL Image.open('im.jpg') PIL.Image RGB ์ฑ„๋„์ด ํฌํ•จ๋œ HWC ํฌ๋งท.
OpenCV cv2.imread('im.jpg') np.ndarray BGR ์ฑ„๋„์ด ํฌํ•จ๋œ HWC ํ˜•์‹ uint8 (0-255).
numpy np.zeros((640,1280,3)) np.ndarray BGR ์ฑ„๋„์ด ํฌํ•จ๋œ HWC ํ˜•์‹ uint8 (0-255).
torch torch.zeros(16,3,320,640) torch.Tensor RGB ์ฑ„๋„์ด ํฌํ•จ๋œ BCHW ํฌ๋งท float32 (0.0-1.0).
CSV 'sources.csv' str ๋˜๋Š” Path ์ด๋ฏธ์ง€, ๋™์˜์ƒ ๋˜๋Š” ๋””๋ ‰ํ„ฐ๋ฆฌ ๊ฒฝ๋กœ๊ฐ€ ํฌํ•จ๋œ CSV ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.
๋™์˜์ƒ โœ… 'video.mp4' str ๋˜๋Š” Path MP4, AVI ๋“ฑ์˜ ํ˜•์‹์˜ ๋™์˜์ƒ ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.
๋””๋ ‰ํ† ๋ฆฌ โœ… 'path/' str ๋˜๋Š” Path ์ด๋ฏธ์ง€ ๋˜๋Š” ๋™์˜์ƒ์ด ํฌํ•จ๋œ ๋””๋ ‰ํ† ๋ฆฌ์˜ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.
๊ธ€๋กœ๋ธŒ โœ… 'path/*.jpg' str ๊ธ€๋กœ๋ธŒ ํŒจํ„ด์œผ๋กœ ์—ฌ๋Ÿฌ ํŒŒ์ผ์„ ์ผ์น˜์‹œํ‚ต๋‹ˆ๋‹ค. ํŒŒ์ผ์—์„œ * ๋ฌธ์ž๋ฅผ ์™€์ผ๋“œ์นด๋“œ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
YouTube โœ… 'https://youtu.be/LNwODJXcvt4' str YouTube ๋™์˜์ƒ์˜ URL์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
์ŠคํŠธ๋ฆผ โœ… 'rtsp://example.com/media.mp4' str RTSP, RTMP, TCP ๋˜๋Š” IP ์ฃผ์†Œ์™€ ๊ฐ™์€ ์ŠคํŠธ๋ฆฌ๋ฐ ํ”„๋กœํ† ์ฝœ์šฉ URL์ž…๋‹ˆ๋‹ค.
๋ฉ€ํ‹ฐ์ŠคํŠธ๋ฆผ โœ… 'list.streams' str ๋˜๋Š” Path *.streams ํ…์ŠคํŠธ ํŒŒ์ผ์— ํ–‰๋‹น ํ•˜๋‚˜์˜ ์ŠคํŠธ๋ฆผ URL์ด ์žˆ๋Š” ๊ฒฝ์šฐ, ์ฆ‰ 8๊ฐœ์˜ ์ŠคํŠธ๋ฆผ์ด ๋ฐฐ์น˜ ํฌ๊ธฐ 8๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ์€ ๊ฐ ์†Œ์Šค ์œ ํ˜•์„ ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค:

์˜ˆ์ธก ์†Œ์Šค

์ด๋ฏธ์ง€ ํŒŒ์ผ์—์„œ ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Define path to the image file
source = 'path/to/image.jpg'

# Run inference on the source
results = model(source)  # list of Results objects

ํ˜„์žฌ ํ™”๋ฉด ์ฝ˜ํ…์ธ ์— ๋Œ€ํ•œ ์ถ”๋ก ์„ ์Šคํฌ๋ฆฐ์ƒท์œผ๋กœ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Define current screenshot as source
source = 'screen'

# Run inference on the source
results = model(source)  # list of Results objects

URL์„ ํ†ตํ•ด ์›๊ฒฉ์œผ๋กœ ํ˜ธ์ŠคํŒ…๋œ ์ด๋ฏธ์ง€ ๋˜๋Š” ๋™์˜์ƒ์—์„œ ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Define remote image or video URL
source = 'https://ultralytics.com/images/bus.jpg'

# Run inference on the source
results = model(source)  # list of Results objects

Python ์ด๋ฏธ์ง• ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ(PIL)๋กœ ์—ฐ ์ด๋ฏธ์ง€์—์„œ ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

from PIL import Image
from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Open an image using PIL
source = Image.open('path/to/image.jpg')

# Run inference on the source
results = model(source)  # list of Results objects

OpenCV๋กœ ์ฝ์€ ์ด๋ฏธ์ง€์—์„œ ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

import cv2
from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Read an image using OpenCV
source = cv2.imread('path/to/image.jpg')

# Run inference on the source
results = model(source)  # list of Results objects

๋„ ๋ฐฐ์—ด๋กœ ํ‘œํ˜„๋œ ์ด๋ฏธ์ง€์—์„œ ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

import numpy as np
from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Create a random numpy array of HWC shape (640, 640, 3) with values in range [0, 255] and type uint8
source = np.random.randint(low=0, high=255, size=(640, 640, 3), dtype='uint8')

# Run inference on the source
results = model(source)  # list of Results objects

PyTorch tensor ์œผ๋กœ ํ‘œ์‹œ๋œ ์ด๋ฏธ์ง€์—์„œ ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

import torch
from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Create a random torch tensor of BCHW shape (1, 3, 640, 640) with values in range [0, 1] and type float32
source = torch.rand(1, 3, 640, 640, dtype=torch.float32)

# Run inference on the source
results = model(source)  # list of Results objects

CSV ํŒŒ์ผ์— ๋‚˜์—ด๋œ ์ด๋ฏธ์ง€, URL, ๋™์˜์ƒ ๋ฐ ๋””๋ ‰ํ„ฐ๋ฆฌ ๋ชจ์Œ์— ๋Œ€ํ•ด ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

import torch
from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Define a path to a CSV file with images, URLs, videos and directories
source = 'path/to/file.csv'

# Run inference on the source
results = model(source)  # list of Results objects

๋น„๋””์˜ค ํŒŒ์ผ์—์„œ ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ stream=True๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฒฐ๊ณผ ๊ฐ์ฒด ์ƒ์„ฑ๊ธฐ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰์„ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Define path to video file
source = 'path/to/video.mp4'

# Run inference on the source
results = model(source, stream=True)  # generator of Results objects

๋””๋ ‰ํ† ๋ฆฌ์— ์žˆ๋Š” ๋ชจ๋“  ์ด๋ฏธ์ง€์™€ ๋™์˜์ƒ์— ๋Œ€ํ•ด ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ํ•˜์œ„ ๋””๋ ‰ํ† ๋ฆฌ์— ์žˆ๋Š” ์ด๋ฏธ์ง€์™€ ๋™์˜์ƒ๋„ ์บก์ฒ˜ํ•˜๋ ค๋ฉด ๊ธ€๋กœ๋ธŒ ํŒจํ„ด์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. path/to/dir/**/*.

from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Define path to directory containing images and videos for inference
source = 'path/to/dir'

# Run inference on the source
results = model(source, stream=True)  # generator of Results objects

๊ธ€๋กœ๋ธŒ ํ‘œํ˜„์‹๊ณผ ์ผ์น˜ํ•˜๋Š” ๋ชจ๋“  ์ด๋ฏธ์ง€์™€ ๋™์˜์ƒ์— ๋Œ€ํ•ด ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. * ๋ฌธ์ž.

from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Define a glob search for all JPG files in a directory
source = 'path/to/dir/*.jpg'

# OR define a recursive glob search for all JPG files including subdirectories
source = 'path/to/dir/**/*.jpg'

# Run inference on the source
results = model(source, stream=True)  # generator of Results objects

YouTube ๋™์˜์ƒ์—์„œ ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ stream=True๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฒฐ๊ณผ ๊ฐ์ฒด ์ƒ์„ฑ๊ธฐ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ๊ธด ๋™์˜์ƒ์˜ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰์„ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Define source as YouTube video URL
source = 'https://youtu.be/LNwODJXcvt4'

# Run inference on the source
results = model(source, stream=True)  # generator of Results objects

RTSP, RTMP, TCP ๋ฐ IP ์ฃผ์†Œ ํ”„๋กœํ† ์ฝœ์„ ์‚ฌ์šฉํ•˜์—ฌ ์›๊ฒฉ ์ŠคํŠธ๋ฆฌ๋ฐ ์†Œ์Šค์—์„œ ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ํ•˜๋‚˜์˜ ์ŠคํŠธ๋ฆผ์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ŠคํŠธ๋ฆผ์ด ์ œ๊ณต๋˜๋Š” ๊ฒฝ์šฐ *.streams ํ…์ŠคํŠธ ํŒŒ์ผ์„ ์ž…๋ ฅํ•˜๋ฉด ์ผ๊ด„ ์ถ”๋ก ์ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ์ฆ‰, 8๊ฐœ์˜ ์ŠคํŠธ๋ฆผ์ด ๋ฐฐ์น˜ ํฌ๊ธฐ 8๋กœ ์‹คํ–‰๋˜๊ณ , ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ๋‹จ์ผ ์ŠคํŠธ๋ฆผ์ด ๋ฐฐ์น˜ ํฌ๊ธฐ 1๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Single stream with batch-size 1 inference
source = 'rtsp://example.com/media.mp4'  # RTSP, RTMP, TCP or IP streaming address

# Multiple streams with batched inference (i.e. batch-size 8 for 8 streams)
source = 'path/to/list.streams'  # *.streams text file with one streaming address per row

# Run inference on the source
results = model(source, stream=True)  # generator of Results objects

์ถ”๋ก  ์ธ์ˆ˜

model.predict() ๋Š” ์ถ”๋ก  ์‹œ ๊ธฐ๋ณธ๊ฐ’์„ ์žฌ์ •์˜ํ•˜๊ธฐ ์œ„ํ•ด ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š” ์—ฌ๋Ÿฌ ์ธ์ˆ˜๋ฅผ ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค:

์˜ˆ์ œ

from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Run inference on 'bus.jpg' with arguments
model.predict('bus.jpg', save=True, imgsz=320, conf=0.5)

์ถ”๋ก  ์ธ์ˆ˜:

์ธ์ˆ˜ ์œ ํ˜• ๊ธฐ๋ณธ๊ฐ’ ์„ค๋ช…
source str 'ultralytics/assets' ์ถ”๋ก ํ•  ๋ฐ์ดํ„ฐ ์†Œ์Šค๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฏธ์ง€ ๊ฒฝ๋กœ, ๋™์˜์ƒ ํŒŒ์ผ, ๋””๋ ‰ํ† ๋ฆฌ, URL ๋˜๋Š” ์‹ค์‹œ๊ฐ„ ํ”ผ๋“œ์šฉ ๋””๋ฐ”์ด์Šค ID๊ฐ€ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์–‘ํ•œ ํ˜•์‹๊ณผ ์†Œ์Šค๋ฅผ ์ง€์›ํ•˜๋ฏ€๋กœ ๋‹ค์–‘ํ•œ ์œ ํ˜•์˜ ์ž…๋ ฅ์— ์œ ์—ฐํ•˜๊ฒŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
conf float 0.25 ํƒ์ง€์— ๋Œ€ํ•œ ์ตœ์†Œ ์‹ ๋ขฐ๋„ ์ž„๊ณ„๊ฐ’์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ด ์ž„๊ณ„๊ฐ’๋ณด๋‹ค ๋‚ฎ์€ ์‹ ๋ขฐ๋„๋กœ ํƒ์ง€๋œ ๊ฐœ์ฒด๋Š” ๋ฌด์‹œ๋ฉ๋‹ˆ๋‹ค. ์ด ๊ฐ’์„ ์กฐ์ •ํ•˜๋ฉด ์˜คํƒ์ง€๋ฅผ ์ค„์ด๋Š” ๋ฐ ๋„์›€์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
iou float 0.7 ๋น„์ตœ๋Œ€ ์–ต์ œ(NMS)์— ๋Œ€ํ•œ ๊ต์ฐจ์  ์ดˆ๊ณผ(IoU) ์ž„๊ณ„๊ฐ’์ž…๋‹ˆ๋‹ค. ๊ฐ’์ด ๋†’์„์ˆ˜๋ก ์ค‘๋ณต๋˜๋Š” ์ƒ์ž๋ฅผ ์ œ๊ฑฐํ•˜์—ฌ ํƒ์ง€ ํšŸ์ˆ˜๊ฐ€ ์ค„์–ด๋“ค์–ด ์ค‘๋ณต์„ ์ค„์ด๋Š” ๋ฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
imgsz int or tuple 640 ์ถ”๋ก ํ•  ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ๋‹จ์ผ ์ •์ˆ˜์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 640 ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ •์‚ฌ๊ฐํ˜• ํฌ๊ธฐ ์กฐ์ • ๋˜๋Š” (๋†’์ด, ๋„ˆ๋น„) ํŠœํ”Œ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ ์ ˆํ•œ ํฌ๊ธฐ ์กฐ์ •์€ ๊ฐ์ง€ ์ •ํ™•๋„์™€ ์ฒ˜๋ฆฌ ์†๋„๋ฅผ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
half bool False ์ •ํ™•๋„์— ๋ฏธ์น˜๋Š” ์˜ํ–ฅ์„ ์ตœ์†Œํ™”ํ•˜๋ฉด์„œ ์ง€์›๋˜๋Š” GPU์—์„œ ๋ชจ๋ธ ์ถ”๋ก  ์†๋„๋ฅผ ๋†’์ผ ์ˆ˜ ์žˆ๋Š” ๋ฐ˜์ •ํ™•๋„(FP16) ์ถ”๋ก ์„ ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค.
device str None ์ถ”๋ก ํ•  ์žฅ์น˜๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค(์˜ˆ, cpu, cuda:0 ๋˜๋Š” 0). ์‚ฌ์šฉ์ž๊ฐ€ ๋ชจ๋ธ ์‹คํ–‰์„ ์œ„ํ•ด CPU, ํŠน์ • GPU ๋˜๋Š” ๊ธฐํƒ€ ์ปดํ“จํŒ… ์žฅ์น˜ ์ค‘์—์„œ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
max_det int 300 ์ด๋ฏธ์ง€๋‹น ํ—ˆ์šฉ๋˜๋Š” ์ตœ๋Œ€ ๊ฐ์ง€ ํšŸ์ˆ˜. ๋ชจ๋ธ์ด ํ•œ ๋ฒˆ์˜ ์ถ”๋ก ์—์„œ ๊ฐ์ง€ํ•  ์ˆ˜ ์žˆ๋Š” ์ด ์˜ค๋ธŒ์ ํŠธ ์ˆ˜๋ฅผ ์ œํ•œํ•˜์—ฌ ๋ฐ€์ง‘๋œ ์žฅ๋ฉด์—์„œ ๊ณผ๋„ํ•œ ์ถœ๋ ฅ์„ ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค.
vid_stride int 1 ๋น„๋””์˜ค ์ž…๋ ฅ์˜ ํ”„๋ ˆ์ž„ ๋ณดํญ. ๋™์˜์ƒ์—์„œ ํ”„๋ ˆ์ž„์„ ๊ฑด๋„ˆ๋›ฐ์–ด ์‹œ๊ฐ„ ํ•ด์ƒ๋„๋ฅผ ํฌ์ƒํ•˜๋ฉด์„œ ์ฒ˜๋ฆฌ ์†๋„๋ฅผ ๋†’์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ’์ด 1์ด๋ฉด ๋ชจ๋“  ํ”„๋ ˆ์ž„์„ ์ฒ˜๋ฆฌํ•˜๊ณ , ๊ฐ’์ด ํด์ˆ˜๋ก ํ”„๋ ˆ์ž„์„ ๊ฑด๋„ˆ๋œ๋‹ˆ๋‹ค.
stream_buffer bool False ๋น„๋””์˜ค ์ŠคํŠธ๋ฆผ์„ ์ฒ˜๋ฆฌํ•  ๋•Œ ๋ชจ๋“  ํ”„๋ ˆ์ž„์„ ๋ฒ„ํผ๋งํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค(True), ๋˜๋Š” ๋ชจ๋ธ์ด ๊ฐ€์žฅ ์ตœ๊ทผ ํ”„๋ ˆ์ž„์„ ๋ฐ˜ํ™˜ํ•ด์•ผ ํ•˜๋Š”์ง€(False). ์‹ค์‹œ๊ฐ„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
visualize bool False ์ถ”๋ก  ์ค‘์— ๋ชจ๋ธ ๊ธฐ๋Šฅ์˜ ์‹œ๊ฐํ™”๋ฅผ ํ™œ์„ฑํ™”ํ•˜์—ฌ ๋ชจ๋ธ์ด '๋ณด๊ณ  ์žˆ๋Š” ๊ฒƒ'์— ๋Œ€ํ•œ ์ธ์‚ฌ์ดํŠธ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋””๋ฒ„๊น… ๋ฐ ๋ชจ๋ธ ํ•ด์„์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
augment bool False ์˜ˆ์ธก์„ ์œ„ํ•œ ํ…Œ์ŠคํŠธ ์‹œ๊ฐ„ ์ฆ๊ฐ•(TTA)์„ ์ง€์›ํ•˜์—ฌ ์ถ”๋ก  ์†๋„๋ฅผ ํฌ์ƒํ•˜๋”๋ผ๋„ ํƒ์ง€ ๊ฒฌ๊ณ ์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
agnostic_nms bool False ์„œ๋กœ ๋‹ค๋ฅธ ํด๋ž˜์Šค์˜ ๊ฒน์น˜๋Š” ์ƒ์ž๋ฅผ ๋ณ‘ํ•ฉํ•˜๋Š” ํด๋ž˜์Šค ๋ฌด๊ด€ NMS(Non-Maximum Suppression)๋ฅผ ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค. ํด๋ž˜์Šค ์ค‘๋ณต์ด ์ผ๋ฐ˜์ ์ธ ๋‹ค์ค‘ ํด๋ž˜์Šค ํƒ์ง€ ์‹œ๋‚˜๋ฆฌ์˜ค์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
classes list[int] None ํด๋ž˜์Šค ID ์ง‘ํ•ฉ์œผ๋กœ ์˜ˆ์ธก์„ ํ•„ํ„ฐ๋งํ•ฉ๋‹ˆ๋‹ค. ์ง€์ •๋œ ํด๋ž˜์Šค์— ์†ํ•˜๋Š” ํƒ์ง€๋งŒ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค. ๋‹ค์ค‘ ํด๋ž˜์Šค ํƒ์ง€ ์ž‘์—…์—์„œ ๊ด€๋ จ ๊ฐœ์ฒด์— ์ง‘์ค‘ํ•˜๋Š” ๋ฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
retina_masks bool False ๋ชจ๋ธ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ ๊ณ ํ•ด์ƒ๋„ ์„ธ๋ถ„ํ™” ๋งˆ์Šคํฌ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์„ธ๋ถ„ํ™” ์ž‘์—…์˜ ๋งˆ์Šคํฌ ํ’ˆ์งˆ์„ ํ–ฅ์ƒ์‹œ์ผœ ๋” ์„ธ๋ฐ€ํ•œ ๋””ํ…Œ์ผ์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
embed list[int] None ํŠน์ง• ๋ฒกํ„ฐ ๋˜๋Š” ์ž„๋ฒ ๋”ฉ์„ ์ถ”์ถœํ•  ๋ ˆ์ด์–ด๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ํด๋Ÿฌ์Šคํ„ฐ๋ง์ด๋‚˜ ์œ ์‚ฌ๋„ ๊ฒ€์ƒ‰๊ณผ ๊ฐ™์€ ๋‹ค์šด์ŠคํŠธ๋ฆผ ์ž‘์—…์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

์‹œ๊ฐํ™” ์ธ์ˆ˜์ž…๋‹ˆ๋‹ค:

์ธ์ˆ˜ ์œ ํ˜• ๊ธฐ๋ณธ๊ฐ’ ์„ค๋ช…
show bool False ๋งŒ์•ฝ True๋ฅผ ํด๋ฆญํ•˜๋ฉด ์ฃผ์„์ด ๋‹ฌ๋ฆฐ ์ด๋ฏธ์ง€ ๋˜๋Š” ๋™์˜์ƒ์ด ์ฐฝ์— ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ ๋˜๋Š” ํ…Œ์ŠคํŠธ ์ค‘์— ์ฆ‰๊ฐ์ ์ธ ์‹œ๊ฐ์  ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›์„ ๋•Œ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
save bool False ์ฃผ์„์ด ๋‹ฌ๋ฆฐ ์ด๋ฏธ์ง€๋‚˜ ๋™์˜์ƒ์„ ํŒŒ์ผ๋กœ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฌธ์„œํ™”, ์ถ”๊ฐ€ ๋ถ„์„ ๋˜๋Š” ๊ฒฐ๊ณผ ๊ณต์œ ์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
save_frames bool False ๋™์˜์ƒ ์ฒ˜๋ฆฌ ์‹œ ๊ฐœ๋ณ„ ํ”„๋ ˆ์ž„์„ ์ด๋ฏธ์ง€๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. ํŠน์ • ํ”„๋ ˆ์ž„์„ ์ถ”์ถœํ•˜๊ฑฐ๋‚˜ ํ”„๋ ˆ์ž„๋ณ„๋กœ ์„ธ๋ถ€์ ์œผ๋กœ ๋ถ„์„ํ•  ๋•Œ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
save_txt bool False ํƒ์ง€ ๊ฒฐ๊ณผ๋ฅผ ๋‹ค์Œ ํ˜•์‹์— ๋”ฐ๋ผ ํ…์ŠคํŠธ ํŒŒ์ผ๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. [class] [x_center] [y_center] [width] [height] [confidence]. ๋‹ค๋ฅธ ๋ถ„์„ ๋„๊ตฌ์™€์˜ ํ†ตํ•ฉ์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
save_conf bool False ์ €์žฅ๋œ ํ…์ŠคํŠธ ํŒŒ์ผ์— ์‹ ๋ขฐ๋„ ์ ์ˆ˜๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. ํ›„์ฒ˜๋ฆฌ ๋ฐ ๋ถ„์„์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์„ธ๋ถ€ ์ •๋ณด๋ฅผ ํ–ฅ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค.
save_crop bool False ํƒ์ง€๋œ ์ด๋ฏธ์ง€๋ฅผ ์ž˜๋ผ๋‚ธ ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ ์„ธํŠธ ๋ณด๊ฐ•, ๋ถ„์„ ๋˜๋Š” ํŠน์ • ๊ฐœ์ฒด์— ๋Œ€ํ•œ ์ง‘์ค‘ ๋ฐ์ดํ„ฐ ์„ธํŠธ ์ƒ์„ฑ์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
show_labels bool True ์‹œ๊ฐ์  ์ถœ๋ ฅ์— ๊ฐ ๊ฐ์ง€ ํ•ญ๋ชฉ์— ๋Œ€ํ•œ ๋ ˆ์ด๋ธ”์„ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค. ๊ฐ์ง€๋œ ๊ฐœ์ฒด์— ๋Œ€ํ•œ ์ฆ‰๊ฐ์ ์ธ ์ดํ•ด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
show_conf bool True ๊ฐ ํƒ์ง€์— ๋Œ€ํ•œ ์‹ ๋ขฐ๋„ ์ ์ˆ˜๋ฅผ ๋ผ๋ฒจ๊ณผ ํ•จ๊ป˜ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค. ๊ฐ ํƒ์ง€์— ๋Œ€ํ•œ ๋ชจ๋ธ์˜ ํ™•์‹ค์„ฑ์— ๋Œ€ํ•œ ์ธ์‚ฌ์ดํŠธ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
show_boxes bool True ๊ฐ์ง€๋œ ๊ฐœ์ฒด ์ฃผ์œ„์— ๊ฒฝ๊ณ„ ์ƒ์ž๋ฅผ ๊ทธ๋ฆฝ๋‹ˆ๋‹ค. ์ด๋ฏธ์ง€ ๋˜๋Š” ๋น„๋””์˜ค ํ”„๋ ˆ์ž„์—์„œ ๋ฌผ์ฒด๋ฅผ ์‹œ๊ฐ์ ์œผ๋กœ ์‹๋ณ„ํ•˜๊ณ  ์œ„์น˜๋ฅผ ํŒŒ์•…ํ•˜๋Š” ๋ฐ ํ•„์ˆ˜์ ์ž…๋‹ˆ๋‹ค.
line_width None or int None ๊ฒฝ๊ณ„ ์ƒ์ž์˜ ์„  ๋„ˆ๋น„๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ None๋ฅผ ํด๋ฆญํ•˜๋ฉด ์ด๋ฏธ์ง€ ํฌ๊ธฐ์— ๋”ฐ๋ผ ์„  ๋„ˆ๋น„๊ฐ€ ์ž๋™์œผ๋กœ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค. ์„ ๋ช…๋„๋ฅผ ์œ„ํ•œ ์‹œ๊ฐ์  ์‚ฌ์šฉ์ž ์ง€์ • ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์ด๋ฏธ์ง€ ๋ฐ ๋™์˜์ƒ ํ˜•์‹

YOLOv8 ๋Š” ultralytics/data/utils .py์— ์ง€์ •๋œ ๋Œ€๋กœ ๋‹ค์–‘ํ•œ ์ด๋ฏธ์ง€ ๋ฐ ๋™์˜์ƒ ํ˜•์‹์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ์œ ํšจํ•œ ์ ‘๋ฏธ์‚ฌ ๋ฐ ์˜ˆ์ œ ์˜ˆ์ธก ๋ช…๋ น์€ ์•„๋ž˜ ํ‘œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

์ด๋ฏธ์ง€

์•„๋ž˜ ํ‘œ์—๋Š” ์œ ํšจํ•œ Ultralytics ์ด๋ฏธ์ง€ ํ˜•์‹์ด ๋‚˜์™€ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋ฏธ์ง€ ์ ‘๋ฏธ์‚ฌ ์˜ˆ์ธก ๋ช…๋ น ์˜ˆ์ œ ์ฐธ์กฐ
.bmp yolo predict source=image.bmp Microsoft BMP ํŒŒ์ผ ํ˜•์‹
.dng yolo predict source=image.dng Adobe DNG
.jpeg yolo predict source=image.jpeg JPEG
.jpg yolo predict source=image.jpg JPEG
.mpo yolo predict source=image.mpo ๋‹ค์ค‘ ๊ทธ๋ฆผ ๊ฐœ์ฒด
.png yolo predict source=image.png ํœด๋Œ€์šฉ ๋„คํŠธ์›Œํฌ ๊ทธ๋ž˜ํ”ฝ
.tif yolo predict source=image.tif ํƒœ๊ทธ ์ด๋ฏธ์ง€ ํŒŒ์ผ ํ˜•์‹
.tiff yolo predict source=image.tiff ํƒœ๊ทธ ์ด๋ฏธ์ง€ ํŒŒ์ผ ํ˜•์‹
.webp yolo predict source=image.webp WebP
.pfm yolo predict source=image.pfm ํœด๋Œ€์šฉ ํ”Œ๋กœํŠธ๋งต

๋™์˜์ƒ

์•„๋ž˜ ํ‘œ์—๋Š” ์œ ํšจํ•œ Ultralytics ๋™์˜์ƒ ํ˜•์‹์ด ๋‚˜์™€ ์žˆ์Šต๋‹ˆ๋‹ค.

๋น„๋””์˜ค ์ ‘๋ฏธ์‚ฌ ์˜ˆ์ธก ๋ช…๋ น ์˜ˆ์ œ ์ฐธ์กฐ
.asf yolo predict source=video.asf ๊ณ ๊ธ‰ ์‹œ์Šคํ…œ ํ˜•์‹
.avi yolo predict source=video.avi ์˜ค๋””์˜ค ๋น„๋””์˜ค ์ธํ„ฐ๋ฆฌ๋ธŒ
.gif yolo predict source=video.gif ๊ทธ๋ž˜ํ”ฝ ๊ตํ™˜ ํ˜•์‹
.m4v yolo predict source=video.m4v MPEG-4 ํŒŒํŠธ 14
.mkv yolo predict source=video.mkv ๋งˆํŠธ๋กœ์Šค์นด
.mov yolo predict source=video.mov QuickTime ํŒŒ์ผ ํ˜•์‹
.mp4 yolo predict source=video.mp4 MPEG-4 ํŒŒํŠธ 14 - ์œ„ํ‚ค๋ฐฑ๊ณผ
.mpeg yolo predict source=video.mpeg MPEG-1 ํŒŒํŠธ 2
.mpg yolo predict source=video.mpg MPEG-1 ํŒŒํŠธ 2
.ts yolo predict source=video.ts MPEG ์ „์†ก ์ŠคํŠธ๋ฆผ
.wmv yolo predict source=video.wmv Windows Media ๋น„๋””์˜ค
.webm yolo predict source=video.webm WebM ํ”„๋กœ์ ํŠธ

๊ฒฐ๊ณผ ์ž‘์—…

๋ชจ๋‘ Ultralytics predict() ํ˜ธ์ถœ์€ ๋‹ค์Œ ๋ชฉ๋ก์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. Results ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค:

๊ฒฐ๊ณผ

from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Run inference on an image
results = model('bus.jpg')  # list of 1 Results object
results = model(['bus.jpg', 'zidane.jpg'])  # list of 2 Results objects

Results ๊ฐ์ฒด์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์†์„ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค:

์†์„ฑ ์œ ํ˜• ์„ค๋ช…
orig_img numpy.ndarray ์›๋ณธ ์ด๋ฏธ์ง€๊ฐ€ ๋„๋นค์ง€ ๋ฐฐ์—ด๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.
orig_shape tuple (๋†’์ด, ๋„ˆ๋น„) ํ˜•์‹์˜ ์›๋ณธ ์ด๋ฏธ์ง€ ๋ชจ์–‘์ž…๋‹ˆ๋‹ค.
boxes Boxes, optional ๊ฐ์ง€ ๊ฒฝ๊ณ„ ์ƒ์ž๊ฐ€ ํฌํ•จ๋œ Boxes ๊ฐœ์ฒด์ž…๋‹ˆ๋‹ค.
masks Masks, optional ๊ฐ์ง€ ๋งˆ์Šคํฌ๊ฐ€ ํฌํ•จ๋œ ๋งˆ์Šคํฌ ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค.
probs Probs, optional ๋ถ„๋ฅ˜ ์ž‘์—…์— ๋Œ€ํ•œ ๊ฐ ํด๋ž˜์Šค์˜ ํ™•๋ฅ ์„ ํฌํ•จํ•˜๋Š” Probs ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค.
keypoints Keypoints, optional ๊ฐ ๊ฐœ์ฒด์— ๋Œ€ํ•ด ๊ฐ์ง€๋œ ํ‚คํฌ์ธํŠธ๋ฅผ ํฌํ•จํ•˜๋Š” ํ‚คํฌ์ธํŠธ ๊ฐœ์ฒด์ž…๋‹ˆ๋‹ค.
obb OBB, optional ๋ฐฉํ–ฅ์ด ์ง€์ •๋œ ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค๋ฅผ ํฌํ•จํ•˜๋Š” OBB ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค.
speed dict ์ด๋ฏธ์ง€๋‹น ๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„์˜ ์ „์ฒ˜๋ฆฌ, ์ถ”๋ก , ํ›„์ฒ˜๋ฆฌ ์†๋„ ์‚ฌ์ „์ž…๋‹ˆ๋‹ค.
names dict ํด๋ž˜์Šค ์ด๋ฆ„ ์‚ฌ์ „์ž…๋‹ˆ๋‹ค.
path str ์ด๋ฏธ์ง€ ํŒŒ์ผ์˜ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.

Results ๊ฐ์ฒด์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค:

๋ฐฉ๋ฒ• ๋ฐ˜ํ™˜ ์œ ํ˜• ์„ค๋ช…
update() None ๊ฒฐ๊ณผ ๊ฐœ์ฒด์˜ ์ƒ์ž, ๋งˆ์Šคํฌ ๋ฐ ํ”„๋กœ๋ธŒ ์†์„ฑ์„ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.
cpu() Results CPU ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋Š” ๋ชจ๋“  ํ…์„œ๊ฐ€ ํฌํ•จ๋œ ๊ฒฐ๊ณผ ๊ฐ์ฒด์˜ ๋ณต์‚ฌ๋ณธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
numpy() Results ๋ชจ๋“  ํ…์„œ๊ฐ€ ํฌํ•จ๋œ Results ๊ฐ์ฒด์˜ ๋ณต์‚ฌ๋ณธ์„ ๋„ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
cuda() Results GPU ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋Š” ๋ชจ๋“  ํ…์„œ๊ฐ€ ํฌํ•จ๋œ ๊ฒฐ๊ณผ ์˜ค๋ธŒ์ ํŠธ์˜ ์‚ฌ๋ณธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
to() Results ์ง€์ •๋œ ๋””๋ฐ”์ด์Šค ๋ฐ dtype์˜ ํ…์„œ๊ฐ€ ํฌํ•จ๋œ ๊ฒฐ๊ณผ ๊ฐ์ฒด์˜ ๋ณต์‚ฌ๋ณธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
new() Results ๋™์ผํ•œ ์ด๋ฏธ์ง€, ๊ฒฝ๋กœ, ์ด๋ฆ„์„ ๊ฐ€์ง„ ์ƒˆ ๊ฒฐ๊ณผ ๊ฐœ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
plot() numpy.ndarray ํƒ์ง€ ๊ฒฐ๊ณผ๋ฅผ ํ”Œ๋กฏํ•ฉ๋‹ˆ๋‹ค. ์ฃผ์„์ด ๋‹ฌ๋ฆฐ ์ด๋ฏธ์ง€์˜ ๋„ ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
show() None ์ฃผ์„์ด ๋‹ฌ๋ฆฐ ๊ฒฐ๊ณผ๋ฅผ ํ™”๋ฉด์— ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.
save() None ์ฃผ์„์ด ๋‹ฌ๋ฆฐ ๊ฒฐ๊ณผ๋ฅผ ํŒŒ์ผ์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
verbose() str ๊ฐ ์ž‘์—…์— ๋Œ€ํ•œ ๋กœ๊ทธ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
save_txt() None ์˜ˆ์ธก์„ txt ํŒŒ์ผ๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
save_crop() None ์ž˜๋ฆฐ ์˜ˆ์ธก์„ ๋‹ค์Œ ์œ„์น˜์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. save_dir/cls/file_name.jpg.
tojson() str ๊ฐœ์ฒด๋ฅผ JSON ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์ž์„ธํ•œ ๋‚ด์šฉ์€ Results ํด๋ž˜์Šค ๋ฌธ์„œ.

์ƒ์ž

Boxes ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค๋ฅผ ์ƒ‰์ธํ•˜๊ณ , ์กฐ์ž‘ํ•˜๊ณ , ๋‹ค๋ฅธ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ƒ์ž

from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Run inference on an image
results = model('bus.jpg')  # results list

# View results
for r in results:
    print(r.boxes)  # print the Boxes object containing the detection bounding boxes

๋‹ค์Œ์€ Boxes ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ ๋ฐ ํ”„๋กœํผํ‹ฐ์˜ ์ด๋ฆ„, ์œ ํ˜• ๋ฐ ์„ค๋ช…์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช…
cpu() ๋ฐฉ๋ฒ• ๊ฐœ์ฒด๋ฅผ CPU ๋ฉ”๋ชจ๋ฆฌ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.
numpy() ๋ฐฉ๋ฒ• ๊ฐ์ฒด๋ฅผ ๋„ ๋ฐฐ์—ด๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
cuda() ๋ฐฉ๋ฒ• ์˜ค๋ธŒ์ ํŠธ๋ฅผ CUDA ๋ฉ”๋ชจ๋ฆฌ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.
to() ๋ฐฉ๋ฒ• ๊ฐœ์ฒด๋ฅผ ์ง€์ •๋œ ์žฅ์น˜๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.
xyxy ์†์„ฑ (torch.Tensor) ์ƒ์ž๋ฅผ xyxy ํ˜•์‹์œผ๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
conf ์†์„ฑ (torch.Tensor) ์ƒ์ž์˜ ์‹ ๋ขฐ๋„ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
cls ์†์„ฑ (torch.Tensor) ์ƒ์ž์˜ ํด๋ž˜์Šค ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
id ์†์„ฑ (torch.Tensor) ์ƒ์ž์˜ ํŠธ๋ž™ ID๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค(๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ).
xywh ์†์„ฑ (torch.Tensor) ์ƒ์ž๋ฅผ xywh ํ˜•์‹์œผ๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
xyxyn ์†์„ฑ (torch.Tensor) ์›๋ณธ ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋กœ ์ •๊ทœํ™”๋œ xyxy ํ˜•์‹์˜ ์ƒ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
xywhn ์†์„ฑ (torch.Tensor) ์›๋ณธ ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋กœ ์ •๊ทœํ™”๋œ xywh ํ˜•์‹์˜ ์ƒ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์ž์„ธํ•œ ๋‚ด์šฉ์€ Boxes ํด๋ž˜์Šค ๋ฌธ์„œ.

๋งˆ์Šคํฌ

Masks ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋งˆ์Šคํฌ๋ฅผ ์ธ๋ฑ์‹ฑํ•˜๊ณ , ์กฐ์ž‘ํ•˜๊ณ , ์„ธ๊ทธ๋จผํŠธ๋กœ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋งˆ์Šคํฌ

from ultralytics import YOLO

# Load a pretrained YOLOv8n-seg Segment model
model = YOLO('yolov8n-seg.pt')

# Run inference on an image
results = model('bus.jpg')  # results list

# View results
for r in results:
    print(r.masks)  # print the Masks object containing the detected instance masks

๋‹ค์Œ์€ Masks ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ ๋ฐ ํ”„๋กœํผํ‹ฐ์˜ ์ด๋ฆ„, ์œ ํ˜• ๋ฐ ์„ค๋ช…์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช…
cpu() ๋ฐฉ๋ฒ• CPU ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋Š” tensor ๋งˆ์Šคํฌ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
numpy() ๋ฐฉ๋ฒ• tensor ๋งˆ์Šคํฌ๋ฅผ ๋„ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
cuda() ๋ฐฉ๋ฒ• GPU ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋Š” ๋งˆ์Šคํฌ tensor ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
to() ๋ฐฉ๋ฒ• ์ง€์ •๋œ ์žฅ์น˜ ๋ฐ dtype์ด ํฌํ•จ๋œ tensor ๋งˆ์Šคํฌ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
xyn ์†์„ฑ (torch.Tensor) ํ…์„œ๋กœ ํ‘œํ˜„๋œ ์ •๊ทœํ™”๋œ ์„ธ๊ทธ๋จผํŠธ์˜ ๋ชฉ๋ก์ž…๋‹ˆ๋‹ค.
xy ์†์„ฑ (torch.Tensor) ํ…์„œ๋กœ ํ‘œํ˜„๋œ ํ”ฝ์…€ ์ขŒํ‘œ์˜ ์„ธ๊ทธ๋จผํŠธ ๋ชฉ๋ก์ž…๋‹ˆ๋‹ค.

์ž์„ธํ•œ ๋‚ด์šฉ์€ Masks ํด๋ž˜์Šค ๋ฌธ์„œ.

ํ‚คํฌ์ธํŠธ

Keypoints ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ขŒํ‘œ๋ฅผ ์ƒ‰์ธ, ์กฐ์ž‘ ๋ฐ ์ •๊ทœํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ‚คํฌ์ธํŠธ

from ultralytics import YOLO

# Load a pretrained YOLOv8n-pose Pose model
model = YOLO('yolov8n-pose.pt')

# Run inference on an image
results = model('bus.jpg')  # results list

# View results
for r in results:
    print(r.keypoints)  # print the Keypoints object containing the detected keypoints

๋‹ค์Œ์€ Keypoints ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ ๋ฐ ํ”„๋กœํผํ‹ฐ์˜ ์ด๋ฆ„, ์œ ํ˜• ๋ฐ ์„ค๋ช…์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช…
cpu() ๋ฐฉ๋ฒ• CPU ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋Š” ํ‚คํฌ์ธํŠธ tensor ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
numpy() ๋ฐฉ๋ฒ• ํ‚คํฌ์ธํŠธ tensor ๋ฅผ ๋„ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
cuda() ๋ฐฉ๋ฒ• GPU ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋Š” ํ‚คํฌ์ธํŠธ tensor ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
to() ๋ฐฉ๋ฒ• ์ง€์ •๋œ ์žฅ์น˜ ๋ฐ dtype์„ ์‚ฌ์šฉํ•˜์—ฌ tensor ํ‚คํฌ์ธํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
xyn ์†์„ฑ (torch.Tensor) ํ…์„œ๋กœ ํ‘œํ˜„๋œ ์ •๊ทœํ™”๋œ ํ‚คํฌ์ธํŠธ ๋ชฉ๋ก์ž…๋‹ˆ๋‹ค.
xy ์†์„ฑ (torch.Tensor) ํ…์„œ๋กœ ํ‘œํ˜„๋˜๋Š” ํ”ฝ์…€ ์ขŒํ‘œ์˜ ํ‚คํฌ์ธํŠธ ๋ชฉ๋ก์ž…๋‹ˆ๋‹ค.
conf ์†์„ฑ (torch.Tensor) ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ ํ‚คํฌ์ธํŠธ์˜ ์‹ ๋ขฐ๋„ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๊ณ , ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์—†์Œ์ž…๋‹ˆ๋‹ค.

์ž์„ธํ•œ ๋‚ด์šฉ์€ Keypoints ํด๋ž˜์Šค ๋ฌธ์„œ.

Probs

Probs ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ธ๋ฑ์Šค, get top1 ๋ฐ top5 ์ธ๋ฑ์Šค์™€ ๋ถ„๋ฅ˜ ์ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

Probs

from ultralytics import YOLO

# Load a pretrained YOLOv8n-cls Classify model
model = YOLO('yolov8n-cls.pt')

# Run inference on an image
results = model('bus.jpg')  # results list

# View results
for r in results:
    print(r.probs)  # print the Probs object containing the detected class probabilities

๋‹ค์Œ์€ ๋ฉ”์„œ๋“œ์™€ ์†์„ฑ์„ ์š”์•ฝํ•œ ํ‘œ์ž…๋‹ˆ๋‹ค. Probs ํด๋ž˜์Šค:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช…
cpu() ๋ฐฉ๋ฒ• CPU ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋Š” probs tensor ์˜ ๋ณต์‚ฌ๋ณธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
numpy() ๋ฐฉ๋ฒ• probs tensor ์˜ ์‚ฌ๋ณธ์„ ๋„ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
cuda() ๋ฐฉ๋ฒ• GPU ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋Š” tensor ํ”„๋กœ๋ธŒ์˜ ์‚ฌ๋ณธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
to() ๋ฐฉ๋ฒ• ์ง€์ •๋œ ์žฅ์น˜ ๋ฐ dtype์ด ํฌํ•จ๋œ probs tensor ์˜ ์‚ฌ๋ณธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
top1 ์†์„ฑ (int) ์ƒ์œ„ 1๋“ฑ๊ธ‰์˜ ์ธ๋ฑ์Šค์ž…๋‹ˆ๋‹ค.
top5 ์†์„ฑ (list[int]) ์ƒ์œ„ 5๊ฐœ ํด๋ž˜์Šค์˜ ์ง€ํ‘œ์ž…๋‹ˆ๋‹ค.
top1conf ์†์„ฑ (torch.Tensor) ์ƒ์œ„ 1๋“ฑ๊ธ‰์˜ ์ž์‹ ๊ฐ.
top5conf ์†์„ฑ (torch.Tensor) ์ƒ์œ„ 5๊ฐœ ํด๋ž˜์Šค์˜ ์ž์‹ ๊ฐ.

์ž์„ธํ•œ ๋‚ด์šฉ์€ Probs ํด๋ž˜์Šค ๋ฌธ์„œ.

OBB

OBB ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐฉํ–ฅ์ด ์ง€์ •๋œ ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค๋ฅผ ์ƒ‰์ธํ•˜๊ณ , ์กฐ์ž‘ํ•˜๊ณ , ๋‹ค๋ฅธ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

OBB

from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n-obb.pt')

# Run inference on an image
results = model('bus.jpg')  # results list

# View results
for r in results:
    print(r.obb)  # print the OBB object containing the oriented detection bounding boxes

๋‹ค์Œ์€ OBB ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ ๋ฐ ํ”„๋กœํผํ‹ฐ์˜ ์ด๋ฆ„, ์œ ํ˜• ๋ฐ ์„ค๋ช…์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช…
cpu() ๋ฐฉ๋ฒ• ๊ฐœ์ฒด๋ฅผ CPU ๋ฉ”๋ชจ๋ฆฌ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.
numpy() ๋ฐฉ๋ฒ• ๊ฐ์ฒด๋ฅผ ๋„ ๋ฐฐ์—ด๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
cuda() ๋ฐฉ๋ฒ• ์˜ค๋ธŒ์ ํŠธ๋ฅผ CUDA ๋ฉ”๋ชจ๋ฆฌ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.
to() ๋ฐฉ๋ฒ• ๊ฐœ์ฒด๋ฅผ ์ง€์ •๋œ ์žฅ์น˜๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.
conf ์†์„ฑ (torch.Tensor) ์ƒ์ž์˜ ์‹ ๋ขฐ๋„ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
cls ์†์„ฑ (torch.Tensor) ์ƒ์ž์˜ ํด๋ž˜์Šค ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
id ์†์„ฑ (torch.Tensor) ์ƒ์ž์˜ ํŠธ๋ž™ ID๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค(๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ).
xyxy ์†์„ฑ (torch.Tensor) ๊ฐ€๋กœ ์ƒ์ž๋ฅผ xyxy ํ˜•์‹์œผ๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
xywhr ์†์„ฑ (torch.Tensor) ํšŒ์ „๋œ ์ƒ์ž๋ฅผ xywhr ํ˜•์‹์œผ๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
xyxyxyxy ์†์„ฑ (torch.Tensor) ํšŒ์ „๋œ ์ƒ์ž๋ฅผ xyxyxyxy ํ˜•์‹์œผ๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
xyxyxyxyn ์†์„ฑ (torch.Tensor) ํšŒ์ „๋œ ์ƒ์ž๋ฅผ ์ด๋ฏธ์ง€ ํฌ๊ธฐ์— ๋”ฐ๋ผ ์ •๊ทœํ™”๋œ xyxyxyxy ํ˜•์‹์œผ๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์ž์„ธํ•œ ๋‚ด์šฉ์€ OBB ํด๋ž˜์Šค ๋ฌธ์„œ.

๊ฒฐ๊ณผ ํ”Œ๋กœํŒ…

The plot() ๋ฉ”์„œ๋“œ์˜ Results ๊ฐœ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ์ง€๋œ ๊ฐœ์ฒด(์˜ˆ: ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค, ๋งˆ์Šคํฌ, ํ‚คํฌ์ธํŠธ, ํ™•๋ฅ )๋ฅผ ์›๋ณธ ์ด๋ฏธ์ง€์— ์˜ค๋ฒ„๋ ˆ์ดํ•˜์—ฌ ์˜ˆ์ธก์„ ์‹œ๊ฐํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ฉ”์„œ๋“œ๋Š” ์ฃผ์„์ด ๋‹ฌ๋ฆฐ ์ด๋ฏธ์ง€๋ฅผ NumPy ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•˜๋ฏ€๋กœ ์‰ฝ๊ฒŒ ํ‘œ์‹œํ•˜๊ฑฐ๋‚˜ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ”Œ๋กœํŒ…

from PIL import Image
from ultralytics import YOLO

# Load a pretrained YOLOv8n model
model = YOLO('yolov8n.pt')

# Run inference on 'bus.jpg'
results = model(['bus.jpg', 'zidane.jpg'])  # results list

# Visualize the results
for i, r in enumerate(results):
    # Plot results image
    im_bgr = r.plot()  # BGR-order numpy array
    im_rgb = Image.fromarray(im_array[..., ::-1])  # RGB-order PIL image

    # Show results to screen (in supported environments)
    r.show()

    # Save results to disk
    r.save(filename=f'results{i}.jpg')

plot() ๋ฉ”์„œ๋“œ ๋งค๊ฐœ๋ณ€์ˆ˜

The plot() ๋ฉ”์„œ๋“œ๋Š” ๋‹ค์–‘ํ•œ ์ธ์ˆ˜๋ฅผ ์ง€์›ํ•˜์—ฌ ์ถœ๋ ฅ์„ ์‚ฌ์šฉ์ž ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

์ธ์ˆ˜ ์œ ํ˜• ์„ค๋ช… ๊ธฐ๋ณธ๊ฐ’
conf bool ํƒ์ง€ ์‹ ๋ขฐ๋„ ์ ์ˆ˜๋ฅผ ํฌํ•จํ•˜์„ธ์š”. True
line_width float ๊ฒฝ๊ณ„ ์ƒ์ž์˜ ์„  ๋„ˆ๋น„์ž…๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ ์ด๋ฏธ์ง€ ํฌ๊ธฐ์— ๋”ฐ๋ผ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค. None. None
font_size float ํ…์ŠคํŠธ ๊ธ€๊ผด ํฌ๊ธฐ. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ ์ด๋ฏธ์ง€ ํฌ๊ธฐ์— ๋”ฐ๋ผ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค. None. None
font str ํ…์ŠคํŠธ ์ฃผ์„์˜ ๊ธ€๊ผด ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. 'Arial.ttf'
pil bool ์ด๋ฏธ์ง€๋ฅผ PIL ์ด๋ฏธ์ง€ ๊ฐ์ฒด๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. False
img numpy.ndarray ํ”Œ๋กœํŒ…์„ ์œ„ํ•œ ๋Œ€์ฒด ์ด๋ฏธ์ง€์ž…๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ ์›๋ณธ ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. None. None
im_gpu torch.Tensor ๋” ๋น ๋ฅธ ๋งˆ์Šคํฌ ํ”Œ๋กœํŒ…์„ ์œ„ํ•œ GPU ๊ฐ€์† ์ด๋ฏธ์ง€. ๋ชจ์–‘: (1, 3, 640, 640). None
kpt_radius int ๊ทธ๋ ค์ง„ ํ‚คํฌ์ธํŠธ์˜ ๋ฐ˜๊ฒฝ์ž…๋‹ˆ๋‹ค. 5
kpt_line bool ํ‚คํฌ์ธํŠธ๋ฅผ ์„ ์œผ๋กœ ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค. True
labels bool ์ฃผ์„์— ํด๋ž˜์Šค ๋ ˆ์ด๋ธ”์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. True
boxes bool ์ด๋ฏธ์ง€์— ๊ฒฝ๊ณ„ ์ƒ์ž๋ฅผ ์˜ค๋ฒ„๋ ˆ์ดํ•ฉ๋‹ˆ๋‹ค. True
masks bool ์ด๋ฏธ์ง€์— ๋งˆ์Šคํฌ๋ฅผ ์˜ค๋ฒ„๋ ˆ์ดํ•ฉ๋‹ˆ๋‹ค. True
probs bool ๋ถ„๋ฅ˜ ํ™•๋ฅ ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. True
show bool ๊ธฐ๋ณธ ์ด๋ฏธ์ง€ ๋ทฐ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฃผ์„์ด ๋‹ฌ๋ฆฐ ์ด๋ฏธ์ง€๋ฅผ ๋ฐ”๋กœ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค. False
save bool ์ฃผ์„์ด ๋‹ฌ๋ฆฐ ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์Œ์—์„œ ์ง€์ •ํ•œ ํŒŒ์ผ์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. filename. False
filename str ์ฃผ์„์ด ๋‹ฌ๋ฆฐ ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•  ํŒŒ์ผ์˜ ๊ฒฝ๋กœ ๋ฐ ์ด๋ฆ„(๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ) save ๋Š” True. None

์Šค๋ ˆ๋“œ ์•ˆ์ „ ์ถ”๋ก 

์—ฌ๋Ÿฌ ๊ฐœ์˜ YOLO ๋ชจ๋ธ์„ ์—ฌ๋Ÿฌ ์Šค๋ ˆ๋“œ์—์„œ ๋ณ‘๋ ฌ๋กœ ์‹คํ–‰ํ•˜๋Š” ๊ฒฝ์šฐ ์ถ”๋ก  ์ค‘ ์Šค๋ ˆ๋“œ ์•ˆ์ „์„ฑ์„ ๋ณด์žฅํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. ์Šค๋ ˆ๋“œ ์•ˆ์ „ ์ถ”๋ก ์€ ๊ฐ ์Šค๋ ˆ๋“œ์˜ ์˜ˆ์ธก์ด ๊ฒฉ๋ฆฌ๋˜์–ด ์„œ๋กœ ๊ฐ„์„ญํ•˜์ง€ ์•Š๋„๋ก ๋ณด์žฅํ•˜์—ฌ ๊ฒฝ์Ÿ ์กฐ๊ฑด์„ ํ”ผํ•˜๊ณ  ์ผ๊ด€๋˜๊ณ  ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ์ถœ๋ ฅ์„ ๋ณด์žฅํ•ฉ๋‹ˆ๋‹ค.

๋ฉ€ํ‹ฐ ์Šค๋ ˆ๋“œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ YOLO ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๊ฐ ์Šค๋ ˆ๋“œ์— ๋Œ€ํ•ด ๋ณ„๋„์˜ ๋ชจ๋ธ ๊ฐ์ฒด๋ฅผ ์ธ์Šคํ„ด์Šคํ™”ํ•˜๊ฑฐ๋‚˜ ์Šค๋ ˆ๋“œ ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ถฉ๋Œ์„ ๋ฐฉ์ง€ํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค:

์Šค๋ ˆ๋“œ ์•ˆ์ „ ์ถ”๋ก 

์Šค๋ ˆ๋“œ ์•ˆ์ „ ์ถ”๋ก ์„ ์œ„ํ•ด ๊ฐ ์Šค๋ ˆ๋“œ ๋‚ด๋ถ€์— ๋‹จ์ผ ๋ชจ๋ธ์„ ์ธ์Šคํ„ด์Šคํ™”ํ•ฉ๋‹ˆ๋‹ค:

from ultralytics import YOLO
from threading import Thread

def thread_safe_predict(image_path):
    # Instantiate a new model inside the thread
    local_model = YOLO("yolov8n.pt")
    results = local_model.predict(image_path)
    # Process results


# Starting threads that each have their own model instance
Thread(target=thread_safe_predict, args=("image1.jpg",)).start()
Thread(target=thread_safe_predict, args=("image2.jpg",)).start()

YOLO ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•œ ์Šค๋ ˆ๋“œ ์•ˆ์ „ ์ถ”๋ก ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ๊ณผ ๋‹จ๊ณ„๋ณ„ ์ง€์นจ์€ YOLO ์Šค๋ ˆ๋“œ ์•ˆ์ „ ์ถ”๋ก  ๊ฐ€์ด๋“œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”. ์ด ๊ฐ€์ด๋“œ๋Š” ์ผ๋ฐ˜์ ์ธ ํ•จ์ •์„ ํ”ผํ•˜๊ณ  ๋ฉ€ํ‹ฐ์Šค๋ ˆ๋“œ ์ถ”๋ก ์ด ์›ํ™œํ•˜๊ฒŒ ์‹คํ–‰๋˜๋„๋ก ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์ŠคํŠธ๋ฆฌ๋ฐ ์†Œ์Šค for-loop

๋‹ค์Œ์€ OpenCV๋ฅผ ์‚ฌ์šฉํ•˜๋Š” Python ์Šคํฌ๋ฆฝํŠธ์ž…๋‹ˆ๋‹ค(cv2) ๋ฐ YOLOv8 ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋น„๋””์˜ค ํ”„๋ ˆ์ž„์— ๋Œ€ํ•œ ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์ด ์Šคํฌ๋ฆฝํŠธ๋Š” ํ•„์š”ํ•œ ํŒจํ‚ค์ง€๋ฅผ ์ด๋ฏธ ์„ค์น˜ํ–ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค(opencv-python ๋ฐ ultralytics).

ํฌ-๋ฃจํ”„ ์ŠคํŠธ๋ฆฌ๋ฐ

import cv2
from ultralytics import YOLO

# Load the YOLOv8 model
model = YOLO('yolov8n.pt')

# Open the video file
video_path = "path/to/your/video/file.mp4"
cap = cv2.VideoCapture(video_path)

# Loop through the video frames
while cap.isOpened():
    # Read a frame from the video
    success, frame = cap.read()

    if success:
        # Run YOLOv8 inference on the frame
        results = model(frame)

        # Visualize the results on the frame
        annotated_frame = results[0].plot()

        # Display the annotated frame
        cv2.imshow("YOLOv8 Inference", annotated_frame)

        # Break the loop if 'q' is pressed
        if cv2.waitKey(1) & 0xFF == ord("q"):
            break
    else:
        # Break the loop if the end of the video is reached
        break

# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()

์ด ์Šคํฌ๋ฆฝํŠธ๋Š” ๋™์˜์ƒ์˜ ๊ฐ ํ”„๋ ˆ์ž„์— ๋Œ€ํ•ด ์˜ˆ์ธก์„ ์‹คํ–‰ํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ์‹œ๊ฐํ™”ํ•˜์—ฌ ์ฐฝ์— ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค. 'Q'๋ฅผ ๋ˆŒ๋Ÿฌ ๋ฃจํ”„๋ฅผ ์ข…๋ฃŒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.



์ƒ์„ฑ 2023-11-12, ์—…๋ฐ์ดํŠธ 2024-02-13
์ž‘์„ฑ์ž: glenn-jocher (15), ํ…์†Œํ„ฐํ‹€ (1), ์•„์œ ์‹œ์—‘์…€ (1), ์›ƒ๋Š”ํ (1)

๋Œ“๊ธ€