انتقل إلى المحتوى

A Guide to Deploying YOLO11 on Amazon SageMaker Endpoints

Deploying advanced computer vision models like Ultralytics' YOLO11 on Amazon SageMaker Endpoints opens up a wide range of possibilities for various machine learning applications. The key to effectively using these models lies in understanding their setup, configuration, and deployment processes. YOLO11 becomes even more powerful when integrated seamlessly with Amazon SageMaker, a robust and scalable machine learning service by AWS.

This guide will take you through the process of deploying YOLO11 PyTorch models on Amazon SageMaker Endpoints step by step. You'll learn the essentials of preparing your AWS environment, configuring the model appropriately, and using tools like AWS CloudFormation and the AWS Cloud Development Kit (CDK) for deployment.

أمازون سيج ميكر

نظرة عامة على أمازون سيج ميكر

Amazon SageMaker هي خدمة تعلم الآلة من Amazon Web Services (AWS) تبسط عملية بناء نماذج التعلم الآلي وتدريبها ونشرها. يوفر مجموعة واسعة من الأدوات للتعامل مع الجوانب المختلفة لسير عمل التعلم الآلي. يتضمن ذلك ميزات تلقائية لضبط النماذج وخيارات لنماذج التدريب على نطاق واسع وطرق مباشرة لنشر النماذج في الإنتاج. يدعم SageMaker أطر عمل التعلم الآلي الشائعة ، مما يوفر المرونة اللازمة للمشاريع المتنوعة. تغطي ميزاته أيضا تسمية البيانات وإدارة سير العمل وتحليل الأداء.

Deploying YOLO11 on Amazon SageMaker Endpoints

Deploying YOLO11 on Amazon SageMaker lets you use its managed environment for real-time inference and take advantage of features like autoscaling. Take a look at the AWS architecture below.

بنية AWS

الخطوة 1: إعداد بيئة AWS الخاصة بك

أولا ، تأكد من وجود المتطلبات الأساسية التالية:

  • حساب AWS: إذا لم يكن لديك حساب بالفعل، فقم بالتسجيل للحصول على حساب AWS.

  • أدوار IAM المكونة: ستحتاج إلى دور IAM مع الأذونات اللازمة ل Amazon SageMaker وAWS CloudFormation وAmazon S3. يجب أن يكون لهذا الدور سياسات تسمح له بالوصول إلى هذه الخدمات.

  • أوس CLIإذا لم تكن مثبتة بالفعل، فقم بتنزيل واجهة سطر أوامر AWS وتثبيتها (CLI) وتكوينه مع تفاصيل حسابك. اتبع ال AWS CLI تعليمات التثبيت.

  • AWS CDK: إذا لم تكن مثبتة بالفعل، فقم بتثبيت AWS Cloud Development Kit (CDK)، والتي سيتم استخدامها لبرمجة عملية النشر. اتبع تعليمات AWS CDK للتثبيت.

  • حصة الخدمة الكافية: تأكد من أن لديك حصصا كافية لموردين منفصلين في Amazon SageMaker: واحد ل ml.m5.4xlarge لاستخدام نقطة النهاية وآخر لاستخدام نقطة النهاية ml.m5.4xlarge لاستخدام مثيل دفتر الملاحظات. كل من هذه تتطلب قيمة حصة واحدة على الأقل. إذا كانت حصصك الحالية أقل من هذا المطلب، فمن المهم طلب زيادة لكل منها. يمكنك طلب زيادة الحصة باتباع التعليمات التفصيلية في وثائق حصص خدمة AWS.

Step 2: Clone the YOLO11 SageMaker Repository

The next step is to clone the specific AWS repository that contains the resources for deploying YOLO11 on SageMaker. This repository, hosted on GitHub, includes the necessary CDK scripts and configuration files.

  • استنساخ مستودع GitHub: قم بتنفيذ الأمر التالي في جهازك الطرفي لاستنساخ المضيف-yolov8-on-sagemaker-endpoint repository:
git clone https://github.com/aws-samples/host-yolov8-on-sagemaker-endpoint.git
  • انتقل إلى الدليل المستنسخ: قم بتغيير الدليل الخاص بك إلى المستودع المستنسخ:
cd host-yolov8-on-sagemaker-endpoint/yolov8-pytorch-cdk

الخطوة 3: إعداد بيئة CDK

الآن بعد أن أصبح لديك التعليمة البرمجية اللازمة، قم بإعداد بيئتك للنشر باستخدام AWS CDK.

  • إنشاء ملف Python البيئة الافتراضية: هذا يعزل الخاص بك Python البيئة والتبعيات. ركض:
