ã«ããã¢ãã«äºæž¬Ultralytics YOLO
ã¯ããã«
æ©æ¢°åŠç¿ãš ã³ã³ãã¥ãŒã¿ããžã§ã³ã®äžçã§ã¯ãèŠèŠããŒã¿ããæå³ãèŠåºãããã»ã¹ããæšè«ããŸãã¯ãäºæž¬ããšåŒã³ãŸããUltralytics YOLO11 ã¯ãå¹ åºãããŒã¿ãœãŒã¹ã«å¯Ÿããé«æ§èœã§ãªã¢ã«ã¿ã€ã ã®æšè«çšã«èª¿æŽããããpredict ã¢ãŒããšããŠç¥ããã匷åãªæ©èœãæäŸããŸãã
èŠããã ïŒ Ultralytics YOLO ã¢ãã«ããã«ã¹ã¿ã ãããžã§ã¯ãã®ã¢ãŠãããããæœåºããæ¹æ³ã
å®äžçã§ã®å¿çš
補é æ¥ | ã¹ããŒã | å®å šæ§ |
---|---|---|
è»äž¡äºååæ€åº | ãµãã«ãŒéžææ€åº | èœäžæ€ç¥ |
ãªãæšè«ã«Ultralytics YOLO ã䜿ãã®ãïŒ
ããã§ã¯ãæ§ã ãªæšè«ããŒãºã«å¯ŸããŠYOLO11 ã® predict ã¢ãŒããæ€èšãã¹ãçç±ã説æããïŒ
- æ±çšæ§ïŒç»åããããªãã©ã€ãã¹ããªãŒã ã§ãããæšè«ãå¯èœã
- ããã©ãŒãã³ã¹ 粟床ãç ç²ã«ããããšãªãããªã¢ã«ã¿ã€ã ã®é«éåŠçãå®çŸã
- 䜿ããããïŒçŽæçãªPython ããã³CLI ã€ã³ã¿ãŒãã§ãŒã¹ã«ãããè¿ éãªå±éãšãã¹ããå¯èœã
- é«ãã«ã¹ã¿ãã€ãºæ§ïŒæ§ã ãªèšå®ããã©ã¡ãŒã¿ã«ãããç¹å®ã®èŠä»¶ã«å¿ããŠã¢ãã«ã®æšè«åäœã調æŽããããšãã§ããŸãã
äºæž¬ã¢ãŒãã®äž»ãªç¹åŸŽ
YOLO11ã®äºæž¬ã¢ãŒãã¯ãå ç¢ã§å€çšéã«äœ¿ããããã«èšèšãããŠããïŒ
- è€æ°ã®ããŒã¿ãœãŒã¹ã®äºææ§ïŒããŒã¿ãåã ã®ç»åãç»åéããããªãã¡ã€ã«ããŸãã¯ãªã¢ã«ã¿ã€ã ã®ãããªã¹ããªãŒã ã®ãããã§ãã£ãŠããäºæž¬ã¢ãŒãã§ã«ããŒã§ããŸãã
- ã¹ããªãŒãã³ã°ã»ã¢ãŒãïŒ ã®ã¡ã¢ãªå¹çã«åªãããžã§ãã¬ãŒã¿ãŒãçæããã«ã¯ãã¹ããªãŒãã³ã°æ©èœã䜿ãã
Results
ãªããžã§ã¯ãã䜿çšããŸãããããæå¹ã«ããã«ã¯stream=True
ããã¬ãã£ã¯ã¿ãŒã®åŒã³åºãã¡ãœããã«è¿œå ããã - ãããåŠçïŒè€æ°ã®ç»åããããªãã¬ãŒã ãäžæ¬ããŠåŠçã§ãããããæšè«æéãããã«ççž®ãããã
- çµ±åã容æïŒæè»ãªAPIã«ãããæ¢åã®ããŒã¿ãã€ãã©ã€ã³ãä»ã®ãœãããŠã§ã¢ã³ã³ããŒãã³ããšç°¡åã«çµ±åã§ããŸãã
Ultralytics YOLO ã®Python ãªã¹ããè¿ãã Results
Python ãªããžã§ã¯ããçæããã Results
ãªããžã§ã¯ãã stream=True
ã¯æšè«äžã«ã¢ãã«ã«æž¡ãããïŒ
äºæž¬ãã
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11n.pt") # pretrained YOLO11n model
# Run batched inference on a list of images
results = model(["image1.jpg", "image2.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
obb = result.obb # Oriented boxes object for OBB outputs
result.show() # display to screen
result.save(filename="result.jpg") # save to disk
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11n.pt") # pretrained YOLO11n model
# Run batched inference on a list of images
results = model(["image1.jpg", "image2.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
obb = result.obb # Oriented boxes object for OBB outputs
result.show() # display to screen
result.save(filename="result.jpg") # save to disk
æšè«ãœãŒã¹
YOLO11 ã¯ãäžè¡šã«ç€ºãããã«ãæšè«ã®ããã«ããŸããŸãªã¿ã€ãã®å
¥åãœãŒã¹ãåŠçããããšãã§ããããœãŒã¹ã«ã¯ãéæ¢ç»åããããªã»ã¹ããªãŒã ãããŸããŸãªããŒã¿åœ¢åŒãå«ãŸããããã®è¡šã¯ãåãœãŒã¹ãåŒæ° stream=True
â
.ã¹ããªãŒãã³ã°ã¢ãŒãã¯ããã¹ãŠã®ãã¬ãŒã ãã¡ã¢ãªã«ããŒããã代ããã«çµæã®ãžã§ãã¬ãŒã¿ãŒãäœæããããããããªãã©ã€ãã¹ããªãŒã ãåŠçããã®ã«æçã§ãã
ããã
çšé stream=True
é·ãåç»ã倧ããªããŒã¿ã»ãããåŠçããéã«ãã¡ã¢ãªãå¹ççã«ç®¡çãããã〠stream=False
ãã®å Žåããã¹ãŠã®ãã¬ãŒã ãŸãã¯ããŒã¿ãã€ã³ãã®çµæãã¡ã¢ãªã«ä¿åãããããã倧ããªå
¥åã«å¯ŸããŠããã«å ç®ãããã¡ã¢ãªäžè¶³ãšã©ãŒãçºçããå¯èœæ§ããããããã«å¯Ÿã㊠stream=True
ãžã§ãã¬ãŒã¿ãŒã䜿çšããçŸåšã®ãã¬ãŒã ãŸãã¯ããŒã¿ãã€ã³ãã®çµæã®ã¿ãã¡ã¢ãªã«ä¿æããããšã§ãã¡ã¢ãªæ¶è²»ã倧å¹
ã«åæžããã¡ã¢ãªäžè¶³ã®åé¡ãé²ããŸãã
ãœãŒã¹ | äŸ | ã¿ã€ã | åè |
---|---|---|---|
ã€ã¡ãŒãž | 'image.jpg' |
str ãŸã㯠Path |
åäžã®ç»åãã¡ã€ã«ã |
URL | 'https://ultralytics.com/images/bus.jpg' |
str |
ç»åãžã®URLã |
ã¹ã¯ãªãŒã³ã·ã§ãã | 'screen' |
str |
ã¹ã¯ãªãŒã³ã·ã§ãããæ®ãã |
ãã« | Image.open('image.jpg') |
PIL.Image |
RGBãã£ã³ãã«ã®HWCãã©ãŒãããã |
ãªãŒãã³CV | cv2.imread('image.jpg') |
np.ndarray |
BGRãã£ã³ãã«ä»ãHWCãã©ãŒããã uint8 (0-255) . |
ãã³ã㌠| 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) . |
ã·ãŒãšã¹ã〠| 'sources.csv' |
str ãŸã㯠Path |
ç»åããããªããŸãã¯ãã£ã¬ã¯ããªãžã®ãã¹ãå«ãCSVãã¡ã€ã«ã |
ãã㪠| 'video.mp4' |
str ãŸã㯠Path |
MP4ãAVIãªã©ã®ãããªãã¡ã€ã«ã |
ãã£ã¬ã¯ã㪠| 'path/' |
str ãŸã㯠Path |
ç»åãŸãã¯åç»ãå«ããã£ã¬ã¯ããªãžã®ãã¹ã |
ã°ãã | 'path/*.jpg' |
str |
è€æ°ã®ãã¡ã€ã«ã«ãããããã°ããã»ãã¿ãŒã³ãè€æ°ã®ãã¡ã€ã«ã«ããããããã«ã¯ * æåãã¯ã€ã«ãã«ãŒããšããŠäœ¿çšããã |
ãŠãŒãã¥ãŒã | 'https://youtu.be/LNwODJXcvt4' |
str |
YouTubeãããªã®URLã |
ã¹ããªãŒã | 'rtsp://example.com/media.mp4' |
str |
RTSPãRTMPãTCPãªã©ã®ã¹ããªãŒãã³ã°ã»ãããã³ã«ã®URLããŸãã¯IPã¢ãã¬ã¹ã |
ãã«ãã¹ããªãŒã | 'list.streams' |
str ãŸã㯠Path |
*.streams ããã¹ããã¡ã€ã«ã§ã1è¡ã«ã€ã1ã€ã®ã¹ããªãŒã URLãã€ãŸãããããµã€ãº8ã§8ã€ã®ã¹ããªãŒã ãå®è¡ãããã |
ãŠã§ãã«ã¡ã© | 0 |
int |
æšè«ãå®è¡ããæ¥ç¶ãããã«ã¡ã©ããã€ã¹ã®ã€ã³ããã¯ã¹ã |
以äžã«ãåãœãŒã¹ã»ã¿ã€ãã䜿çšããããã®ã³ãŒãäŸã瀺ããŸãïŒ
äºæž¬ãœãŒã¹
ç»åãã¡ã€ã«ã«å¯ŸããŠæšè«ãå®è¡ããã
çŸåšã®ç»é¢ã®å 容ãã¹ã¯ãªãŒã³ã·ã§ãããšããŠæšè«ãå®è¡ããã
URLãä»ããŠãªã¢ãŒãã§ãã¹ããããŠããç»åããããªã§æšè«ãå®è¡ããŸãã
Python Imaging Library (PIL)ã§éããç»åã«å¯ŸããŠæšè«ãå®è¡ããã
OpenCVã§èªã¿èŸŒãã ç»åã«å¯ŸããŠæšè«ãå®è¡ããã
numpyã®é åãšããŠè¡šçŸãããç»åã«å¯ŸããŠæšè«ãå®è¡ããã
import numpy as np
from ultralytics import YOLO
# Load a pretrained YOLO11n model
model = YOLO("yolo11n.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
ãšããŠè¡šçŸãããç»åã«å¯ŸããŠæšè«ãå®è¡ããã PyTorchtensor.
import torch
from ultralytics import YOLO
# Load a pretrained YOLO11n model
model = YOLO("yolo11n.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ãåç»ããã£ã¬ã¯ããªã®ã³ã¬ã¯ã·ã§ã³ã«å¯ŸããŠæšè«ãå®è¡ããŸãã
ãããªãã¡ã€ã«ã§æšè«ãå®è¡ãããã䜿çšã㊠stream=True
ã䜿ãã°ãçµæãªããžã§ã¯ãã®ãžã§ãã¬ãŒã¿ãŒãäœæããŠã¡ã¢ãªäœ¿çšéãæžããããšãã§ããã
ãã£ã¬ã¯ããªå
ã®ãã¹ãŠã®ç»åãšåç»ã«å¯ŸããŠæšè«ãå®è¡ããããµããã£ã¬ã¯ããªå
ã®ç»åãåç»ããã£ããã£ããã«ã¯ãã°ãããã¿ãŒã³ã䜿ãã path/to/dir/**/*
.
ãšããã°ããè¡šçŸã«ããããããã¹ãŠã®ç»åãšåç»ã«å¯ŸããŠæšè«ãå®è¡ããã *
ã®æåãããã
from ultralytics import YOLO
# Load a pretrained YOLO11n model
model = YOLO("yolo11n.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
ãŸããResultsãªããžã§ã¯ãã®ãžã§ãã¬ãŒã¿ãŒãäœæããããšã§ãé·ãåç»ã®ã¡ã¢ãªäœ¿çšéãæžããããšãã§ããŸãã
ã¹ããªãŒã ã¢ãŒãã䜿çšããŠãRTSPãRTMPãTCPããŸãã¯IPã¢ãã¬ã¹ãããã³ã«ã䜿çšããã©ã€ããããªã¹ããªãŒã ã§æšè«ãå®è¡ãããåäžã®ã¹ããªãŒã ãæäŸãããå Žåãã¢ãã«ã¯ ããããµã€ãº è€æ°ã¹ããªãŒã ã®å Žå㯠.streams
ãããã»ãµã€ãºã¯ãæäŸãããã¹ããªãŒã ã®æ°ã«ãã£ãŠæ±ºå®ãããïŒããšãã°ã8ã¹ããªãŒã ã®å Žåã¯ãããã»ãµã€ãº8ïŒã
from ultralytics import YOLO
# Load a pretrained YOLO11n model
model = YOLO("yolo11n.pt")
# Single stream with batch-size 1 inference
source = "rtsp://example.com/media.mp4" # RTSP, RTMP, TCP, or IP streaming address
# Run inference on the source
results = model(source, stream=True) # generator of Results objects
ã·ã³ã°ã«ã¹ããªãŒã ã䜿çšããå Žåãããããµã€ãºã¯ããã©ã«ãã§1ã«èšå®ããããããªãã£ãŒãã®å¹ççãªãªã¢ã«ã¿ã€ã åŠçãå¯èœã«ãªããŸãã
è€æ°ã®ãããªã¹ããªãŒã ãåæã«åŠçããã«ã¯ .streams
ã¹ããªãŒãã³ã°ã»ãœãŒã¹ãå«ãããã¹ãã»ãã¡ã€ã«ãã¢ãã«ã¯ãããæšè«ãå®è¡ããããããµã€ãºã¯ã¹ããªãŒã æ°ã«çããããã®èšå®ã«ãããè€æ°ã®ãã£ãŒããåæã«å¹ççã«åŠçã§ããã
from ultralytics import YOLO
# Load a pretrained YOLO11n model
model = YOLO("yolo11n.pt")
# Multiple streams with batched inference (e.g., batch-size 8 for 8 streams)
source = "path/to/list.streams" # *.streams text file with one streaming address per line
# Run inference on the source
results = model(source, stream=True) # generator of Results objects
äŸ .streams
ããã¹ããã¡ã€ã«ïŒ
rtsp://example.com/media1.mp4
rtsp://example.com/media2.mp4
rtmp://example2.com/live
tcp://192.168.1.100:554
...
ãã¡ã€ã«å ã®åè¡ã¯ã¹ããªãŒãã³ã°ã»ãœãŒã¹ãè¡šããè€æ°ã®ãããªã»ã¹ããªãŒã ãäžåºŠã«ã¢ãã¿ãŒããæšè«ãå®è¡ããããšãã§ããã
æ¥ç¶ãããã«ã¡ã©ã»ããã€ã¹ã§æšè«ãå®è¡ããã«ã¯ãç¹å®ã®ã«ã¡ã©ã®ã€ã³ããã¯ã¹ã source
.
æšè«
model.predict()
ã¯ãæšè«æã«ããã©ã«ããäžæžãããããã«æž¡ãããšãã§ããè€æ°ã®åŒæ°ãåãä»ããïŒ
äŸ
æšè«åŒæ°ïŒ
è°è« | ã¿ã€ã | ããã©ã«ã | 説æ |
---|---|---|---|
source |
str |
'ultralytics/assets' |
æšè«ã®ããŒã¿ãœãŒã¹ãæå®ããŸããç»åãã¹ããããªãã¡ã€ã«ããã£ã¬ã¯ããªãURLããŸãã¯ã©ã€ããã£ãŒãã®ããã€ã¹IDãæå®ã§ããŸããå¹ åºããã©ãŒããããšãœãŒã¹ããµããŒãããŠãããããããŸããŸãªã¿ã€ãã®å ¥åã«æè»ã«å¯Ÿå¿ã§ããŸãã |
conf |
float |
0.25 |
æ€åºã®æå°ä¿¡é ŒåºŠãããå€ãèšå®ããŸãããã®éŸå€ä»¥äžã®ä¿¡é ŒåºŠã§æ€åºããããªããžã§ã¯ãã¯ç¡èŠãããŸãããã®å€ã調æŽããããšã§ã誀æ€åºãæžããããšãã§ããŸãã |
iou |
float |
0.7 |
Non-Maximum Suppression (NMS)ã®Intersection Over Union(IoU)ãããå€ãå€ãäœãã»ã©ãéè€ããããã¯ã¹ãæé€ãããããæ€åºæ°ãå°ãªããªããéè€ãæžããã®ã«äŸ¿å©ã§ãã |
imgsz |
int or tuple |
640 |
æšè«ã®ããã®ç»åãµã€ãºãå®çŸ©ãããåäžã®æŽæ°å€ 640 æ£æ¹åœ¢ã«ãªãµã€ãºããå ŽåããŸãã¯ïŒé«ããå¹
ïŒã®ã¿ãã«ã䜿çšããŸããé©åãªãµã€ãžã³ã°ã¯æ€åºãåäžããã 粟床 ãšåŠçé床ã |
half |
bool |
False |
å粟床(FP16)æšè«ãå¯èœã«ãªãããµããŒããããŠããGPUã§ã®ã¢ãã«æšè«ãã粟床ãžã®åœ±é¿ãæå°éã«æããªããé«éåããããšãã§ããŸãã |
device |
str |
None |
æšè«ãè¡ãããã€ã¹ãæå®ããïŒäŸïŒ cpu , cuda:0 ãŸã㯠0 ).CPU ãç¹å®ã®GPU ããŸãã¯ã¢ãã«å®è¡çšã®ä»ã®ã³ã³ãã¥ãŒãã»ããã€ã¹ãéžæããããšãã§ããŸãã |
batch |
int |
1 |
æšè«ã®ãããã»ãµã€ãºãæå®ããïŒãœãŒã¹ã ãã£ã¬ã¯ããªããããªãã¡ã€ã«ããŸã㯠.txt ãã¡ã€ã«).ããããµã€ãºã倧ããã»ã©ãæšè«ã«å¿
èŠãªç·æéãççž®ããé«ãã¹ã«ãŒããããæäŸã§ããã |
max_det |
int |
300 |
ç»åãããã®æ倧æ€åºæ°ã1åã®æšè«ã§ã¢ãã«ãæ€åºã§ãããªããžã§ã¯ãã®ç·æ°ãå¶éããå¯éããã·ãŒã³ã§ã®éå°ãªåºåãé²ããŸãã |
vid_stride |
int |
1 |
ãããªå ¥åã®ãã¬ãŒã ã¹ãã©ã€ããæéçãªè§£å床ãç ç²ã«ããŠåŠçãé«éåããããã«ããããªã®ãã¬ãŒã ãã¹ãããã§ããããã«ããã1ã®å€ã¯ãã¹ãŠã®ãã¬ãŒã ãåŠçãããã以äžã®å€ã¯ãã¬ãŒã ãã¹ãããããã |
stream_buffer |
bool |
False |
ãããªã¹ããªãŒã ã®åä¿¡ãã¬ãŒã ããã¥ãŒã«å
¥ãããã©ããã決å®ããããã False ãã`True'ãªããæ°ãããã¬ãŒã ã«å¯Ÿå¿ããããã«å€ããã¬ãŒã ãåé€ãã(ãªã¢ã«ã¿ã€ã ã¢ããªã±ãŒã·ã§ã³ã«æé©åãããŠãã)ããã `True' ãªããæ°ãããã¬ãŒã ããããã¡ã«ãã¥ãŒã€ã³ã°ãããã¬ãŒã ãã¹ããããããªãããã«ããŸãããæšè«ã® FPS ãã¹ããªãŒã ã® FPS ããäœãå Žåã¯é
延ãçºçããŸãã |
visualize |
bool |
False |
æšè«äžã«ã¢ãã«ã®ç¹åŸŽãå¯èŠåããã¢ãã«ãäœããèŠãŠãããã®ããç¥ãããšãã§ããŸãããããã°ãã¢ãã«ã®è§£éã«åœ¹ç«ã¡ãŸãã |
augment |
bool |
False |
äºæž¬ã«å¯Ÿãããã¹ãæéæ¡åŒµïŒTTAïŒãå¯èœã«ããæšè«é床ãç ç²ã«ããããšã§æ€åºã®ããã¹ãæ§ãåäžãããå¯èœæ§ãããã |
agnostic_nms |
bool |
False |
ç°ãªãã¯ã©ã¹ã®ãªãŒããŒã©ããããããã¯ã¹ãããŒãžãããã¯ã©ã¹ã«ãšããããªãéæ倧æå¶ïŒNMSïŒãæå¹ã«ããŸããã¯ã©ã¹ã®éè€ãäžè¬çãªãã«ãã¯ã©ã¹æ€åºã·ããªãªã§åœ¹ç«ã¡ãŸãã |
classes |
list[int] |
None |
ã¯ã©ã¹ ID ã®ã»ããã«äºæž¬ããã£ã«ã¿ãªã³ã°ããŸããæå®ãããã¯ã©ã¹ã«å±ããæ€åºã®ã¿ãè¿ãããŸããè€æ°ã¯ã©ã¹ã®æ€åºã¿ã¹ã¯ã§ãé¢é£ãããªããžã§ã¯ãã«çŠç¹ãåœãŠãã®ã«äŸ¿å©ã§ãã |
retina_masks |
bool |
False |
é«è§£å床ã®ã»ã°ã¡ã³ããŒã·ã§ã³ãã¹ã¯ãè¿ããŸããè¿ããããã¹ã¯ (masks.data )ãæå¹ãªããå
ã®ç»åãµã€ãºãšäžèŽãããç¡å¹ã«ãããšãæšè«æã«äœ¿ãããç»åãµã€ãºã«ãªããŸãã |
embed |
list[int] |
None |
ç¹åŸŽãã¯ãã«ãŸãã¯åã蟌ã¿ãæœåºããã¬ã€ã€ãæå®ããŸããã¯ã©ã¹ã¿ãªã³ã°ãé¡äŒŒæ€çŽ¢ã®ãããªäžæµã®ã¿ã¹ã¯ã«äŸ¿å©ã§ãã |
project |
str |
None |
以äžã®å Žåãäºæž¬åºåãä¿åããããããžã§ã¯ãã»ãã£ã¬ã¯ããªã®ååã save ãæå¹ã«ãªã£ãŠããã |
name |
str |
None |
äºæž¬ã©ã³ã®ååããããžã§ã¯ãã»ãã©ã«ãå
ã«ãµãã»ãã£ã¬ã¯ããªãäœæããããã«äœ¿çšãããŸãã save ãæå¹ã«ãªã£ãŠããã |
å¯èŠåã®åŒæ°ïŒ
è°è« | ã¿ã€ã | ããã©ã«ã | 説æ |
---|---|---|---|
show |
bool |
False |
ãã True 泚éä»ãã®ç»åããããªããŠã£ã³ããŠã«è¡šç€ºããŸããéçºäžããã¹ãäžã®å³æã®èŠèŠçãã£ãŒãããã¯ã«äŸ¿å©ã§ãã |
save |
bool |
False ãŸã㯠True |
泚éä»ãã®ç»åãåç»ããã¡ã€ã«ã«ä¿åã§ããŸããææžåããããªãåæãçµæã®å ±æã«äŸ¿å©ã§ããããã©ã«ãã¯ãCLI ã®å Žå㯠TrueãPython ã®å Žå㯠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 ãŸã㯠int |
None |
ããŠã³ãã£ã³ã°ããã¯ã¹ã®ç·å¹
ãæå®ããŸãããã None ç·å¹
ã¯ç»åãµã€ãºã«å¿ããŠèªåçã«èª¿æŽãããŸããèŠèŠçã«ããããããã«ã¹ã¿ãã€ãºã§ããŸãã |
ç»åãšãããªã®ãã©ãŒããã
YOLO11 ultralytics/data/utils.py ã§æå®ãããŠããããã«ãæ§ã ãªç»åããããªãã©ãŒãããããµããŒãããŠããŸããæå¹ãªæ¥å°ŸèŸãšäºæž¬ã³ãã³ãäŸã«ã€ããŠã¯ä»¥äžã®è¡šãåç §ããŠãã ããã
ç»å
以äžã®è¡šã¯ãæå¹ãªUltralytics ç»åãã©ãŒãããã瀺ããŠããŸãã
泚
HEICç»åã¯æšè«ã®ã¿ã«ãµããŒãããããã¬ãŒãã³ã°ã«ã¯äœ¿çšã§ããŸããã
ç»åã®æ¥å°ŸèŸ | äºæž¬ã³ãã³ãã®äŸ | åè |
---|---|---|
.bmp |
yolo predict source=image.bmp |
Microsoft BMPãã¡ã€ã«åœ¢åŒ |
.dng |
yolo predict source=image.dng |
ã¢ããDNG |
.jpeg |
yolo predict source=image.jpeg |
ãžã§ã€ãã° |
.jpg |
yolo predict source=image.jpg |
ãžã§ã€ãã° |
.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 |
ãŠã§ãã㌠|
.pfm |
yolo predict source=image.pfm |
ããŒã¿ãã«ã»ãããŒãããã |
.HEIC |
yolo predict source=image.HEIC |
é«å¹çç»åãã©ãŒããã |
ãããª
以äžã®è¡šã«ã¯ãæå¹ãª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 Part 14 - Wikipedia |
.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 |
ãŠã£ã³ããŠãºã»ã¡ãã£ã¢ã»ãã㪠|
.webm |
yolo predict source=video.webm |
WebMãããžã§ã¯ã |
çµæãåºã
ãã¹ãŠUltralytics predict()
ã®ãªã¹ããè¿ãã Results
ãªããžã§ã¯ããããïŒ
çµæ
Results
ãªããžã§ã¯ãã¯ä»¥äžã®å±æ§ãæã€ïŒ
å±æ§ | ã¿ã€ã | 説æ |
---|---|---|
orig_img |
numpy.ndarray |
numpy é åãšããŠã®å ç»åã |
orig_shape |
tuple |
å ç»åã®åœ¢ç¶ã (height, width) ãã©ãŒãããã§è¡šãããã®ã |
boxes |
Boxes, optional |
æ€åºããŠã³ãã£ã³ã°ããã¯ã¹ãå«ãBoxesãªããžã§ã¯ãã |
masks |
Masks, optional |
æ€åºãã¹ã¯ãå«ãMasksãªããžã§ã¯ãã |
probs |
Probs, optional |
åé¡ã¿ã¹ã¯ã®åã¯ã©ã¹ã®ç¢ºçãå«ã Probs ãªããžã§ã¯ãã |
keypoints |
Keypoints, optional |
åãªããžã§ã¯ãã®æ€åºãããããŒãã€ã³ããå«ãããŒãã€ã³ããªããžã§ã¯ãã |
obb |
OBB, optional |
æåããŠã³ãã£ã³ã°ããã¯ã¹ãå«ã OBB ãªããžã§ã¯ãã |
speed |
dict |
ååŠçãæšè«ãããã³åŸåŠçã®é床ãç»åããšã«ããªç§åäœã§è¡šããèŸæžã |
names |
dict |
ã¯ã©ã¹åã®èŸæžã |
path |
str |
ç»åãã¡ã€ã«ã®ãã¹ã |
Results
ãªããžã§ã¯ãã«ã¯ä»¥äžã®ã¡ãœãããããïŒ
æ¹æ³ | ãªã¿ãŒã³ã»ã¿ã€ã | 説æ |
---|---|---|
update() |
None |
çµæãªããžã§ã¯ãã®ããã¯ã¹ããã¹ã¯ãprobså±æ§ãæŽæ°ããã |
cpu() |
Results |
CPU ããã¹ãŠã®ãã³ãœã«ãå«ãResultsãªããžã§ã¯ãã®ã³ããŒãè¿ãã |
numpy() |
Results |
ãã¹ãŠã®ãã³ãœã«ãnumpyé åãšããŠResultsãªããžã§ã¯ãã®ã³ããŒãè¿ãã |
cuda() |
Results |
GPU ããã¹ãŠã®ãã³ãœã«ãå«ãResultsãªããžã§ã¯ãã®ã³ããŒãè¿ãã |
to() |
Results |
æå®ãããããã€ã¹ãšdtypeã®ãã³ãœã«ãæã€Resultsãªããžã§ã¯ãã®ã³ããŒãè¿ãã |
new() |
Results |
åãç»åããã¹ãååãæã€æ°ããResultsãªããžã§ã¯ããè¿ãã |
plot() |
numpy.ndarray |
æ€åºçµæãããããããã泚éä»ãç»åã®numpyé åãè¿ããŸãã |
show() |
None |
泚éä»ãã®çµæãç»é¢ã«è¡šç€ºããã |
save() |
None |
泚éä»ãçµæããã¡ã€ã«ã«ä¿å |
verbose() |
str |
åã¿ã¹ã¯ã®ãã°æååãè¿ãã |
save_txt() |
None |
äºæž¬å€ãtxtãã¡ã€ã«ã«ä¿åããã |
save_crop() |
None |
ããªãã³ã°ããäºæž¬å€ãä¿åãã save_dir/cls/file_name.jpg . |
tojson() |
str |
ãªããžã§ã¯ããJSON圢åŒã«å€æããã |
詳现㯠Results
ã¯ã©ã¹ææž.
ããã¯ã¹
Boxes
ãªããžã§ã¯ãã¯ãããŠã³ãã£ã³ã°ã»ããã¯ã¹ã®ã€ã³ããã¯ã¹ä»ããæäœãç°ãªããã©ãŒããããžã®å€æã«äœ¿çšã§ããã
ããã¯ã¹
以äžã¯ãã®è¡šã§ããã Boxes
ã¯ã©ã¹ã®ã¡ãœãããšããããã£ã®ååãåã説æïŒ
å称 | ã¿ã€ã | 説æ |
---|---|---|
cpu() |
æ¹æ³ | ãªããžã§ã¯ããCPU ã¡ã¢ãªã«ç§»åããã |
numpy() |
æ¹æ³ | ãªããžã§ã¯ãã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
ãªããžã§ã¯ãã䜿çšããŠããã¹ã¯ã®ã€ã³ããã¯ã¹ä»ããæäœãã»ã°ã¡ã³ããžã®å€æãè¡ãããšãã§ããŸãã
ãã¹ã¯
以äžã¯ãã®è¡šã§ããã Masks
ã¯ã©ã¹ã®ã¡ãœãããšããããã£ã®ååãåã説æïŒ
å称 | ã¿ã€ã | 説æ |
---|---|---|
cpu() |
æ¹æ³ | CPU ã¡ã¢ãªäžã®ãã¹ã¯tensor ãè¿ãã |
numpy() |
æ¹æ³ | ãã¹ã¯tensor ã numpy ã®é åãšããŠè¿ããŸãã |
cuda() |
æ¹æ³ | GPU ã¡ã¢ãªäžã®ãã¹ã¯tensor ãè¿ãã |
to() |
æ¹æ³ | æå®ãããããã€ã¹ãš dtype ãæã€ãã¹ã¯tensor ãè¿ãã |
xyn |
ããããã£torch.Tensor ) |
æ£èŠåãããã»ã°ã¡ã³ãã®ãªã¹ãã |
xy |
ããããã£torch.Tensor ) |
ãã³ãœã«ãšããŠè¡šçŸããããã¯ã»ã«åº§æšã®ã»ã°ã¡ã³ãã®ãªã¹ãã |
詳现㯠Masks
ã¯ã©ã¹ææž.
ããŒãã€ã³ã
Keypoints
ãªããžã§ã¯ãã¯ã座æšã®ã€ã³ããã¯ã¹ä»ããæäœãæ£èŠåã«äœ¿çšã§ããã
ããŒãã€ã³ã
以äžã¯ãã®è¡šã§ããã Keypoints
ã¯ã©ã¹ã®ã¡ãœãããšããããã£ã®ååãåã説æïŒ
å称 | ã¿ã€ã | 説æ |
---|---|---|
cpu() |
æ¹æ³ | CPU ã¡ã¢ãªäžã®tensor ããŒãã€ã³ããè¿ãã |
numpy() |
æ¹æ³ | ããŒãã€ã³ãtensor ã numpy ã®é åãšããŠè¿ãã |
cuda() |
æ¹æ³ | GPU ã¡ã¢ãªäžã®tensor ããŒãã€ã³ããè¿ãã |
to() |
æ¹æ³ | æå®ãããããã€ã¹ãš dtype ãæã€ããŒãã€ã³ãtensor ãè¿ãã |
xyn |
ããããã£torch.Tensor ) |
ãã³ãœã«ãšããŠè¡šçŸãããæ£èŠåããŒãã€ã³ãã®ãªã¹ãã |
xy |
ããããã£torch.Tensor ) |
ãã³ãœã«ãšããŠè¡šçŸããããã¯ã»ã«åº§æšã®ããŒãã€ã³ãã®ãªã¹ãã |
conf |
ããããã£torch.Tensor ) |
ããŒãã€ã³ãã®ä¿¡é Œå€ãããã°ãããè¿ãããªããã° Noneã |
詳现㯠Keypoints
ã¯ã©ã¹ææž.
åé¡
Probs
ãªããžã§ã¯ãã䜿çšããããšãã§ããŸãã top1
ãã㊠top5
åé¡ã®ææšãšåŸç¹ã
åé¡
ã®ã¡ãœãããšããããã£ãè¡šã«ãŸãšããã Probs
ã¯ã©ã¹ã§ããïŒ
å称 | ã¿ã€ã | 説æ |
---|---|---|
cpu() |
æ¹æ³ | CPU ã¡ã¢ãªäžã® probstensor ã®ã³ããŒãè¿ãã |
numpy() |
æ¹æ³ | probstensor ã®ã³ããŒã numpy é åãšããŠè¿ãã |
cuda() |
æ¹æ³ | GPU ã¡ã¢ãªäžã® probstensor ã®ã³ããŒãè¿ãã |
to() |
æ¹æ³ | æå®ãããããã€ã¹ãš dtype ãæ〠probstensor ã®ã³ããŒãè¿ãã |
top1 |
ããããã£int ) |
ããã1ã¯ã©ã¹ã®ã€ã³ããã¯ã¹ã |
top5 |
ããããã£list[int] ) |
äžäœ5ã¯ã©ã¹ã®ææšã |
top1conf |
ããããã£torch.Tensor ) |
ããã1ã¯ã©ã¹ã®èªä¿¡ã |
top5conf |
ããããã£torch.Tensor ) |
ããã5ã¯ã©ã¹ã®ã³ã³ãã£ãã³ã¹ |
詳现㯠Probs
ã¯ã©ã¹ææž.
OBB
OBB
ãªããžã§ã¯ãã䜿çšããŠãã€ã³ããã¯ã¹ãäœæããããããŠã³ãã£ã³ã°ããã¯ã¹ãæäœããããç°ãªããã©ãŒãããã«å€æãããããããšãã§ããã
OBB
以äžã¯ãã®è¡šã§ããã OBB
ã¯ã©ã¹ã®ã¡ãœãããšããããã£ã®ååãåã説æïŒ
å称 | ã¿ã€ã | 説æ |
---|---|---|
cpu() |
æ¹æ³ | ãªããžã§ã¯ããCPU ã¡ã¢ãªã«ç§»åããã |
numpy() |
æ¹æ³ | ãªããžã§ã¯ãã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 ) |
å転ããããã¯ã¹ãxyxyxy圢åŒã§è¿ãã |
xyxyxyxyn |
ããããã£torch.Tensor ) |
ç»åãµã€ãºã§æ£èŠåãã xyxyxy 圢åŒã®å転ããã¯ã¹ãè¿ãã |
詳现㯠OBB
ã¯ã©ã¹ææž.
çµæã®ãããã
ã«ã€ã㊠plot()
ã¡ãœãã Results
ãªããžã§ã¯ãã¯ãæ€åºããããªããžã§ã¯ãïŒããŠã³ãã£ã³ã°ããã¯ã¹ããã¹ã¯ãããŒãã€ã³ãã確çãªã©ïŒãå
ã®ç»åã«éããããšã§ãäºæž¬ã®èŠèŠåã容æã«ããŸãããã®ã¡ãœããã¯ã泚éä»ãç»åãNumPyã®é
åãšããŠè¿ãã®ã§ã衚瀺ãä¿åãç°¡åã«ã§ããŸãã
ãããã
from PIL import Image
from ultralytics import YOLO
# Load a pretrained YOLO11n model
model = YOLO("yolo11n.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_bgr[..., ::-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()
ã¡ãœããã»ãã©ã¡ãŒã¿
ã«ã€ã㊠plot()
ã¡ãœããã¯ãåºåãã«ã¹ã¿ãã€ãºããããã®ããŸããŸãªåŒæ°ããµããŒãããŠããïŒ
è°è« | ã¿ã€ã | 説æ | ããã©ã«ã |
---|---|---|---|
conf |
bool |
æ€åºä¿¡é ŒåºŠã¹ã³ã¢ãå«ããã | True |
line_width |
float |
ããŠã³ãã£ã³ã°ããã¯ã¹ã®ç·å¹
ã以äžã®å Žåãç»åãµã€ãºã«åãããŠæ¡å€§çž®å°ããŸãã None . |
None |
font_size |
float |
ããã¹ãã®ãã©ã³ããµã€ãºããã None . |
None |
font |
str |
ããã¹ã泚éã®ãã©ã³ãåã | 'Arial.ttf' |
pil |
bool |
ç»åãPIL Imageãªããžã§ã¯ããšããŠè¿ãã | 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 |
color_mode |
str |
ã€ã³ã¹ã¿ã³ã¹ãããã¯ã©ã¹ããªã©ãã«ã©ãŒã¢ãŒããæå®ããã | 'class' |
ã¹ã¬ããã»ãŒãæšè«
æšè«äžã«ã¹ã¬ããã»ãŒãã確ä¿ããããšã¯ãè€æ°ã®YOLO ã¢ãã«ãç°ãªãã¹ã¬ããã§äžŠè¡ããŠå®è¡ããå Žåã«éåžžã«éèŠã§ããã¹ã¬ããã»ãŒãæšè«ã¯ãåã¹ã¬ããã®äºæž¬ãåé¢ãããäºãã«å¹²æžããªãããšãä¿èšŒãã競åç¶æ ãåé¿ããäžè²«æ§ã®ããä¿¡é Œæ§ã®é«ãåºåãä¿èšŒããŸãã
ãã«ãã¹ã¬ããã»ã¢ããªã±ãŒã·ã§ã³ã§YOLO ã¢ãã«ã䜿çšããå Žåã競åãé²ãããã«ãã¹ã¬ããããšã«å¥ã ã®ã¢ãã«ã»ãªããžã§ã¯ããã€ã³ã¹ã¿ã³ã¹åããããã¹ã¬ããããŒã«ã«ã»ã¹ãã¬ãŒãžãæ¡çšããããšãéèŠã§ãïŒ
ã¹ã¬ããã»ãŒãæšè«
ã¹ã¬ããã»ãŒããªæšè«ã®ããã«ãåã¹ã¬ããå ã§åäžã®ã¢ãã«ãã€ã³ã¹ã¿ã³ã¹åããïŒ
from threading import Thread
from ultralytics import YOLO
def thread_safe_predict(model, image_path):
"""Performs thread-safe prediction on an image using a locally instantiated YOLO model."""
model = YOLO(model)
results = model.predict(image_path)
# Process results
# Starting threads that each have their own model instance
Thread(target=thread_safe_predict, args=("yolo11n.pt", "image1.jpg")).start()
Thread(target=thread_safe_predict, args=("yolo11n.pt", "image2.jpg")).start()
YOLO ã¢ãã«ã«ããã¹ã¬ããã»ãŒãæšè«ã®è©³çŽ°ãšã¹ããããã€ã¹ãããã®æé ã«ã€ããŠã¯ãYOLO ã¹ã¬ããã»ãŒãæšè«ã¬ã€ããåç §ããŠãã ããããã®ã¬ã€ãã§ã¯ãããããèœãšãç©Žãåé¿ãããã«ãã¹ã¬ããæšè«ãã¹ã ãŒãºã«å®è¡ããããã«å¿ èŠãªæ å ±ãæäŸããŸãã
ã¹ããªãŒãã³ã°ã»ãœãŒã¹ for
-ã«ãŒã
以äžã¯OpenCVã䜿ã£ãPython ã¹ã¯ãªããã§ãããcv2
)ãšYOLO ããããªãã¬ãŒã ã«å¯ŸããŠæšè«ãå®è¡ããããã®ã¹ã¯ãªããã¯ãå¿
èŠãªããã±ãŒãž (opencv-python
ãã㊠ultralytics
).
ã¹ããªãŒãã³ã°ã»ãã©ãŒã»ã«ãŒã
import cv2
from ultralytics import YOLO
# Load the YOLO model
model = YOLO("yolo11n.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 YOLO inference on the frame
results = model(frame)
# Visualize the results on the frame
annotated_frame = results[0].plot()
# Display the annotated frame
cv2.imshow("YOLO 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'ãæŒãããšã§çµäºã§ããã
ããããã質å
Ultralytics YOLO ããªã¢ã«ã¿ã€ã æšè«ã®ããã®äºæž¬ã¢ãŒããšã¯ïŒ
Ultralytics YOLO ã¯ããªã¢ã«ã¿ã€ã ã®ç©äœæ€åºãã»ã°ã¡ã³ããŒã·ã§ã³ãåé¡ã®ããã®æå 端ã¢ãã«ã§ããäºæž¬ã¢ãŒãã§ã¯ãç»åããããªãã©ã€ãã¹ããªãŒã ãªã©æ§ã ãªããŒã¿ãœãŒã¹ã«å¯ŸããŠé«éãªæšè«ãè¡ãããšãã§ããŸããæ§èœãšæ±çšæ§ãè¿œæ±ããèšèšã«ããããããåŠçã¢ãŒããšã¹ããªãŒãã³ã°ã»ã¢ãŒããæäŸããŸããæ©èœã®è©³çŽ°ã«ã€ããŠã¯ãUltralytics YOLO predict modeãã芧ãã ããã
Ultralytics YOLO ã䜿ã£ãŠãç°ãªãããŒã¿ãœãŒã¹ã«å¯ŸããŠæšè«ãå®è¡ããã«ã¯ã©ãããã°ããã§ããïŒ
Ultralytics YOLO ã¯ãåã
ã®ç»åãåç»ããã£ã¬ã¯ããªãURLãã¹ããªãŒã ãªã©ãããŸããŸãªããŒã¿ãœãŒã¹ãåŠçã§ããŸããããŒã¿ãœãŒã¹ã¯ model.predict()
ãåŒã³åºããäŸãã° 'image.jpg'
ããŒã«ã«ã»ã€ã¡ãŒãžãŸã㯠'https://ultralytics.com/images/bus.jpg'
ãURLã«äœ¿çšãããæ§ã
㪠æšè«ãœãŒã¹ ãåç
§ããŠãã ããã
YOLO æšè«ã®é床ãšã¡ã¢ãªäœ¿çšéãæé©åããã«ã¯ïŒ
æšè«é床ãæé©åããã¡ã¢ãªãå¹ççã«ç®¡çããã«ã¯ãã¹ããªãŒãã³ã°ã»ã¢ãŒãã䜿çšããããšãã§ããŸãã stream=True
ãäºæž¬ã¡ãœããã®åŒã³åºãã¡ãœããã«è¿œå ãããã¹ããªãŒãã³ã°ã»ã¢ãŒãã¯ãã¡ã¢ãªå¹çã®ãã Results
ãªããžã§ã¯ããããŒããããé·ãåç»ã倧ããªããŒã¿ã»ããã®åŠçã«ã¯ãã¹ããªãŒãã³ã°ã¢ãŒããç¹ã«äŸ¿å©ã§ãã詳现ã¯ãã¡ã ã¹ããªãŒãã³ã°ã¢ãŒã.
Ultralytics YOLO ã¯ã©ã®ãããªæšè«ãæ¯æããŠããã®ãïŒ
ã«ã€ã㊠model.predict()
YOLO ã¡ãœããã¯ã次ã®ãããªããŸããŸãªåŒæ°ããµããŒãããŠããã conf
, iou
, imgsz
, device
ãªã©ããããŸãããããã®åŒæ°ã«ãããä¿¡é Œãããå€ãç»åãµã€ãºãèšç®ã«äœ¿çšããããã€ã¹ãªã©ã®ãã©ã¡ãŒã¿ãèšå®ããæšè«ããã»ã¹ãã«ã¹ã¿ãã€ãºããããšãã§ããŸãããããã®åŒæ°ã®è©³çŽ°ãªèª¬æ㯠æšè«åŒæ° ã»ã¯ã·ã§ã³ãåç
§ããããã
YOLO ã®äºæž¬çµæãèŠèŠåããŠä¿åããã«ã¯ã©ãããã°ããã§ããïŒ
YOLO ãæšè«ãå®è¡ããã Results
ãªããžã§ã¯ãã«ã¯ã泚éä»ãç»åã衚瀺ãããä¿åãããããããã®ã¡ãœãããå«ãŸããŠããŸãã以äžã®ãããªã¡ãœããã䜿ããŸãã result.show()
ãã㊠result.save(filename="result.jpg")
ã䜿çšããŠçµæãèŠèŠåããä¿åããŸãããããã®ã¡ãœããã®å
æ¬çãªãªã¹ãã«ã€ããŠã¯ çµæãšã®åãçµã¿ ã»ã¯ã·ã§ã³ãåç
§ããããã