Ultralytics ããã¥ã¡ã³ãYOLO11 ãã¹ã©ã€ã¹æšè«ã«SAHIã䜿çšãã
Ultralytics SAHI(Slicing Aided Hyper Inference)ãšYOLO11 ã®äœ¿ãæ¹ã®ããã¥ã¡ã³ããžããããããã®å æ¬çãªã¬ã€ãã¯ãYOLO11 ãšãšãã« SAHI ãå®è£ ããããã«å¿ èŠãªãã¹ãŠã®éèŠãªç¥èãæäŸããããšãç®çãšããŠããŸããSAHIãšã¯äœãããªãã¹ã©ã€ã¹æšè«ã倧èŠæš¡ãªã¢ããªã±ãŒã·ã§ã³ã«äžå¯æ¬ ãªã®ãããããŠã©ã®ããã«ãããã®æ©èœãYOLO11 ãšçµ±åãããªããžã§ã¯ãæ€åºæ§èœãåäžããããã«ã€ããŠæ·±ãæãäžããŸãã
SAHIã®çŽ¹ä»
SAHI (Slicing Aided Hyper Inference)ã¯ã倧èŠæš¡ãã€é«è§£å床ã®ç»åã«å¯Ÿããç©äœæ€åºã¢ã«ãŽãªãºã ãæé©åããããã«èšèšãããé©æ°çãªã©ã€ãã©ãªã§ããSAHIã®ã³ã¢æ©èœã¯ãç»åã管çå¯èœãªã¹ã©ã€ã¹ã«åå²ããåã¹ã©ã€ã¹ã«å¯ŸããŠç©äœæ€åºãå®è¡ããçµæãã€ãªãåãããããšã«ãããŸããSAHIã¯ãYOLO ã·ãªãŒãºãå«ãæ§ã ãªç©äœæ€åºã¢ãã«ãšäºææ§ããããããèšç®ãªãœãŒã¹ã®æé©å©çšãä¿èšŒããªããæè»æ§ãæäŸããŸãã
èŠããã ïŒ SAHIïŒã¹ã©ã€ã·ã³ã°æ¯æŽè¶
æšè«ïŒã䜿ã£ãæšè«Ultralytics YOLO11
SAHIã®äž»ãªç¹åŸŽ
- ã·ãŒã ã¬ã¹ãªçµ±åïŒSAHIã¯ãYOLO ã¢ãã«ãšç°¡åã«çµ±åã§ããŸããã€ãŸããå€ãã®ã³ãŒããå€æŽããããšãªããã¹ã©ã€ã¹ãšæ€åºãéå§ã§ããŸãã
- ãªãœãŒã¹å¹çïŒå€§ããªç»åãå°ããªããŒãã«åå²ããããšã§ãSAHIã¯ã¡ã¢ãªäœ¿çšéãæé©åããéããããªãœãŒã¹ã®ããŒããŠã§ã¢ã§é«å質ã®æ€åºãå®è¡ã§ããŸãã
- é«ç²ŸåºŠïŒSAHIã¯ãã¹ãã£ããã³ã°åŠçäžã«éè€ããæ€åºããã¯ã¹ãããŒãžããã¹ããŒããªã¢ã«ãŽãªãºã ãæ¡çšããããšã§ãæ€åºç²ŸåºŠãç¶æããŠããŸãã
ã¹ã©ã€ã¹æšè«ãšã¯ïŒ
ã¹ã©ã€ã¹æšè«ãšã¯ã倧ããªç»åãé«è§£å床ã®ç»åãããå°ããªã»ã°ã¡ã³ãïŒã¹ã©ã€ã¹ïŒã«åå²ãããã®ã¹ã©ã€ã¹äžã§ãªããžã§ã¯ãæ€åºãè¡ããã¹ã©ã€ã¹ãåã³ã³ãã€ã«ããŠå ã®ç»åäžã®ãªããžã§ã¯ãã®äœçœ®ãåæ§ç¯ããããšã§ãããã®ãã¯ããã¯ã¯ãèšç®ãªãœãŒã¹ãéãããŠããå Žåããã¡ã¢ãªã®åé¡ã«ã€ãªãããããªéåžžã«é«è§£å床ã®ç»åãæ±ãå Žåã«éåžžã«æå¹ã§ãã
ã¹ã©ã€ã¹æšè«ã®å©ç¹
-
èšç®è² è·ã®è»œæžïŒå°ããªç»åã¹ã©ã€ã¹ã¯åŠçé床ãéããã¡ã¢ãªæ¶è²»éãå°ãªããããããŒãšã³ãã®ããŒããŠã§ã¢ã§ãã¹ã ãŒãºãªæäœãå¯èœã§ãã
-
æ€åºå質ã®ç¶æïŒåã¹ã©ã€ã¹ã¯ç¬ç«ããŠåŠçãããããã察象ç©ãæããã®ã«ååãªå€§ããã®ã¹ã©ã€ã¹ã§ããã°ãç©äœæ€åºã®å質ãäœäžããããšã¯ãªãã
-
æ¡åŒµæ§ã®åäžïŒãã®æè¡ã«ãããããŸããŸãªãµã€ãºã解å床ã®ç»åã«å¯ŸããŠã察象ç©ã®æ€åºãããç°¡åã«æ¡å€§çž®å°ã§ããããã«ãªããè¡æç»åããå»ç蚺æãŸã§ãå¹ åºãçšéã«æé©ã§ãã
YOLO11 SAHIãªã | YOLO11 SAHIãš |
---|---|
ã€ã³ã¹ããŒã«ãšæºå
ã€ã³ã¹ããŒã«
ãŸãã¯ãSAHIãšUltralytics ã®ææ°ããŒãžã§ã³ãã€ã³ã¹ããŒã«ããŠãã ããïŒ
ã¢ãžã¥ãŒã«ã®ã€ã³ããŒããšãªãœãŒã¹ã®ããŠã³ããŒã
ããã§ã¯ãå¿ èŠãªã¢ãžã¥ãŒã«ãã€ã³ããŒãããYOLO11 ã¢ãã«ãšããã€ãã®ãã¹ãç»åãããŠã³ããŒãããæ¹æ³ã説æããŸãïŒ
from sahi.utils.file import download_from_url
from sahi.utils.yolov8 import download_yolov8s_model
# Download YOLO11 model
model_path = "models/yolo11s.pt"
download_yolov8s_model(model_path)
# Download test images
download_from_url(
"https://raw.githubusercontent.com/obss/sahi/main/demo/demo_data/small-vehicles1.jpeg",
"demo_data/small-vehicles1.jpeg",
)
download_from_url(
"https://raw.githubusercontent.com/obss/sahi/main/demo/demo_data/terrain2.png",
"demo_data/terrain2.png",
)
æšæºæšè«YOLO11
ã¢ãã«ãã€ã³ã¹ã¿ã³ã¹åãã
YOLO11 ããã®ããã«ãªããžã§ã¯ãæ€åºçšã®ã¢ãã«ãã€ã³ã¹ã¿ã³ã¹åããããšãã§ããïŒ
from sahi import AutoDetectionModel
detection_model = AutoDetectionModel.from_pretrained(
model_type="yolov8",
model_path=yolov8_model_path,
confidence_threshold=0.3,
device="cpu", # or 'cuda:0'
)
æšæºçãªäºæž¬ãè¡ã
ç»åãã¹ãŸãã¯numpyç»åãçšããŠæšæºçãªæšè«ãè¡ãã
from sahi.predict import get_prediction
# With an image path
result = get_prediction("demo_data/small-vehicles1.jpeg", detection_model)
# With a numpy image
result = get_prediction(read_image("demo_data/small-vehicles1.jpeg"), detection_model)
çµæãå¯èŠåãã
äºæž¬ãããããŠã³ãã£ã³ã°ããã¯ã¹ãšãã¹ã¯ããšã¯ã¹ããŒãããŠèŠèŠåããŸãïŒ
ã¹ã©ã€ã¹æšè«YOLO11
ã¹ã©ã€ã¹å¯žæ³ãšãªãŒããŒã©ããæ¯ãæå®ããŠã¹ã©ã€ã¹æšè«ãè¡ãïŒ
from sahi.predict import get_sliced_prediction
result = get_sliced_prediction(
"demo_data/small-vehicles1.jpeg",
detection_model,
slice_height=256,
slice_width=256,
overlap_height_ratio=0.2,
overlap_width_ratio=0.2,
)
äºæž¬çµæã®åãæ±ã
SAHIãæäŸããã®ã¯ PredictionResult
ãªããžã§ã¯ãã«å€æããããšãã§ããïŒ
# Access the object prediction list
object_prediction_list = result.object_prediction_list
# Convert to COCO annotation, COCO prediction, imantics, and fiftyone formats
result.to_coco_annotations()[:3]
result.to_coco_predictions(image_id=1)[:3]
result.to_imantics_annotations()[:3]
result.to_fiftyone_detections()[:3]
ãããäºæž¬
ç»åã®ãã£ã¬ã¯ããªãäžæ¬äºæž¬ããïŒ
from sahi.predict import predict
predict(
model_type="yolov8",
model_path="path/to/yolo11n.pt",
model_device="cpu", # or 'cuda:0'
model_confidence_threshold=0.4,
source="path/to/dir",
slice_height=256,
slice_width=256,
overlap_height_ratio=0.2,
overlap_width_ratio=0.2,
)
以äžã§ããïŒããã§ãYOLO11 ãSAHIãæšæºæšè«ãšã¹ã©ã€ã¹æšè«ã®äž¡æ¹ã«äœ¿çšã§ããããã«ãªã£ãã
åŒçšãšè¬èŸ
SAHIãç 究ãŸãã¯éçºã§äœ¿çšããå Žåã¯ãSAHIã®åèè«æãåŒçšããèè ã«è¬èŸãè¿°ã¹ãŠãã ããïŒ
@article{akyon2022sahi,
title={Slicing Aided Hyper Inference and Fine-tuning for Small Object Detection},
author={Akyon, Fatih Cagatay and Altinuc, Sinan Onur and Temizel, Alptekin},
journal={2022 IEEE International Conference on Image Processing (ICIP)},
doi={10.1109/ICIP46576.2022.9897990},
pages={966-970},
year={2022}
}
ã³ã³ãã¥ãŒã¿ããžã§ã³ã³ãã¥ããã£ã®ããã«ãã®è²ŽéãªãªãœãŒã¹ãäœæããç¶æããŠããSAHIç 究ã°ã«ãŒãã«æè¬ããŸããSAHIãšãã®äœæè ã®è©³çŽ°ã«ã€ããŠã¯ãSAHI GitHubãªããžããªãã芧ãã ããã
ããããã質å
ç©äœæ€åºã«ãããã¹ã©ã€ã¹æšè«ã®ããã«ãYOLO11 ãSAHIãšçµ±åããã«ã¯ïŒ
Ultralytics YOLO11 ã SAHI (Slicing Aided Hyper Inference) ãšçµ±åããŠã¹ã©ã€ã¹æšè«ãè¡ãããšã§ãé«è§£å床ç»åã®ãªããžã§ã¯ãæ€åºã¿ã¹ã¯ãã管çå¯èœãªã¹ã©ã€ã¹ã«åå²ããããšã§æé©åããŸãããã®ã¢ãããŒãã¯ãã¡ã¢ãªäœ¿çšéãæ¹åããé«ãæ€åºç²ŸåºŠãä¿èšŒããŸãã䜿ãå§ããã«ã¯ãultralytics ãš sahi ã©ã€ãã©ãªãã€ã³ã¹ããŒã«ããå¿ èŠããããŸãïŒ
次ã«ãYOLO11 ã¢ãã«ãšãã¹ãç»åãããŠã³ããŒãããŸãïŒ
from sahi.utils.file import download_from_url
from sahi.utils.yolov8 import download_yolov8s_model
# Download YOLO11 model
model_path = "models/yolo11s.pt"
download_yolov8s_model(model_path)
# Download test images
download_from_url(
"https://raw.githubusercontent.com/obss/sahi/main/demo/demo_data/small-vehicles1.jpeg",
"demo_data/small-vehicles1.jpeg",
)
ãã詳现ãªæé ã«ã€ããŠã¯ãã¹ã©ã€ã¹æšè«ã¬ã€ããåç §ããŠãã ããã
ãªãSAHIãšYOLO11 ã倧ããªç»åã®ç©äœæ€åºã«äœ¿ãå¿ èŠãããã®ãïŒ
SAHI ãUltralytics YOLO11 ãšäœµçšããããšã§ã倧ããªç»åã®ç©äœæ€åºã«ããã€ãã®å©ç¹ãããïŒ
- èšç®è² è·ã®è»œæžïŒå°ããªã¹ã©ã€ã¹ã¯åŠçé床ãéããã¡ã¢ãªæ¶è²»éãå°ãªããããéããããªãœãŒã¹ã®ããŒããŠã§ã¢ã§é«å質ã®æ€åºãå®è¡ããããšãå¯èœã§ãã
- æ€åºç²ŸåºŠã®ç¶æïŒSAHIã¯ãã€ã³ããªãžã§ã³ããªã¢ã«ãŽãªãºã ã䜿çšããŠãéè€ããããã¯ã¹ãããŒãžããæ€åºå質ãç¶æããŸãã
- æ¡åŒµæ§ã®åäžïŒç°ãªãç»åãµã€ãºã解å床ã§ç©äœæ€åºã¿ã¹ã¯ãã¹ã±ãŒãªã³ã°ããããšã§ãSAHIã¯è¡æç»å解æãå»ç蚺æãªã©ã®ããŸããŸãªã¢ããªã±ãŒã·ã§ã³ã«æé©ã§ãã
ã¹ã©ã€ã¹æšè«ã®å©ç¹ã«ã€ããŠã¯ãããã¥ã¡ã³ããã芧ãã ããã
SAHIã§YOLO11 ãäºæž¬çµæãå¯èŠåã§ããŸããïŒ
ã¯ããYOLO11 ã SAHI ãšäžç·ã«äœ¿çšãããšãäºæž¬çµæãèŠèŠåã§ããŸããçµæããšã¯ã¹ããŒãããŠå¯èŠåããæ¹æ³ã¯ä»¥äžã®éãã§ãïŒ
from IPython.display import Image
result.export_visuals(export_dir="demo_data/")
Image("demo_data/prediction_visual.png")
ãã®ã³ãã³ãã¯ãå¯èŠåãããäºæž¬ãæå®ããããã£ã¬ã¯ããªã«ä¿åãããã®åŸãããŒãããã¯ãã¢ããªã±ãŒã·ã§ã³ã§è¡šç€ºããããã«ç»åãããŒãããããšãã§ããŸãã詳现ãªã¬ã€ãã«ã€ããŠã¯ãæšæºæšè«ã»ã¯ã·ã§ã³ããã§ãã¯ããŠãã ããã
YOLO11 ãªããžã§ã¯ãæ€åºãæ¹åããããã«ãSAHIã¯ã©ã®ãããªæ©èœãæäŸããŠããŸããïŒ
SAHI (Slicing Aided Hyper Inference) ã¯ãUltralytics YOLO11 ãç©äœæ€åºãè£å®ããããã€ãã®æ©èœãæäŸããïŒ
- ã·ãŒã ã¬ã¹ãªçµ±åïŒSAHIã¯ãYOLO ã¢ãã«ãšç°¡åã«çµ±åã§ããæå°éã®ã³ãŒã調æŽã§æžã¿ãŸãã
- ãªãœãŒã¹å¹çïŒå€§ããªç»åãå°ããªã¹ã©ã€ã¹ã«åå²ããã¡ã¢ãªäœ¿çšéãšé床ãæé©åããŸãã
- é«ç²ŸåºŠïŒã¹ãã£ããã³ã°ã®éçšã§éãªãåã£ãæ€åºããã¯ã¹ãå¹æçã«ããŒãžããããšã§ãSAHIã¯é«ãæ€åºç²ŸåºŠãç¶æããŸãã
詳ããã¯ãSAHIã®äž»ãªç¹åŸŽãã芧ãã ããã
YOLO11 ãSAHIã䜿ã£ã倧èŠæš¡ãªæšè«ãããžã§ã¯ããã©ã®ããã«æ±ãã°ããã®ãïŒ
YOLO11 ãSAHIã䜿çšããŠå€§èŠæš¡ãªæšè«ãããžã§ã¯ããåŠçããã«ã¯ã以äžã®ãã¹ããã©ã¯ãã£ã¹ã«åŸã£ãŠãã ããïŒ
- å¿ èŠãªã©ã€ãã©ãªãã€ã³ã¹ããŒã«ããïŒultralytics ãš sahi ã®ææ°çãããããšã確èªããŠãã ããã
- ã¹ã©ã€ã¹æšè«ã®èšå®ç¹å®ã®ãããžã§ã¯ãã«æé©ãªã¹ã©ã€ã¹å¯žæ³ãšãªãŒããŒã©ããæ¯çã決å®ããŸãã
- ãããäºæž¬ã®å®è¡ïŒSAHIã®æ©èœã䜿çšããŠãç»åã®ãã£ã¬ã¯ããªã«å¯ŸããŠãããäºæž¬ãå®è¡ããå¹çãåäžãããŸãã
ãããäºæž¬ã®äŸïŒ
from sahi.predict import predict
predict(
model_type="yolov8",
model_path="path/to/yolo11n.pt",
model_device="cpu", # or 'cuda:0'
model_confidence_threshold=0.4,
source="path/to/dir",
slice_height=256,
slice_width=256,
overlap_height_ratio=0.2,
overlap_width_ratio=0.2,
)
ãã詳现ãªæé ã«ã€ããŠã¯ããããäºæž¬ã®ã»ã¯ã·ã§ã³ãã芧ãã ããã