python3 -m venv .venv
  • تفعيل البيئة الافتراضية:
source .venv/bin/activate
  • تثبيت التبعيات: تثبيت المطلوب Python التبعيات للمشروع:
pip3 install -r requirements.txt
  • ترقية مكتبة AWS CDK: تأكد من أن لديك أحدث إصدار من مكتبة AWS CDK:
pip install --upgrade aws-cdk-lib

الخطوة 4: إنشاء حزمة AWS CloudFormation

  • تجميع تطبيق CDK: أنشئ قالب AWS CloudFormation من التعليمات البرمجية ل CDK الخاصة بك:
cdk synth
  • تمهيد تطبيق CDK: قم بإعداد بيئة AWS الخاصة بك لنشر CDK:
cdk bootstrap
  • نشر المكدس: سيؤدي ذلك إلى إنشاء موارد AWS الضرورية ونشر نموذجك:
cdk deploy

Step 5: Deploy the YOLO Model

Before diving into the deployment instructions, be sure to check out the range of YOLO11 models offered by Ultralytics. This will help you choose the most appropriate model for your project requirements.

After creating the AWS CloudFormation Stack, the next step is to deploy YOLO11.

  • افتح مثيل دفتر الملاحظات: انتقل إلى وحدة تحكم AWS وانتقل إلى خدمة Amazon SageMaker. حدد "مثيلات دفتر الملاحظات" من لوحة المعلومات، ثم حدد موقع مثيل دفتر الملاحظات الذي تم إنشاؤه بواسطة البرنامج النصي لنشر CDK. افتح مثيل دفتر الملاحظات للوصول إلى بيئة Jupyter.

  • الوصول إلى inference.py وتعديله: بعد فتح مثيل دفتر ملاحظات SageMaker في Jupyter، حدد موقع ملف 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."""
    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)
  • Deploy the Endpoint Using 1_DeployEndpoint.ipynb: In the Jupyter environment, open the 1_DeployEndpoint.ipynb notebook located in the sm-notebook directory. Follow the instructions in the notebook and run the cells to download the YOLO11 model, package it with the updated inference code, and upload it to an Amazon S3 bucket. The notebook will guide you through creating and deploying a SageMaker endpoint for the YOLO11 model.

الخطوة 6: اختبار النشر الخاص بك

Now that your YOLO11 model is deployed, it's important to test its performance and functionality.

  • افتح دفتر ملاحظات الاختبار: في نفس بيئة Jupyter ، حدد موقع دفتر ملاحظات 2_TestEndpoint.ipynb وافتحه ، أيضا في دليل sm-notebook.

  • Run the Test Notebook: Follow the instructions within the notebook to test the deployed SageMaker endpoint. This includes sending an image to the endpoint and running inferences. Then, you'll plot the output to visualize the model's performance and accuracy, as shown below.

Testing Results YOLO11

  • موارد التنظيف: سيرشدك دفتر ملاحظات الاختبار أيضا خلال عملية تنظيف نقطة النهاية والنموذج المستضاف. هذه خطوة مهمة لإدارة التكاليف والموارد بشكل فعال ، خاصة إذا كنت لا تخطط لاستخدام النموذج المنشور على الفور.

الخطوة 7: الرصد والإدارة

بعد الاختبار، تعد المراقبة والإدارة المستمرة للنموذج الذي تم نشره أمرا ضروريا.

  • المراقبة باستخدام Amazon CloudWatch: تحقق بانتظام من أداء وصحة نقطة نهاية SageMaker باستخدام Amazon CloudWatch.

  • إدارة نقطة النهاية: استخدم وحدة تحكم SageMaker للإدارة المستمرة لنقطة النهاية. يتضمن ذلك توسيع نطاق النموذج أو تحديثه أو إعادة نشره كما هو مطلوب.

By completing these steps, you will have successfully deployed and tested a YOLO11 model on Amazon SageMaker Endpoints. This process not only equips you with practical experience in using AWS services for machine learning deployment but also lays the foundation for deploying other advanced models in the future.

ملخص

This guide took you step by step through deploying YOLO11 on Amazon SageMaker Endpoints using AWS CloudFormation and the AWS Cloud Development Kit (CDK). The process includes cloning the necessary GitHub repository, setting up the CDK environment, deploying the model using AWS services, and testing its performance on SageMaker.

لمزيد من التفاصيل الفنية، راجع هذه المقالة على مدونة AWS لتعلم الآلة. يمكنك أيضا التحقق من وثائق Amazon SageMaker الرسمية لمزيد من الأفكار حول الميزات والوظائف المختلفة.

Are you interested in learning more about different YOLO11 integrations? Visit the Ultralytics integrations guide page to discover additional tools and capabilities that can enhance your machine-learning projects.

الأسئلة المتداولة

How do I deploy the Ultralytics YOLO11 model on Amazon SageMaker Endpoints?

To deploy the Ultralytics YOLO11 model on Amazon SageMaker Endpoints, follow these steps:

  1. قم بإعداد بيئة AWS الخاصة بك: تأكد من أن لديك حساب AWS، وأدوار IAM مع الأذونات اللازمة، وتكوين AWS CLI . قم بتثبيت AWS CDK إذا لم يكن قد تم بالفعل (راجع تعليمات AWS CDK).
  2. Clone the YOLO11 SageMaker Repository:
    git clone https://github.com/aws-samples/host-yolov8-on-sagemaker-endpoint.git
    cd host-yolov8-on-sagemaker-endpoint/yolov8-pytorch-cdk
    
  3. إعداد بيئة CDK: إنشاء بيئة افتراضية Python وتفعيلها وتثبيت التبعيات وترقية مكتبة AWS CDK.
    python3 -m venv .venv
    source .venv/bin/activate
    pip3 install -r requirements.txt
    pip install --upgrade aws-cdk-lib
    
  4. النشر باستخدام AWS CDK: تجميع مكدس CloudFormation ونشره، وتهيئة البيئة.
    cdk synth
    cdk bootstrap
    cdk deploy
    

لمزيد من التفاصيل، راجع قسم التوثيق.

What are the prerequisites for deploying YOLO11 on Amazon SageMaker?

To deploy YOLO11 on Amazon SageMaker, ensure you have the following prerequisites:

  1. حساب AWS: حساب AWS نشط(قم بالتسجيل هنا).
  2. أدوار IAM: تكوين أدوار IAM مع أذونات لـ SageMaker و CloudFormation و Amazon S3.
  3. AWS CLI: تثبيت وتهيئة واجهة سطر أوامر AWS(دليل تثبيت AWS CLI ).
  4. AWS CDK: تثبيت AWS Cloud Development Kit(دليل إعداد CDK).
  5. حصص الخدمات: حصص كافية لـ ml.m5.4xlarge مثيلات لاستخدام كل من نقطة النهاية والدفتر (طلب زيادة الحصة).

للحصول على الإعداد التفصيلي، راجع هذا القسم.

Why should I use Ultralytics YOLO11 on Amazon SageMaker?

Using Ultralytics YOLO11 on Amazon SageMaker offers several advantages:

  1. قابلية التوسع والإدارة: يوفّر SageMaker بيئة مُدارة مع ميزات مثل التوسعة التلقائية، والتي تساعد في احتياجات الاستدلال في الوقت الحقيقي.
  2. التكامل مع خدمات AWS: التكامل بسلاسة مع خدمات AWS الأخرى، مثل S3 لتخزين البيانات، و CloudFormation للبنية التحتية كرمز، و CloudWatch للمراقبة.
  3. سهولة النشر: إعداد مبسط باستخدام البرامج النصية لـ AWS CDK وعمليات نشر مبسطة.
  4. الأداء: استفد من البنية التحتية عالية الأداء في Amazon SageMaker لتشغيل مهام الاستدلال على نطاق واسع بكفاءة.

اكتشف المزيد حول مزايا استخدام SageMaker في قسم المقدمة.

Can I customize the inference logic for YOLO11 on Amazon SageMaker?

Yes, you can customize the inference logic for YOLO11 on Amazon SageMaker:

  1. حور 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)
    
  2. نشر النموذج المحدّث: تأكّد من إعادة نشر النموذج باستخدام دفاتر ملاحظات Jupyter المتوفرة (1_DeployEndpoint.ipynb) لتضمين هذه التغييرات.

راجع الخطوات التفصيلية لنشر النموذج المعدل.

How can I test the deployed YOLO11 model on Amazon SageMaker?

To test the deployed YOLO11 model on Amazon SageMaker:

  1. افتح دفتر الاختبار: حدد موقع 2_TestEndpoint.ipynb دفتر الملاحظات في بيئة SageMaker Jupyter.
  2. قم بتشغيل دفتر الملاحظات: اتبع تعليمات الدفتر لإرسال صورة إلى نقطة النهاية وإجراء الاستدلال وعرض النتائج.
  3. تصور النتائج: استخدم وظائف الرسم البياني المضمنة لتصور مقاييس الأداء، مثل المربعات المحدودة حول الكائنات المكتشفة.

للحصول على إرشادات شاملة للاختبار، تفضل بزيارة قسم الاختبار.

📅 Created 9 months ago ✏️ Updated 22 days ago

التعليقات