YOLO11 è¿ éãªå±éã®ããã®TorchScript ãžã®ã¢ãã«ãšã¯ã¹ããŒã
çµã¿èŸŒã¿ã·ã¹ãã ããŠã§ããã©ãŠã¶ãPython ã®ãµããŒããéå®ããããã©ãããã©ãŒã ãªã©ãããŸããŸãªç°å¢ã«ã³ã³ãã¥ãŒã¿ããžã§ã³ã¢ãã«ãå±éããã«ã¯ãæè»ã§ç§»æ€æ§ã®é«ããœãªã¥ãŒã·ã§ã³ãå¿ èŠã§ããTorchScript ã¯ã移æ€æ§ãšãPython ãã¬ãŒã ã¯ãŒã¯å šäœãå©çšã§ããªãç°å¢ã§ãã¢ãã«ãå®è¡ã§ããæ©èœã«éç¹ã眮ããŠããŸãããã®ãããããŸããŸãªããã€ã¹ããã©ãããã©ãŒã ã«ã³ã³ãã¥ãŒã¿ã»ããžã§ã³æ©èœãå±éããå¿ èŠãããã·ããªãªã«æé©ã§ãã
Torchscript ã«ãšã¯ã¹ããŒãããŠã·ãªã¢ã©ã€ãº Ultralytics YOLO11ãã®ã¬ã€ãã§ã¯ã ã®ã¢ãã«ã 圢åŒã«ãšã¯ã¹ããŒãããæ¹æ³ã玹ä»ããŸãããã®ã¬ã€ãã§ã¯ãYOLO11 ã®ã¢ãã«ãTorchScript ãã©ãŒãããã«ãšã¯ã¹ããŒãããããå¹ åºãã¢ããªã±ãŒã·ã§ã³ã§äœ¿çšã§ããããã«ããæ¹æ³ã玹ä»ããŸãã
ãªãTorchScript ã
PyTorch ã®ã¯ãªãšãŒã¿ãŒã«ãã£ãŠéçºãããTorchScript ã¯ãPyTorch ã®ã¢ãã«ãããŸããŸãªãã©ãããã©ãŒã ã§æé©åããå±éããããã®åŒ·åãªããŒã«ã§ããYOLO11 ã¢ãã«ã TorchScriptã«ãšã¯ã¹ããŒãããããšã¯ãç 究ããå®äžçã®ã¢ããªã±ãŒã·ã§ã³ã«ç§»è¡ããããã«éåžžã«éèŠã§ããTorchScript PyTorch ãã¬ãŒã ã¯ãŒã¯ã®äžéšã§ããPyTorch ã¯ãPython ããµããŒãããŠããªãç°å¢ã§ã ã¢ãã«ã䜿çšã§ããããã«ããããšã§ããã®ç§»è¡ãã¹ã ãŒãºã«ããŸãã
ãã®ããã»ã¹ã«ã¯ããã¬ãŒã¹ãšã¹ã¯ãªããã£ã³ã°ãšãã2ã€ã®ææ³ãããããã¬ãŒã¹ã¯ã¢ãã«å®è¡äžã®ãªãã¬ãŒã·ã§ã³ãèšé²ããã¹ã¯ãªããã¯Python ã®ãµãã»ããã䜿ã£ãã¢ãã«ã®å®çŸ©ãå¯èœã«ããããããã®ãã¯ããã¯ã¯ãYOLO11 ã®ãããªã¢ãã«ããéåžžã®Python ç°å¢ã®å€ã§ãéæ³ã䜿ããããšãä¿èšŒããã
TorchScript ãŸããæŒç®åèåãã¡ã¢ãªäœ¿çšéã®æ¹è¯ãªã©ã®æè¡ã«ãã£ãŠã¢ãã«ãæé©åããå¹ççãªå®è¡ãä¿èšŒããããšãã§ããŸããTorchScript ã«ãšã¯ã¹ããŒãããããäžã€ã®å©ç¹ã¯ãæ§ã ãªããŒããŠã§ã¢ãã©ãããã©ãŒã ã§ã¢ãã«ã®å®è¡ãé«éåã§ããå¯èœæ§ãããããšã§ããããã¯ãC++ç°å¢ãçµã¿èŸŒã¿ã·ã¹ãã ããŸãã¯ãŠã§ããã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ã«çµ±åã§ãããPyTorch ã¢ãã«ã®ã¹ã¿ã³ãã¢ãã³ã§éç£å¯èœãªè¡šçŸãäœæããŸãã
TorchScript ã¢ãã«ã®äž»ãªç¹åŸŽ
TorchScript PyTorch ããšã³ã·ã¹ãã ã®éèŠãªéšåã§ããããã£ãŒãã©ãŒãã³ã°ã¢ãã«ã®æé©åãšå±éã®ããã®åŒ·åãªæ©èœãæäŸããŸãã
ããã§ã¯ãTorchScript ãéçºè ã«ãšã£ãŠäŸ¡å€ããããŒã«ã«ããŠããäž»ãªæ©èœã玹ä»ããïŒ
-
éçã°ã©ãå®è¡ïŒTorchScript ã¯ãã¢ãã«ã®èšç®ãéçã°ã©ãã§è¡šçŸããŠãããPyTorch ã®åçã°ã©ãå®è¡ãšã¯ç°ãªããéçã°ã©ãå®è¡ã§ã¯ãèšç®ã°ã©ãã¯å®éã®å®è¡ã®åã«äžåºŠå®çŸ©ãããã³ã³ãã€ã«ãããã
-
ã¢ãã«ã®ã·ãªã¢ã©ã€ãº:TorchScript ã§ã¯ãPyTorch ã®ã¢ãã«ããã©ãããã©ãŒã ã«äŸåããªã圢åŒã«ã·ãªã¢ã©ã€ãºããããšãã§ããŸããã·ãªã¢ã©ã€ãºãããã¢ãã«ã¯ãå ã®Python ã
-
JITã³ã³ãã€ã«:TorchScript ã¯ãPyTorch ã®ã¢ãã«ãæé©åãããäžéè¡šçŸã«å€æããããã«ããžã£ã¹ãã»ã€ã³ã»ã¿ã€ã ïŒJITïŒã³ã³ãã€ã«ã䜿çšããŸããJITã¯ã¢ãã«ã®èšç®ã°ã©ããã³ã³ãã€ã«ããã¿ãŒã²ããã»ããã€ã¹äžã§ã®å¹ççãªå®è¡ãå¯èœã«ããã
-
èšèªéã®çµ±åïŒTorchScript ã䜿ãã°ãPyTorch ã®ã¢ãã«ããC++ãJavaãJavaScript ãªã©ã®ä»ã®èšèªã«ãšã¯ã¹ããŒãããããšãã§ãããããã«ãããPyTorch ã®ã¢ãã«ããç°ãªãèšèªã§æžãããæ¢åã®ãœãããŠã§ã¢ã»ã·ã¹ãã ã«çµ±åããããšã容æã«ãªããŸãã
-
段éçãªå€æïŒTorchScript ã¯æ®µéçãªå€æã¢ãããŒããæäŸããPyTorch ã¢ãã«ã®äžéšã段éçã«TorchScript ã«å€æããããšãã§ããŸãããã®æè»æ§ã¯ãè€éãªã¢ãã«ãæ±ãå Žåããã³ãŒãã®ç¹å®ã®éšåãæé©åãããå Žåã«ç¹ã«åœ¹ç«ã¡ãŸãã
é åãªãã·ã§ã³TorchScript
YOLO11 ã¢ãã«ãTorchScript ãã©ãŒãããã«ãšã¯ã¹ããŒãããã³ãŒããèŠãåã«ãTorchScript ã¢ãã«ãéåžžã©ãã§äœ¿ãããã®ããç解ãããã
TorchScript ã¯ãæ©æ¢°åŠç¿ã¢ãã«ã®ããŸããŸãªå°å ¥ãªãã·ã§ã³ãæäŸããŠããïŒ
-
C++ APIïŒTorchScript ã®æãäžè¬çãªäœ¿çšäŸã¯ããã® C++ API ã§ããããã® API ã䜿çšãããšãæé©åãããTorchScript ã¢ãã«ã C++ ã¢ããªã±ãŒã·ã§ã³å ã§çŽæ¥ããŒãããŠå®è¡ããããšãã§ãããããã¯ãPython ãé©ããŠããªãã£ãããå©çšã§ããªãã£ããããæ¬çªç°å¢ã«æé©ã§ããC++ APIã¯ãTorchScript ã¢ãã«ã®äœãªãŒããŒããããã€å¹ççãªå®è¡ãæäŸããæœåšçãªããã©ãŒãã³ã¹ãæ倧éã«åŒãåºããŸãã
-
ã¢ãã€ã«ã»ãããã€ã¡ã³ãïŒTorchScript ã¯ãã¢ãã«ãã¢ãã€ã«ã»ããã€ã¹ã«å®¹æã«ãããã€å¯èœãªåœ¢åŒã«å€æããããã®ããŒã«ãæäŸãããPyTorch ã¢ãã€ã«ã¯ãiOS ããã³Android ã¢ããªå ã§ãããã®ã¢ãã«ãå®è¡ããããã®ã©ã³ã¿ã€ã ãæäŸãããããã«ãããäœã¬ã€ãã³ã·ãŒã®ãªãã©ã€ã³æšè«æ©èœãå®çŸãããŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ãšããŒã¿ãã©ã€ãã·ãŒãåäžããã
-
ã¯ã©ãŠããããã€ã¡ã³ã:TorchScript ã®ã¢ãã«ã¯ãTorchServeã®ãããªãœãªã¥ãŒã·ã§ã³ã䜿ã£ãŠã¯ã©ãŠãããŒã¹ã®ãµãŒããŒã«ãããã€ã§ãããTorchServeã¯ãã¢ãã«ã®ããŒãžã§ã³ç®¡çããããåŠçãæ¬çªç°å¢ã§ã®ã¹ã±ãŒã©ãã«ãªãããã€ã®ããã®ã¡ããªã¯ã¹ç£èŠãªã©ã®æ©èœãæäŸããŸããTorchScript ã䜿ã£ãã¯ã©ãŠããããã€ã¡ã³ãã«ãããAPIããã®ä»ã®ãŠã§ããµãŒãã¹çµç±ã§ã¢ãã«ã«ã¢ã¯ã»ã¹ã§ããããã«ãªããŸãã
TorchScript ãžã®ãšã¯ã¹ããŒã ïŒYOLO11 ã¢ãã«ã®å€æ
YOLO11 ã¢ãã«ãTorchScript ã«ãšã¯ã¹ããŒãããããšã§ãããŸããŸãªå Žæã§ã®äœ¿çšã容æã«ãªããããé«éãã€å¹ççã«å®è¡ã§ããããã«ãªããŸããããã¯ããã£ãŒãã©ãŒãã³ã°ã»ã¢ãã«ãå®äžçã®ã¢ããªã±ãŒã·ã§ã³ã§ããå¹æçã«äœ¿ããã人ã«ãšã£ãŠçŽ æŽãããããšã ã
ã€ã³ã¹ããŒã«
å¿ èŠãªããã±ãŒãžãã€ã³ã¹ããŒã«ããã«ã¯ã以äžãå®è¡ããïŒ
ã€ã³ã¹ããŒã«ããã»ã¹ã«é¢ãã詳现ãªèª¬æãšãã¹ããã©ã¯ãã£ã¹ã«ã€ããŠã¯ãUltralytics ã€ã³ã¹ããŒã«ã¬ã€ããã芧ãã ãããYOLO11 ã«å¿ èŠãªããã±ãŒãžãã€ã³ã¹ããŒã«ããéã«ãäœããã®åé¡ãçºçããå Žåã¯ã解決çããã³ãã«ã€ããŠãããããåé¡ã¬ã€ããåç §ããŠãã ããã
䜿çšæ¹æ³
䜿ãæ¹ã®èª¬æã«å ¥ãåã«ãUltralytics YOLO11 ã®å šã¢ãã«ããšã¯ã¹ããŒãã«å¯Ÿå¿ããŠããããšã確èªããŠãããŸããã ã
䜿çšæ¹æ³
from ultralytics import YOLO
# Load the YOLO11 model
model = YOLO("yolo11n.pt")
# Export the model to TorchScript format
model.export(format="torchscript") # creates 'yolo11n.torchscript'
# Load the exported TorchScript model
torchscript_model = YOLO("yolo11n.torchscript")
# Run inference
results = torchscript_model("https://ultralytics.com/images/bus.jpg")
ãšã¯ã¹ããŒãããã»ã¹ã®è©³çŽ°ã«ã€ããŠã¯ãUltralytics ããã¥ã¡ã³ãã®ãšã¯ã¹ããŒãã«é¢ããããŒãžãã芧ãã ããã
ãšã¯ã¹ããŒããããYOLO11 TorchScript ã¢ãã«ã®å±é
Ultralytics YOLO11 ã¢ãã«ãTorchScript ãã©ãŒãããã«ãšã¯ã¹ããŒãããããšã«æåãããããããããããã€ããããšãã§ããŸããTorchScript ã¢ãã«ãå®è¡ããããã®æåã®ã¹ããããšããŠæšå¥šãããã®ã¯ãYOLO("model.torchscript") ã¡ãœãããå©çšããããšã§ãããããããã®ä»ã®æ§ã ãªèšå®ã«ãããTorchScript ã¢ãã«ã®ãããã€ã«é¢ãã詳现ãªèª¬æã«ã€ããŠã¯ã以äžã®ãªãœãŒã¹ãã芧ãã ããïŒ
-
ã¢ãã€ã«é åãæ¢ã:ã¢ãã€ã«å±é PyTorchã¢ãã€ã«ããã¥ã¡ã³ãã¯ãã¢ãã€ã«ããã€ã¹ã«ã¢ãã«ãå±éããããã®å æ¬çãªã¬ã€ãã©ã€ã³ãæäŸããã¢ããªã±ãŒã·ã§ã³ã®å¹çæ§ãšå¿çæ§ãä¿èšŒããŸãã
-
ãã¹ã¿ãŒãµãŒããŒåŽã®å±é:ã¹ã±ãŒã©ãã«ã§å¹ççãªã¢ãã«é ä¿¡ã®ããã®ã¹ããããã€ã¹ãããã®ãã¥ãŒããªã¢ã«ãæäŸããŸãã
-
C++ã®å°å ¥:C++ ã§ã®TorchScript ã¢ãã«ã®ããŒãã«é¢ãããã¥ãŒããªã¢ã«ãã芧ãã ãããC++ ã¢ããªã±ãŒã·ã§ã³ãžã®TorchScript ã¢ãã«ã®çµ±åã容æã«ãªããããã©ãŒãã³ã¹ãšæ±çšæ§ãåäžããŸãã
æŠèŠ
ãã®ã¬ã€ãã§ã¯ãUltralytics YOLO11 ã¢ãã«ãTorchScript ãã©ãŒãããã«ãšã¯ã¹ããŒãããããã»ã¹ã«ã€ããŠèª¬æããŸããæäŸãããæ瀺ã«åŸãããšã§ãYOLO11 ã¢ãã«ã®ããã©ãŒãã³ã¹ãæé©åããããŸããŸãªãã©ãããã©ãŒã ãç°å¢ã«å±éããæè»æ§ãåŸãããšãã§ããŸãã
䜿ãæ¹ã®è©³çŽ°ã«ã€ããŠã¯ãTorchScript ã®å ¬åŒããã¥ã¡ã³ããã芧ãã ããã
ãŸãããã®ä»ã®Ultralytics YOLO11 ã®çµ±åã«ã€ããŠè©³ãããç¥ãã«ãªãããå Žåã¯ãçµ±åã¬ã€ãã®ããŒãžãã芧ãã ãããæçšãªãªãœãŒã¹ãèŠèãããããèŠã€ãããŸãã
ããããã質å
Ultralytics YOLO11 ã¢ãã«ããTorchScript ãžã®ãšã¯ã¹ããŒããšã¯ïŒ
Ultralytics YOLO11 ã¢ãã«ãTorchScript ã«ãšã¯ã¹ããŒãããããšã§ãæè»ãªã¯ãã¹ãã©ãããã©ãŒã å±éãå¯èœã«ãªããTorchScriptãŸããPyTorch ãšã³ã·ã¹ãã ã®äžéšã§ããC++ã¯ãã¢ãã«ã®ã·ãªã¢ã©ã€ãºã容æã«ããPython ã®ãµããŒãããªãç°å¢ã§ãå®è¡ã§ããããã«ããŸãããã®ãããçµã¿èŸŒã¿ã·ã¹ãã ãC++ç°å¢ãã¢ãã€ã«ã»ã¢ããªã±ãŒã·ã§ã³ãããã«ã¯ãŠã§ãã»ãã©ãŠã¶ã§ã®ã¢ãã«ã®ãããã€ã«æé©ã§ããTorchScript ã«ãšã¯ã¹ããŒãããããšã§ãå¹ççãªããã©ãŒãã³ã¹ãšãæ§ã ãªãã©ãããã©ãŒã ã«ãããYOLO11 ã¢ãã«ã®å¹ åºãé©çšãå¯èœã«ãªããŸãã
Ultralytics ã䜿ã£ãŠãYOLO11 ã®ã¢ãã«ãTorchScript ã«ãšã¯ã¹ããŒãããã«ã¯ïŒ
YOLO11 ã¢ãã«ãTorchScript ã«ãšã¯ã¹ããŒãããã«ã¯ã以äžã®ã³ãŒãäŸã䜿çšããŸãïŒ
䜿çšæ¹æ³
from ultralytics import YOLO
# Load the YOLO11 model
model = YOLO("yolo11n.pt")
# Export the model to TorchScript format
model.export(format="torchscript") # creates 'yolo11n.torchscript'
# Load the exported TorchScript model
torchscript_model = YOLO("yolo11n.torchscript")
# Run inference
results = torchscript_model("https://ultralytics.com/images/bus.jpg")
ãšã¯ã¹ããŒãåŠçã®è©³çŽ°ã«ã€ããŠã¯ãUltralytics ã®ãšã¯ã¹ããŒãã«é¢ããããã¥ã¡ã³ããåç §ããŠãã ããã
YOLO11 ã¢ãã«ã®ãããã€ã«TorchScript ã䜿ãã¹ãçç±ã¯ïŒ
YOLO11 ã¢ãã«ã®å±éã«TorchScript ã䜿çšãããšãããã€ãã®å©ç¹ãããïŒ
- 移æ€æ§ïŒãšã¯ã¹ããŒããããã¢ãã«ã¯ãC++ã¢ããªã±ãŒã·ã§ã³ãçµã¿èŸŒã¿ã·ã¹ãã ãã¢ãã€ã«æ©åšãªã©ãPython ãå¿ èŠãšããªãç°å¢ã§å®è¡ã§ããŸãã
- æé©å:TorchScript ã¯ãéçã°ã©ãå®è¡ãšJITïŒJust-In-TimeïŒã³ã³ãã€ã«ããµããŒãããŠãããã¢ãã«ã®ããã©ãŒãã³ã¹ãæé©åããããšãã§ããŸãã
- èšèªéã®çµ±å:TorchScript ã®ã¢ãã«ã¯ä»ã®ããã°ã©ãã³ã°èšèªã«çµ±åããããšãã§ããæè»æ§ãšæ¡åŒµæ§ãé«ããŸãã
- ã·ãªã¢ã©ã€ãºïŒã¢ãã«ãã·ãªã¢ã©ã€ãºããããšã§ããã©ãããã©ãŒã ã«äŸåããªãããŒããšæšè«ãå¯èœã«ãªãã
é åã«é¢ãã詳现ã«ã€ããŠã¯ãPyTorch Mobile DocumentationãTorchServe DocumentationãC++ Deployment Guideãã芧ãã ããã
YOLO11 ã®ã¢ãã«ãTorchScript ã«ãšã¯ã¹ããŒãããããã®ã€ã³ã¹ããŒã«æé ãæããŠãã ããã
YOLO11 ã¢ãã«ã®ãšã¯ã¹ããŒãã«å¿ èŠãªããã±ãŒãžãã€ã³ã¹ããŒã«ããã«ã¯ã以äžã®ã³ãã³ãã䜿çšããŸãïŒ
詳ããæé ã«ã€ããŠã¯ãUltralytics ã€ã³ã¹ããŒã«ã¬ã€ããã芧ãã ãããã€ã³ã¹ããŒã«äžã«åé¡ãçºçããå Žåã¯ããããããåé¡ãã¬ã€ããåç §ããŠãã ããã
ãšã¯ã¹ããŒãããTorchScript YOLO11 ã®ã¢ãã«ã¯ã©ã®ããã«é 眮ããã®ã§ããïŒ
YOLO11 ã¢ãã«ãTorchScript ãã©ãŒãããã«ãšã¯ã¹ããŒãããåŸãæ§ã ãªãã©ãããã©ãŒã ã«å±éããããšãã§ããŸãïŒ
- C++ APIïŒäœãªãŒããŒãããã§é«å¹çãªçç£ç°å¢ã«æé©ã
- ã¢ãã€ã«å±éïŒiOS ããã³Android ã¢ããªã±ãŒã·ã§ã³ã«ã¯PyTorch Mobileã䜿çšããã
- ã¯ã©ãŠãå±éïŒã¹ã±ãŒã©ãã«ãªãµãŒããŒãµã€ããããã€ã¡ã³ãã«TorchServeã®ãããªãµãŒãã¹ã掻çšããã
TorchScript ã®æ©èœããã«ã«æŽ»çšããããã«ããããã®ç°å¢ã§ã¢ãã«ãå±éããããã®å æ¬çãªã¬ã€ãã©ã€ã³ãæ¢ãã