Amazon SageMaker ãšã³ããã€ã³ããžã®YOLO11 å±éã¬ã€ã
Ultralytics' YOLO11 ã®ãããªé«åºŠãª ã³ã³ãã¥ãŒã¿ããžã§ã³ã¢ãã«ãAmazon SageMaker Endpoints ã«ãããã€ããããšã§ãæ§ã ãªæ©æ¢°åŠç¿ã¢ããªã±ãŒã·ã§ã³ã®å¯èœæ§ãåºãããŸãããããã®ã¢ãã«ãå¹æçã«äœ¿çšããéµã¯ããã®ã»ããã¢ãããèšå®ãããã³ãããã€ããã»ã¹ãç解ããããšã«ãããŸããYOLO11 ãAWSã«ããå ç¢ã§ã¹ã±ãŒã©ãã«ãªæ©æ¢°åŠç¿ãµãŒãã¹ã§ããAmazon SageMakerãšã·ãŒã ã¬ã¹ã«çµ±åããããšãããã«åŒ·åã«ãªããŸãã
ãã®ã¬ã€ãã§ã¯ãAmazon SageMaker ãšã³ããã€ã³ãã«ã¢ãã«YOLO11 PyTorchã¢ãã«ã Amazon SageMaker Endpoints ã«ãããã€ããæé ãé ãè¿œã£ãŠèª¬æããŸããAWS ç°å¢ãæºåããã¢ãã«ãé©åã«æ§æããAWS CloudFormation ã AWS Cloud Development Kit (CDK) ã®ãããªããŒã«ã䜿ã£ãŠãããã€ããããã®èŠç¹ãåŠã³ãŸãã
ã¢ããŸã³ã»ã»ãŒãžã¡ãŒã«ãŒ
Amazon SageMakerã¯ãAmazon Web ServicesïŒAWSïŒãæäŸããæ©æ¢°åŠç¿ãµãŒãã¹ã§ãæ©æ¢°åŠç¿ã¢ãã«ã®æ§ç¯ããã¬ãŒãã³ã°ããããã€ã®ããã»ã¹ãç°¡çŽ åãããæ©æ¢°åŠç¿ã¯ãŒã¯ãããŒã®æ§ã ãªåŽé¢ãåŠçããããã®å¹ åºãããŒã«ãæäŸãããããã«ã¯ãã¢ãã«ããã¥ãŒãã³ã°ããããã®èªååæ©èœãã¢ãã«ã倧èŠæš¡ã«ãã¬ãŒãã³ã°ããããã®ãªãã·ã§ã³ãã¢ãã«ãæ¬çªç°å¢ã«ãããã€ããããã®ç°¡åãªæ¹æ³ãªã©ãå«ãŸããŸããSageMaker ã¯äžè¬çãªæ©æ¢°åŠç¿ãã¬ãŒã ã¯ãŒã¯ããµããŒãããŠãããå€æ§ãªãããžã§ã¯ãã«å¿ èŠãªæè»æ§ãæäŸããŸãããŸããããŒã¿ã©ããªã³ã°ãã¯ãŒã¯ãããŒç®¡çãããã©ãŒãã³ã¹åæã«ã察å¿ããŠããŸãã
Amazon SageMaker ãšã³ããã€ã³ããžã®YOLO11 ã®å±é
Amazon SageMaker ã«YOLO11 ããããã€ããããšã§ããã®ãããŒãžãç°å¢ããªã¢ã«ã¿ã€ã ã®æšè«ã«äœ¿çšãããªãŒãã¹ã±ãŒã«ã®ãããªæ©èœãå©çšããããšãã§ããŸãã以äžã® AWS ã¢ãŒããã¯ãã£ãã芧ãã ããã
ã¹ããã1ïŒAWSç°å¢ã®ã»ããã¢ãã
ãŸãã以äžã®åææ¡ä»¶ãæŽã£ãŠããããšã確èªããïŒ
-
AWSã¢ã«ãŠã³ãïŒãŸã ãæã¡ã§ãªãå Žåã¯ãAWSã¢ã«ãŠã³ãã«ãµã€ã³ã¢ããããŠãã ããã
-
èšå®ãããIAMããŒã«ïŒAmazon SageMakerãAWS CloudFormationãAmazon S3ã«å¿ èŠãªæš©éãæã€IAMããŒã«ãå¿ èŠã§ãããã®ããŒã«ã¯ããããã®ãµãŒãã¹ãžã®ã¢ã¯ã»ã¹ãèš±å¯ããããªã·ãŒãæã£ãŠããå¿ èŠããããŸãã
-
AWSCLI ïŒãŸã ã€ã³ã¹ããŒã«ãããŠããªãå Žåã¯ãAWS Command Line Interface (CLI) ãããŠã³ããŒãããŠã€ã³ã¹ããŒã«ããã¢ã«ãŠã³ãæ å ±ã䜿çšããŠèšå®ããŸããAWSCLI ã®æé ã«åŸã£ãŠã€ã³ã¹ããŒã«ããŠãã ããã
-
AWS CDK: ãŸã ã€ã³ã¹ããŒã«ãããŠããªãå Žåã¯ããããã€ã®ã¹ã¯ãªããã«äœ¿çšãã AWS Cloud Development Kit (CDK) ãã€ã³ã¹ããŒã«ããŸããAWS CDKã®ã€ã³ã¹ããŒã«æé ã«åŸã£ãŠãã ããã
-
ååãªãµãŒãã¹ã¯ã©ãŒã¿ïŒAmazon SageMakerã®2ã€ã®ãªãœãŒã¹ã«ååãªã¯ã©ãŒã¿ãããããšã確èªããŠãã ããã
ml.m5.4xlarge
ãšã³ããã€ã³ãçšãšml.m5.4xlarge
ãããŒãããã¯ã»ã€ã³ã¹ã¿ã³ã¹ã®äœ¿çšéã«å²ãåœãŠãŸããããããæäœ1ã€ã®ã¯ã©ãŒã¿å€ãå¿ èŠã§ããçŸåšã®ã¯ã©ãŒã¿ããã®èŠä»¶ãäžåã£ãŠããå Žåãããããã®ã¯ã©ãŒã¿ã®å¢å ããªã¯ãšã¹ãããããšãéèŠã§ããã¯ã©ãŒã¿ã®å¢å 㯠AWS Service Quotas ããã¥ã¡ã³ã.
ã¹ããã 2:YOLO11 SageMaker ãªããžããªã®ã¯ããŒã³
次ã®ã¹ãããã¯ãSageMaker ã§YOLO11 ããããã€ããããã®ãªãœãŒã¹ãå«ãç¹å®ã® AWS ãªããžããªãã¯ããŒã³ããããšã§ããGitHub ã§ãã¹ããããŠãããã®ãªããžããªã«ã¯ãå¿ èŠãª CDK ã¹ã¯ãªãããšèšå®ãã¡ã€ã«ãå«ãŸããŠããŸãã
- GitHub ãªããžããªãã¯ããŒã³ããŸãïŒã¿ãŒããã«ã§ä»¥äžã®ã³ãã³ããå®è¡ããhost-yolov8-on-sagemaker-endpoint ãªããžããªãã¯ããŒã³ããŸãïŒ
- ã¯ããŒã³ããããã£ã¬ã¯ããªã«ç§»åããŸãïŒãã£ã¬ã¯ããªãã¯ããŒã³ããããªããžããªã«å€æŽããŸãïŒ
ã¹ããã3ïŒCDKç°å¢ã®ã»ããã¢ãã
å¿ èŠãªã³ãŒããæã£ãã®ã§ãAWS CDKã§ãããã€ããããã®ç°å¢ãã»ããã¢ããããã
- Python ä»®æ³ç°å¢ãäœæããïŒããã«ãããPython ã®ç°å¢ãšäŸåé¢ä¿ãåé¢ããããå®è¡ããïŒ
- ä»®æ³ç°å¢ãèµ·åããŸãïŒ
- äŸåé¢ä¿ãã€ã³ã¹ããŒã«ããŸãïŒãããžã§ã¯ãã«å¿ èŠãªPython ã®äŸåé¢ä¿ãã€ã³ã¹ããŒã«ããŸãïŒ
- AWS CDK ã©ã€ãã©ãªãã¢ããã°ã¬ãŒãããŸãïŒAWS CDKã©ã€ãã©ãªã®ææ°ããŒãžã§ã³ã確èªããŠãã ããïŒ
ã¹ããã4: AWS CloudFormationã¹ã¿ãã¯ã®äœæ
- CDKã¢ããªã±ãŒã·ã§ã³ãåæããŸãïŒCDKã³ãŒãããAWS CloudFormationãã³ãã¬ãŒããçæããŸãïŒ
- CDKã¢ããªã±ãŒã·ã§ã³ãããŒãã¹ãã©ããããCDKããããã€ããããã«AWSç°å¢ãæºåããŸãïŒ
- ã¹ã¿ãã¯ããããã€ããïŒå¿ èŠãªAWSãªãœãŒã¹ãäœæããã¢ãã«ããããã€ããŸãïŒ
ã¹ããã 5:YOLO ã¢ãã«ã®å±é
å°å ¥ã®èª¬æã«å ¥ãåã«ã Ultralytics ãæäŸããYOLO11 ã¢ãã«ã®ç¯å²ãå¿ ããã§ãã¯ããŠãã ãããããã¯ãããªãã®ãããžã§ã¯ãã®èŠä»¶ã«æãé©åãªã¢ãã«ãéžæããã®ã«åœ¹ç«ã¡ãŸãã
AWS CloudFormation Stack ãäœæãããã次ã¯YOLO11 ããããã€ããã
-
ããŒãããã¯ã€ã³ã¹ã¿ã³ã¹ãéããŸãïŒAWSã³ã³ãœãŒã«ã«ã¢ã¯ã»ã¹ããAmazon SageMakerãµãŒãã¹ã«ç§»åããŸããããã·ã¥ããŒããã "Notebook Instances "ãéžæããCDKãããã€ã¹ã¯ãªããã«ãã£ãŠäœæãããããŒãããã¯ã€ã³ã¹ã¿ã³ã¹ãèŠã€ããŸããããŒãããã¯ã€ã³ã¹ã¿ã³ã¹ãéããŠJupyterç°å¢ã«ã¢ã¯ã»ã¹ããŸãã
-
inference.pyã«ã¢ã¯ã»ã¹ããŠä¿®æ£ããŸãïŒJupyter 㧠SageMaker ããŒãããã¯ã®ã€ã³ã¹ã¿ã³ã¹ãéããinference.py ãã¡ã€ã«ãæ¢ããŸããinference.pyã®output_fné¢æ°ã以äžã®ããã«ç·šéããæ§æãšã©ãŒããªãããšã確èªããŠã¹ã¯ãªããã«å€æŽãä¿åããŸãã
import json
def output_fn(prediction_output):
"""Formats model outputs as JSON string, extracting attributes like boxes, masks, keypoints."""
print("Executing output_fn from inference.py ...")
infer = {}
for result in prediction_output:
if result.boxes is not None:
infer["boxes"] = result.boxes.numpy().data.tolist()
if result.masks is not None:
infer["masks"] = result.masks.numpy().data.tolist()
if result.keypoints is not None:
infer["keypoints"] = result.keypoints.numpy().data.tolist()
if result.obb is not None:
infer["obb"] = result.obb.numpy().data.tolist()
if result.probs is not None:
infer["probs"] = result.probs.numpy().data.tolist()
return json.dumps(infer)
- 1_DeployEndpoint.ipynbã䜿çšããŠãšã³ããã€ã³ãããããã€ããïŒJupyterç°å¢ã§ãsm-notebookãã£ã¬ã¯ããªã«ãã1_DeployEndpoint.ipynbããŒãããã¯ãéããŸããããŒãããã¯ã®æ瀺ã«åŸã£ãŠã»ã«ãå®è¡ããYOLO11 ã¢ãã«ãããŠã³ããŒãããæŽæ°ãããæšè«ã³ãŒããšãšãã«ããã±ãŒãžåããAmazon S3 ãã±ããã«ã¢ããããŒãããŸãããã®ããŒãããã¯ã¯ãYOLO11 ã¢ãã«çšã® SageMaker ãšã³ããã€ã³ãã®äœæãšãããã€ãã¬ã€ãããŸãã
ã¹ããã 6: é åã®ãã¹ã
YOLO11 ã¢ãã«ããããã€ããããããã®ããã©ãŒãã³ã¹ãšæ©èœæ§ããã¹ãããããšãéèŠã§ãã
-
ãã¹ãã»ããŒãããã¯ãéãïŒåãJupyterç°å¢ã§ãsm-notebookãã£ã¬ã¯ããªã«ãã2_TestEndpoint.ipynbããŒãããã¯ãæ¢ããŠéãã
-
ãã¹ãããŒãããã¯ãå®è¡ããŸãïŒããŒãããã¯å ã®æ瀺ã«åŸã£ãŠããããã€ããã SageMaker ãšã³ããã€ã³ãããã¹ãããŸããããã«ã¯ããšã³ããã€ã³ãã«ç»åãéä¿¡ããæšè«ãå®è¡ããããšãå«ãŸããŸãããã®åŸã以äžã®ããã«åºåãããããããŠãã¢ãã«ã®ããã©ãŒãã³ã¹ãšç²ŸåºŠãå¯èŠåããŸãã
- ã¯ãªãŒã³ã¢ããã»ãªãœãŒã¹ïŒãã¹ãããŒãããã¯ã¯ããšã³ããã€ã³ããšãã¹ããããã¢ãã«ãã¯ãªãŒã³ã¢ããããããã»ã¹ãæ¡å ããŸããããã¯ãã³ã¹ããšãªãœãŒã¹ãå¹æçã«ç®¡çããããã®éèŠãªã¹ãããã§ãã
ã¹ããã7ïŒã¢ãã¿ãªã³ã°ãšç®¡ç
ãã¹ãåŸã¯ãå±éããã¢ãã«ã®ç¶ç¶çãªã¢ãã¿ãªã³ã°ãšç®¡çãäžå¯æ¬ ã§ããã
-
Amazon CloudWatch ã§ç£èŠïŒAmazon CloudWatch ã䜿çšããŠãSageMaker ãšã³ããã€ã³ãã®ããã©ãŒãã³ã¹ãšå¥å šæ§ãå®æçã«ãã§ãã¯ããŸãã
-
ãšã³ããã€ã³ãã®ç®¡çãšã³ããã€ã³ãã®ç¶ç¶çãªç®¡çã«ã¯ãSageMaker ã³ã³ãœãŒã«ã䜿çšããŸããããã«ã¯ãå¿ èŠã«å¿ããŠã¢ãã«ãã¹ã±ãŒãªã³ã°ãæŽæ°ããŸãã¯åãããã€ããããšãå«ãŸããŸãã
ãããã®ã¹ããããå®äºããããšã§ãAmazon SageMaker Endpoints äžã§YOLO11 ã¢ãã«ã®ãããã€ãšãã¹ããæåãããããšãã§ããŸãããã®ããã»ã¹ã¯ãæ©æ¢°åŠç¿ã®ãããã€ã®ããã« AWS ãµãŒãã¹ã䜿çšããå®è·µçãªçµéšã身ã«ã€ããã ãã§ãªããå°æ¥çã«ä»ã®é«åºŠãªã¢ãã«ããããã€ããããã®åºç€ãç¯ããŸãã
æŠèŠ
ãã®ã¬ã€ãã§ã¯ãAWS CloudFormation ãš AWS Cloud Development Kit (CDK) ã䜿ã£ãŠ Amazon SageMaker Endpoints ã«YOLO11 ããããã€ããæé ãé ãè¿œã£ãŠèª¬æããŸããããã®ããã»ã¹ã«ã¯ãå¿ èŠãª GitHub ãªããžããªã®ã¯ããŒã³ãCDK ç°å¢ã®ã»ããã¢ãããAWS ãµãŒãã¹ã䜿çšããã¢ãã«ã®ãããã€ãSageMaker ã§ã®ããã©ãŒãã³ã¹ã®ãã¹ããå«ãŸããŸãã
æè¡çãªè©³çŽ°ã«ã€ããŠã¯ãAWS Machine Learning Blog ã®ãã¡ãã®èšäºãåç §ããŠãã ããããŸããAmazon SageMakerã®å ¬åŒããã¥ã¡ã³ãã§ãæ§ã ãªç¹åŸŽãæ©èœã«ã€ããŠã®è©³çŽ°ã確èªããããšãã§ããŸãã
YOLO11 ã®ããŸããŸãªçµ±åã«ã€ããŠãã£ãšãç¥ãã«ãªãããã§ããïŒUltralytics çµ±åã¬ã€ãã®ããŒãžã§ãæ©æ¢°åŠç¿ãããžã§ã¯ãã匷åã§ãããã®ä»ã®ããŒã«ãæ©èœãã芧ãã ããã
ããããã質å
Amazon SageMaker ãšã³ããã€ã³ãã«Ultralytics YOLO11 ã¢ãã«ããããã€ããã«ã¯ïŒ
Amazon SageMaker Endpoints ã§Ultralytics YOLO11 ã¢ãã«ãå±éããã«ã¯ã以äžã®æé ã«åŸããŸãïŒ
- AWSç°å¢ãã»ããã¢ããããŸãïŒAWS ã¢ã«ãŠã³ããå¿ èŠãªæš©éãæ〠IAM ããŒã«ãããã³ AWSCLI ãèšå®ãããŠããããšã確èªããŸããAWS CDK ãã€ã³ã¹ããŒã«ãããŠããªãå Žåã¯ãã€ã³ã¹ããŒã«ããŸãïŒAWS CDK ã®èª¬æãåç §ïŒã
- YOLO11 SageMaker ãªããžããªã®ã¯ããŒã³:
- CDKç°å¢ã®ã»ããã¢ãã:Python ä»®æ³ç°å¢ã®äœæãã¢ã¯ãã£ããŒã·ã§ã³ãäŸåé¢ä¿ã®ã€ã³ã¹ããŒã«ãAWS CDK ã©ã€ãã©ãªã®ã¢ããã°ã¬ãŒãã
- AWS CDKã䜿ã£ããããã€:CloudFormationã¹ã¿ãã¯ãåæããŠãããã€ããç°å¢ãããŒãã¹ãã©ããããã
詳ããã¯ãããã¥ã¡ã³ãã®ã»ã¯ã·ã§ã³ãã芧ãã ããã
Amazon SageMaker ã§YOLO11 ããããã€ããããã®åææ¡ä»¶ã¯äœã§ããïŒ
Amazon SageMaker ã«YOLO11 ããããã€ããã«ã¯ã以äžã®åææ¡ä»¶ãããããšã確èªããŠãã ããïŒ
- AWSã¢ã«ãŠã³ãïŒã¢ã¯ãã£ããªAWSã¢ã«ãŠã³ãïŒãµã€ã³ã¢ããã¯ãã¡ãïŒã
- IAM ããŒã«ïŒSageMakerãCloudFormationãAmazon S3çšã®æš©éãæã€IAMããŒã«ãèšå®ã
- AWSCLI ïŒAWS Command Line Interface(AWSCLI ã€ã³ã¹ããŒã«ã¬ã€ã)ãã€ã³ã¹ããŒã«ããŠèšå®ããŸããã
- AWS CDK: AWS Cloud Development KitïŒCDKã»ããã¢ããã¬ã€ãïŒãã€ã³ã¹ããŒã«ã
- ãµãŒãã¹ã»ã¯ã©ãŒã¿:ååãªåºå Žæ
ml.m5.4xlarge
ã€ã³ã¹ã¿ã³ã¹ããšã³ããã€ã³ããšããŒãããã¯ã®äž¡æ¹ã§äœ¿çšãã (å¢æ ãèŠè«ãã).
詳现ãªã»ããã¢ããã«ã€ããŠã¯ããã®ã»ã¯ã·ã§ã³ãåç §ããŠãã ããã
ãªãAmazon SageMakerã®Ultralytics YOLO11 ã
Amazon SageMakerã§Ultralytics YOLO11 ã䜿çšãããšãããã€ãã®å©ç¹ããããŸãïŒ
- ã¹ã±ãŒã©ããªãã£ãšç®¡çïŒSageMaker ã¯ããªãŒãã¹ã±ãŒãªã³ã°ãªã©ã®æ©èœãåãã管çç°å¢ãæäŸãããªã¢ã«ã¿ã€ã æšè«ã®ããŒãºã«å¯Ÿå¿ããŸãã
- AWSãµãŒãã¹ãšã®çµ±åïŒããŒã¿ã¹ãã¬ãŒãžã®S3ãInfrastructure as Codeã®CloudFormationãã¢ãã¿ãªã³ã°ã®CloudWatchãªã©ãä»ã®AWSãµãŒãã¹ãšã·ãŒã ã¬ã¹ã«çµ±åã§ããŸãã
- ãããã€ã®å®¹æãïŒAWS CDKã¹ã¯ãªããã䜿çšããŠã»ããã¢ãããç°¡çŽ åãããããã€ããã»ã¹ãåçåã
- ããã©ãŒãã³ã¹Amazon SageMakerã®é«æ§èœã€ã³ãã©ã掻çšãã倧èŠæš¡ãªæšè«ã¿ã¹ã¯ãå¹ççã«å®è¡ã
SageMaker ã䜿çšããå©ç¹ã«ã€ããŠã¯ãå°å ¥ã»ã¯ã·ã§ã³ãåç §ããŠãã ããã
Amazon SageMakerã®YOLO11 ãæšè«ããžãã¯ãã«ã¹ã¿ãã€ãºã§ããŸããïŒ
ã¯ããAmazon SageMakerã®YOLO11 ãæšè«ããžãã¯ãã«ã¹ã¿ãã€ãºããããšãã§ããŸãïŒ
-
ä¿®æ£
inference.py
:ãæ¢ããã«ã¹ã¿ãã€ãºãããoutput_fn
é¢æ°ã®inference.py
ãã¡ã€ã«ã§åºåãã©ãŒãããã調æŽãããimport json def output_fn(prediction_output): """Formats model outputs as JSON string, extracting attributes like boxes, masks, keypoints.""" infer = {} for result in prediction_output: if result.boxes is not None: infer["boxes"] = result.boxes.numpy().data.tolist() # Add more processing logic if necessary return json.dumps(infer)
-
æŽæ°ãããã¢ãã«ã®å±é:æäŸãããŠããJupyterããŒãããã¯ã䜿ã£ãŠã¢ãã«ãåãããã€ããŠãã ãã(
1_DeployEndpoint.ipynb
)ã«å€æŽãããã
å€æŽããã¢ãã«ãå±éããããã®è©³çŽ°ãªæé ãåç §ããŠãã ããã
Amazon SageMaker ã§ãããã€ãããYOLO11 ã¢ãã«ããã¹ãããã«ã¯ã©ãããã°ããã§ããïŒ
Amazon SageMaker ã«ãããã€ãããYOLO11 ã¢ãã«ããã¹ãããïŒ
- ãã¹ãããŒããéã:ãèŠã€ããã
2_TestEndpoint.ipynb
SageMaker Jupyter ç°å¢ã®ããŒãããã¯ã - ããŒãããã¯ãå®è¡ããŸãïŒããŒãããã¯ã®æ瀺ã«åŸã£ãŠããšã³ããã€ã³ãã«ç»åãéä¿¡ããæšè«ãå®è¡ããçµæã衚瀺ããŸãã
- çµæã®å¯èŠåïŒå èµã®ããããæ©èœã䜿çšããŠãæ€åºããããªããžã§ã¯ãã®åšå²ã®ããŠã³ãã£ã³ã°ããã¯ã¹ãªã©ã®ããã©ãŒãã³ã¹ã¡ããªã¯ã¹ãèŠèŠåããŸãã
ç·åçãªãã¹ãæ¹æ³ã«ã€ããŠã¯ããã¹ãã»ã¯ã·ã§ã³ãã芧ãã ããã