ابدأ

عزّز مجموعة بياناتك لتدريب YOLO26 باستخدام Albumentations

عند إنشاء نماذج الرؤية الحاسوبية، يمكن لجودة بيانات التدريب وتنوعها أن يؤثرا كثيرًا في أداء النموذج. توفّر Albumentations طريقة سريعة ومرنة وفعالة لتطبيق مجموعة واسعة من تحويلات الصور التي تحسّن قدرة النموذج على التكيف مع سيناريوهات العالم الحقيقي. ويتكامل Albumentations مع Ultralytics YOLO26، ويمكنه مساعدتك في إنشاء مجموعات بيانات متينة لمهام اكتشاف الكائنات وتجزئة المثيلات والتجزئة الدلالية وتقدير العمق وتقدير الوضعية والصناديق المحيطة الموجّهة.

يضيف Albumentations تقنيات مثل التحويلات الهندسية وتعديلات الألوان إلى بيانات تدريب YOLO26. يشرح هذا الدليل كيفية دمج Albumentations في خط أنابيب تعزيز البيانات في Ultralytics وكيفية تخصيصه لمشروعاتك.

Albumentations لزيادة تنوع الصور#

Albumentations مكتبة مفتوحة المصدر لتعزيز الصور، أُنشئت في يونيو 2018. صُممت لتبسيط عملية تعزيز الصور في الرؤية الحاسوبية وتسريعها. وقد أُنشئت مع مراعاة الأداء والمرونة، وتدعم تقنيات تعزيز متنوعة، بدءًا من التحويلات البسيطة كالتدوير والقلب وصولًا إلى التعديلات الأكثر تعقيدًا كتغيير السطوع والتباين. تساعد Albumentations المطورين على إنشاء مجموعات بيانات غنية ومتنوعة لمهام مثل تصنيف الصور واكتشاف الكائنات والتجزئة.

يمكنك استخدام Albumentations بسهولة لتطبيق التحسينات على الصور وأقنعة التجزئة والصناديق المحيطة والنقاط المفتاحية، مع ضمان تحويل جميع عناصر مجموعة البيانات معًا. وتعمل المكتبة مع أطر التعلم العميق الشائعة مثل PyTorch وTensorFlow، ما يجعلها مناسبة لمجموعة واسعة من المشروعات.

تلائم Albumentations مجموعات البيانات الصغيرة ومهام الرؤية الحاسوبية واسعة النطاق. تقلل المعالجة السريعة الوقت المستغرق في إعداد البيانات، كما يمكن لزيادة تنوع بيانات التدريب تحسين أداء النموذج في تطبيقات العالم الحقيقي.

الميزات الرئيسية لـ Albumentations#

توفّر Albumentations العديد من الميزات المفيدة التي تبسّط عمليات تحويل الصور المعقدة لمجموعة واسعة من تطبيقات الرؤية الحاسوبية. فيما يلي بعض الميزات الرئيسية:

  • مجموعة واسعة من التحويلات: توفّر Albumentations أكثر من 70 تحويلًا مختلفًا، بما في ذلك التغييرات الهندسية (مثل التدوير والقلب) وتعديلات الألوان (مثل السطوع والتباين) وإضافة الضوضاء (مثل ضوضاء غاوسية). ويتيح تعدد الخيارات إنشاء مجموعات بيانات تدريب متنوعة ومتينة للغاية.

Albumentations augmentation examples

  • تحسين الأداء العالي: بُنيت Albumentations على OpenCV وNumPy، وتستخدم تقنيات تحسين متقدمة مثل SIMD (تعليمة واحدة وبيانات متعددة)، التي تعالج نقاط بيانات متعددة في الوقت نفسه لتسريع المعالجة. وتعالج مجموعات البيانات الكبيرة بسرعة، مما يجعلها من أسرع الخيارات المتاحة لزيادة تنوع الصور.

  • ثلاثة مستويات للتحسين: تدعم Albumentations ثلاثة مستويات للتحسين: التحويلات على مستوى البكسل، والتحويلات المكانية، والتحويلات على مستوى المزج. تؤثر التحويلات على مستوى البكسل في الصور المدخلة فقط، دون تغيير الأقنعة أو الصناديق المحيطة أو النقاط المفتاحية. أما التحويلات المكانية فتغيّر الصورة وعناصرها، مثل الأقنعة والصناديق المحيطة. وتجمع التحويلات على مستوى المزج عدة صور في صورة واحدة.

أمثلة على التحسين في Albumentations على مستوى البكسل والمستوى المكاني ومستوى المزج

  • نتائج القياس المعياري: تُظهر اختبارات الأداء المنشورة لـAlbumentations سرعة جيدة مقارنةً بمكتبات التحسين الأخرى، لا سيما على مجموعات البيانات الكبيرة.

لماذا ينبغي لك استخدام Albumentations في مشروعات الذكاء الاصطناعي للرؤية؟#

تتميّز Albumentations بأنها أداة موثوقة لمهام الرؤية الحاسوبية المتعلقة بزيادة تنوع الصور. إليك بعض الأسباب الرئيسية التي تدعوك إلى التفكير في استخدامها في مشروعات الذكاء الاصطناعي للرؤية:

  • واجهة API سهلة الاستخدام: توفر Albumentations واجهة API واحدة وواضحة لتطبيق مجموعة واسعة من التحويلات على الصور والأقنعة والصناديق المحيطة والنقاط المفتاحية. صُممت لتتكيف بسهولة مع مجموعات البيانات المختلفة، مما يجعل إعداد البيانات أبسط وأكثر كفاءة.

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

  • قابلية التوسّع: تتيح Albumentations إضافة تحسينات جديدة بسهولة واستخدامها إلى جانب التحويلات المضمنة عبر واجهة واحدة.

كيفية استخدام Albumentations لزيادة تنوع بيانات تدريب YOLO26#

تتكامل Albumentations مباشرةً مع وضع التدريب في Ultralytics، وتُطبّق التحسينات تلقائيًا عند تثبيت حزمة Albumentations.

التثبيت#

لاستخدام Albumentations مع YOLO26، ابدأ بالتأكد من تثبيت الحزم المطلوبة. إذا لم تكن Albumentations مثبتة، فلن تُطبّق تحسيناتها أثناء التدريب. وبعد تثبيتها، تُطبّق التحويلات مباشرةً على صور التدريب أثناء سير العملية.

التثبيت
# Install the required packages
pip install albumentations ultralytics

للاطلاع على التعليمات التفصيلية وأفضل الممارسات المتعلقة بعملية التثبيت، راجع دليل تثبيت Ultralytics. إذا واجهت أي صعوبات أثناء تثبيت الحزم المطلوبة لـ YOLO26، فراجع دليل المشكلات الشائعة للاطلاع على الحلول والنصائح.

تتطلب أمثلة التحويلات المخصصة في هذه الصفحة الإصدار 1.4.22 من Albumentations أو إصدارًا أحدث، ولذلك تتطلب Python 3.9 أو إصدارًا أحدث.

الاستخدام#

بعد تثبيت الحزم المطلوبة، يمكنك البدء باستخدام Albumentations مع YOLO26. عند تدريب YOLO26 مع تثبيت Albumentations، تُطبّق مجموعة افتراضية من تحويلات Albumentations تلقائيًا.

الاستخدام
from ultralytics import YOLO

# ⁨تحميل نموذج مدرَّب مسبقًا⁩
model = YOLO("yolo26n.pt")

# ⁨درّب النموذج باستخدام التحويلات الافتراضية⁩
results = model.train(data="coco8.yaml", epochs=100, imgsz=640)

تصف الأقسام التالية تحويلات Albumentations الافتراضية التي تُطبّق أثناء التدريب.

التمويه#

يطبّق تحويل Blur في Albumentations تأثيرًا بسيطًا للتمويه على الصورة من خلال حساب متوسط قيم البكسلات ضمن مساحة مربعة صغيرة، أو نواة. ويُنفّذ ذلك باستخدام دالة OpenCV cv2.blur، التي تساعد على تقليل التشويش في الصورة، لكنها تقلل أيضًا تفاصيلها قليلًا.

فيما يلي المعلمات والقيم المستخدمة في هذا التكامل:

  • blur_limit: يتحكم هذا في نطاق حجم تأثير التمويه. النطاق الافتراضي هو (3, 7)، ما يعني أن حجم نواة التمويه يتراوح بين 3 و7 بكسلات، ولا يُسمح إلا بالأعداد الفردية للحفاظ على تمركز التمويه.

  • p: احتمال تطبيق التمويه. في هذا التكامل، p=0.01، أي أن احتمال تطبيق هذا التمويه على كل صورة يبلغ 1%. ويسمح هذا الاحتمال المنخفض بتطبيق التمويه من حين لآخر، ما يضيف قدرًا من التنوع ويساعد النموذج على التعميم دون الإفراط في تمويه الصور.

Albumentations Blur augmentation result

التمويه الوسيط#

يطبّق تحويل MedianBlur في Albumentations تأثير التمويه الوسيط على الصورة، وهو مفيد بوجه خاص لتقليل الضوضاء مع الحفاظ على الحواف. وعلى خلاف أساليب التمويه المعتادة، يستخدم MedianBlur مرشحًا وسيطًا، وهو فعّال على نحو خاص في إزالة ضوضاء الملح والفلفل مع الحفاظ على حدة الحواف.

فيما يلي المعلمات والقيم المستخدمة في هذا التكامل:

  • blur_limit: تتحكم هذه المعلمة في الحد الأقصى لحجم نواة التمويه. في هذا التكامل، نطاقها الافتراضي هو (3, 7)، ما يعني أن حجم نواة التمويه يُختار عشوائيًا بين 3 و7 بكسلات، ولا يُسمح إلا بالقيم الفردية لضمان المحاذاة الصحيحة.

  • p: يحدد احتمال تطبيق التمويه الوسيط. هنا، p=0.01، لذا يبلغ احتمال تطبيق التحويل على كل صورة 1%. ويضمن هذا الاحتمال المنخفض استخدام التمويه الوسيط باعتدال، مما يساعد النموذج على التعميم عبر إتاحة صور ذات ضوضاء أقل وحواف محفوظة له من حين لآخر.

تعرض الصورة أدناه مثالًا على تطبيق هذا التحويل على صورة.

Albumentations MedianBlur augmentation

تدرّج الرمادي#

يحوّل تحويل ToGray في Albumentations الصورة إلى تدرّج الرمادي، فيختزلها إلى تنسيق أحادي القناة، ويمكنه اختياريًا تكرار هذه القناة لتطابق عددًا محددًا من قنوات الإخراج. ويمكن استخدام طرق مختلفة لضبط كيفية حساب سطوع تدرّج الرمادي، بدءًا من حساب المتوسط البسيط ووصولًا إلى تقنيات أكثر تقدمًا لإدراك التباين والسطوع بصورة واقعية.

فيما يلي المعلمات والقيم المستخدمة في هذا التكامل:

  • num_output_channels: يحدد عدد القنوات في صورة الإخراج. إذا تجاوزت هذه القيمة 1، فستُكرّر قناة تدرّج الرمادي الوحيدة لإنشاء صورة متعددة القنوات بتدرّج الرمادي. والقيمة الافتراضية هي 3، ما ينتج صورة بتدرّج الرمادي تضم ثلاث قنوات متطابقة.

  • method: يحدد طريقة التحويل إلى تدرّج الرمادي. تطبّق الطريقة الافتراضية، "weighted_average"، صيغة (0.299R + 0.587G + 0.114B) التي تتوافق إلى حد كبير مع الإدراك البشري، فتنتج تأثيرًا طبيعيًا لتدرّج الرمادي. وتوفر الخيارات الأخرى، مثل "from_lab" و"desaturation" و"average" و"max" و"pca"، طرقًا بديلة لإنشاء صور بتدرّج الرمادي وفقًا لمتطلبات السرعة أو إبراز السطوع أو الحفاظ على التفاصيل.

  • p: يتحكم في مدى تكرار تطبيق تحويل تدرّج الرمادي. عند ضبط p=0.01، يبلغ احتمال تحويل كل صورة إلى تدرّج الرمادي 1%، ما يتيح مزج صور ملونة وأخرى بتدرّج الرمادي لمساعدة النموذج على التعميم بصورة أفضل.

تعرض الصورة أدناه مثالًا على تطبيق تحويل تدرّج الرمادي.

Albumentations grayscale conversion

معادلة المدرج التكراري التكيفية محدودة التباين (CLAHE)#

يطبّق تحويل CLAHE في Albumentations تقنية معادلة المدرج التكراري التكيفية محدودة التباين (CLAHE)، التي تعزز تباين الصورة من خلال معادلة المدرج التكراري في مناطق موضعية (مربعات) بدلًا من تطبيقها على الصورة كاملة. ينتج CLAHE تأثير تحسين متوازنًا، ويتجنب تضخيم التباين بصورة مفرطة، وهو ما قد ينتج عن معادلة المدرج التكراري القياسية، لا سيما في المناطق ذات التباين المنخفض أصلًا.

فيما يلي المعلمات والقيم المستخدمة في هذا التكامل:

  • clip_limit: يتحكم في نطاق تحسين التباين. وتُحدّد القيمة الافتراضية (1, 4) الحد الأقصى للتباين المسموح به في كل فسيفساء. تتيح القيم الأعلى تباينًا أكبر، لكنها قد تُدخل تشويشًا أيضًا.

  • tile_grid_size: يحدّد حجم شبكة الفسيفساء، ويُعبّر عنه عادةً بالصيغة (صفوف، أعمدة). والقيمة الافتراضية هي (8, 8)، أي تقسيم الصورة إلى شبكة 8x8. توفّر أحجام الفسيفساء الأصغر تعديلات أكثر موضعية، بينما تنتج الأحجام الأكبر تأثيرات أقرب إلى المعادلة العامة.

  • p: احتمال تطبيق CLAHE. هنا، تضيف p=0.01 تأثير التحسين بنسبة 1% فقط من الوقت، ما يضمن تطبيق تعديلات التباين باعتدال لإضفاء تنوع عرضي على صور التدريب.

تعرض الصورة أدناه مثالًا على تطبيق تحويل CLAHE.

Albumentations CLAHE contrast enhancement

استخدام تحويلات Albumentations مخصّصة#

مع أن التكامل الافتراضي لـAlbumentations يوفّر مجموعة قوية من التحسينات، فقد ترغب في تخصيص التحويلات لحالة استخدامك المحددة. باستخدام Ultralytics YOLO26، يمكنك تمرير تحويلات Albumentations مخصصة عبر Python API باستخدام المعامل augmentations. تتطلب الأمثلة في هذا القسم Albumentations 1.4.22 أو إصدارًا أحدث.

كيفية تعريف تحويلات مخصّصة#

يمكنك تعريف قائمة التحويلات الخاصة بك في Albumentations وتمريرها إلى دالة التدريب. يحل ذلك محل تحويلات Albumentations الافتراضية، مع إبقاء جميع تحويلات YOLO الأخرى (مثل hsv_h وdegrees وmosaic وغيرها) فعّالة.

إليك مثالًا على تحويلات أكثر تقدمًا:

import albumentations as A

from ultralytics import YOLO

# ⁨تحميل النموذج⁩
model = YOLO("yolo26n.pt")

# ⁨تعريف تحويلات مخصّصة باستخدام تقنيات متنوعة لزيادة البيانات⁩
custom_transforms = [
    # ⁨تنويعات التمويه⁩
    A.OneOf(
        [
            A.MotionBlur(blur_limit=7, p=1.0),
            A.MedianBlur(blur_limit=7, p=1.0),
            A.GaussianBlur(blur_limit=7, p=1.0),
        ],
        p=0.3,
    ),
    # ⁨تنويعات الضوضاء⁩
    A.OneOf(
        [
            A.GaussNoise(std_range=(0.0124, 0.0277), p=1.0),
            A.ISONoise(color_shift=(0.01, 0.05), intensity=(0.1, 0.5), p=1.0),
        ],
        p=0.2,
    ),
    # ⁨تعديلات الألوان والتباين⁩
    A.CLAHE(clip_limit=4.0, tile_grid_size=(8, 8), p=0.5),
    A.RandomBrightnessContrast(brightness_limit=0.3, contrast_limit=0.3, p=0.5),
    A.HueSaturationValue(hue_shift_limit=20, sat_shift_limit=30, val_shift_limit=20, p=0.5),
    # ⁨محاكاة حالات الحجب⁩
    A.CoarseDropout(num_holes_range=(1, 8), hole_height_range=(8, 32), hole_width_range=(8, 32), fill=0, p=0.2),
]

# ⁨التدريب باستخدام تحويلات مخصّصة⁩
results = model.train(
    data="coco8.yaml",
    epochs=100,
    imgsz=640,
    augmentations=custom_transforms,
)

اعتبارات مهمة#

عند استخدام تحويلات Albumentations مخصّصة، ضع النقاط التالية في الحسبان:

  • الإعدادات: أنشئ كائنات التحويلات المخصّصة عبر واجهة Python البرمجية. ويمكن أيضًا تمرير التحويلات المتسلسلة عبر CLI أو ملفات إعداد YAML، بما في ذلك عند استئناف التدريب.
  • استبدال الإعدادات الافتراضية: ستحل تحويلاتك المخصّصة محل تحويلات Albumentations الافتراضية بالكامل. وتظل تحويلات YOLO الأخرى فعّالة.
  • معالجة التسميات: تنقل التحويلات المكانية، بما فيها التحويلات المتداخلة داخل A.OneOf أو A.Compose، مربعات الإحاطة والمضلعات والنقاط المفتاحية وأقنعة العمق أو الدلالات مع الصورة. ولا يستطيع A.RandomGridShuffle الحفاظ على بنية المضلعات أو النقاط المفتاحية، ويؤدي استخدامه مع عينات التقسيم وتقدير الوضع وOBB إلى ظهور خطأ.
  • الأداء: تتطلب بعض التحويلات موارد حسابية كبيرة. راقب سرعة التدريب واضبطها وفقًا لذلك.
  • التوافق مع المهام: تعمل تحويلات Albumentations المخصّصة مع التدريب على الكشف والتقسيم والتقسيم الدلالي والعمق وتقدير الوضع وOBB، لكنها لا تعمل مع التصنيف (الذي يستخدم مسارًا مختلفًا لزيادة البيانات).

حالات استخدام التحويلات المخصّصة#

تستفيد التطبيقات المختلفة من استراتيجيات متنوعة لزيادة البيانات:

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

للاطلاع على القائمة الكاملة للتحويلات المتاحة ومعاملاتها، تفضل بزيارة وثائق Albumentations.

للاطلاع على أمثلة أكثر تفصيلًا وأفضل الممارسات لاستخدام تحويلات Albumentations المخصّصة مع YOLO26، راجع دليل زيادة بيانات YOLO.

واصل التعلّم عن Albumentations#

إذا كنت مهتمًا بمعرفة المزيد عن Albumentations، فاطّلع على الموارد التالية للحصول على إرشادات وأمثلة أكثر تفصيلًا:

أهم النتائج#

استعرضنا في هذا الدليل الجوانب الأساسية لـAlbumentations، وهي مكتبة Python لتعزيز الصور. وناقشنا نطاق التحويلات الواسع الذي توفره، وأداءها المحسّن، وكيفية استخدامها في مشروع YOLO26 المقبل.

الأسئلة الشائعة#

  • يتكامل Albumentations مع YOLO26، وتُطبّق التحسينات تلقائيًا أثناء التدريب إذا كانت الحزمة مثبتة لديك. إليك كيفية البدء:

    # ⁨تثبيت الحزم المطلوبة⁩
    # !pip install albumentations ultralytics
    from ultralytics import YOLO
    
    # ⁨تحميل النموذج وتدريبه باستخدام عمليات زيادة البيانات التلقائية⁩
    model = YOLO("yolo26n.pt")
    model.train(data="coco8.yaml", epochs=100)

    يطبّق التكامل الافتراضي التمويه والتمويه الوسيط والتحويل إلى التدرج الرمادي وCLAHE، باحتمال منخفض يبلغ 1% لكل منها، لتوفير تنوع عرضي دون أن تطغى على التدريب.

  • يتميّز Albumentations لعدة أسباب:

    1. الأداء: مبني على OpenCV وNumPy مع تحسين SIMD لتحقيق سرعة عالية
    2. المرونة: يدعم أكثر من 70 تحويلًا لزيادة البيانات على مستوى البكسل والمستوى المكاني ومستوى المزج.
    3. التوافق: يعمل مع أطر العمل الشائعة مثل PyTorch وTensorFlow
    4. الموثوقية: تمنع مجموعة الاختبارات الشاملة تلف البيانات غير الملحوظ.
    5. سهولة الاستخدام: واجهة API موحّدة واحدة لجميع أنواع زيادة البيانات.
  • يعزز Albumentations مجموعة متنوعة من مهام الرؤية الحاسوبية، ومنها:

    تجعل خيارات زيادة البيانات المتنوعة في المكتبة منها أداة قيّمة لمهام الرؤية التي تتطلب أداءً قويًا للنموذج. وفي Ultralytics YOLO26، يستخدم تدريب التصنيف مسارًا خاصًا به لزيادة البيانات قائمًا على torchvision، ولا يطبّق تحويلات Albumentations.

التعليقات19

اطرح سؤالًا، وشارك نتائجك، أو ساعد شخصًا آخر.

  1. anushka-koreGitHub

    Is there a way that we can define more custom albumentations transforms to be applied during model train? If yes, will they also change the bounding box coords accordingly if they are spatial transforms?

    1. manuelescobar5036GitHub

      The albumentations transforms are defined in the ultralytics/data/augment.py file. There you can find the following function that returns the transforms to be applied to the images, which includes the Albumentations transform. image

      Then, in the same file you can find the Albumentations class which defines the pipeline. In this pipeline you can add the new transforms that you want. image

      Bouding boxes are changed accordingly to their spatial transforms. This is done when you pass bbox_params to the Albumentations pipeline. image

    2. Glenn JocherUltralytics(تم التعديل)

      @anushka-kore Yes. Pass your own Albumentations transforms to training with the augmentations argument (Python only):

      import albumentations as A
      from ultralytics import YOLO
      
      model = YOLO("yolo26n.pt")
      model.train(data="coco8.yaml", augmentations=[A.Blur(p=0.01), A.CLAHE(p=0.01)])

      Spatial transforms (rotation, flips, perspective, etc.) are applied together with the bounding boxes, which are updated automatically through Albumentations' bbox handling in YOLO format. Non-spatial transforms like color adjustments only change the image. See the Albumentations integration guide for details.

    3. anushka-koreGitHub

      Hey @glenn-jocher and @deox1994, I later realised that simply defining my list of custom transform in the augment.py file is not working. This is the part I changed in the augment.py file (original ones are commented out)-

              T = [
                  #A.Blur(p=0.01),
                  #A.MedianBlur(p=0.01),
                  #A.ToGray(p=0.01),
                  #A.CLAHE(p=0.01),
                  A.RandomBrightnessContrast(p=0.2),
                  #A.RandomGamma(p=0.0),
                  #A.ImageCompression(quality_range=(75, 100), p=0.0),
                  A.HorizontalFlip(p=0.5),
                  A.VerticalFlip(p=0.5),
                  A.Rotate(limit=30, p=0.5),
                  A.GaussianBlur(p=0.2),
                  A.GaussNoise(p=0.2),
              ]

      For your reference, this is the error I get, you could view the list of albumentation transforms I applied here as well- ..... Transferred 1009/1015 items from pretrained weights Freezing layer 'model.23.dfl.conv.weight' AMP: running Automatic Mixed Precision (AMP) checks... AMP: checks passed ✅ train: Scanning /home/xxx/dataset_MIP_clean/train/labels.cache... 831 images, 73 backgrounds, 0 corrupt: 100%|██████████| 831/831 [00:00<?, ?it/s] albumentations: RandomBrightnessContrast(p=0.2, brightness_by_max=True, brightness_limit=(-0.2, 0.2), contrast_limit=(-0.2, 0.2), ensure_safe_range=False), HorizontalFlip(p=0.5), VerticalFlip(p=0.5), Rotate(p=0.5, border_mode=0, crop_border=False, fill=0.0, fill_mask=0.0, interpolation=1, limit=(-30.0, 30.0), mask_interpolation=0, rotate_method='largest_box'), GaussianBlur(p=0.2, blur_limit=(0, 0), sigma_limit=(0.5, 3.0)), GaussNoise(p=0.2, mean_range=(0.0, 0.0), noise_scale_factor=1.0, per_channel=True, std_range=(0.2, 0.44)) val: Scanning /home/xxx/dataset_MIP_clean/val/labels.cache... 210 images, 13 backgrounds, 0 corrupt: 100%|██████████| 210/210 [00:00<?, ?it/s] Plotting labels to /home/xxx/yolov11_predictions/test4/labels.jpg... optimizer: 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'momentum' automatically... optimizer: AdamW(lr=0.000769, momentum=0.9) with parameter groups 167 weight(decay=0.0), 174 weight(decay=0.0005), 173 bias(decay=0.0) Image sizes 640 train, 640 val Using 8 dataloader workers Logging results to /home/xxx/yolov11_predictions/test4 Starting training for 200 epochs...

        Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
        1/200      15.4G      5.502      51.38      2.745         17        640:  10%|▉         | 5/52 [00:02<00:22,  2.07it/s]

      Traceback (most recent call last): File "/home/xxx/yolo_train.py", line 149, in train_yolo(output_dir) File "/home/xxx/yolo_train.py", line 116, in train_yolo results = model.train( ^^^^^^^^^^^^ File "/home/xxx/env/lib/python3.12/site-packages/ultralytics/engine/model.py", line 791, in train self.trainer.train() File "/home/xxx/env/lib/python3.12/site-packages/ultralytics/engine/trainer.py", line 211, in train self._do_train(world_size) File "/home/xxx/env/lib/python3.12/site-packages/ultralytics/engine/trainer.py", line 366, in _do_train for i, batch in pbar: ^^^^ File "/home/xxx/env/lib/python3.12/site-packages/tqdm/std.py", line 1178, in iter for obj in iterable: ^^^^^^^^ File "/home/xxx/env/lib/python3.12/site-packages/ultralytics/data/build.py", line 59, in iter yield next(self.iterator) ^^^^^^^^^^^^^^^^^^^ File "/home/xxx/env/lib/python3.12/site-packages/torch/utils/data/dataloader.py", line 708, in next data = self._next_data() ^^^^^^^^^^^^^^^^^ File "/home/xxx/env/lib/python3.12/site-packages/torch/utils/data/dataloader.py", line 1455, in _next_data return self._process_data(data) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/xxx/env/lib/python3.12/site-packages/torch/utils/data/dataloader.py", line 1505, in _process_data data.reraise() File "/home/xxx/env/lib/python3.12/site-packages/torch/_utils.py", line 733, in reraise raise exception RuntimeError: Caught RuntimeError in DataLoader worker process 5. Original Traceback (most recent call last): File "/home/xxx/env/lib/python3.12/site-packages/torch/utils/data/_utils/worker.py", line 349, in _worker_loop data = fetcher.fetch(index) # type: ignore[possibly-undefined] ^^^^^^^^^^^^^^^^^^^^ File "/home/xxx/env/lib/python3.12/site-packages/torch/utils/data/_utils/fetch.py", line 55, in fetch return self.collate_fn(data) ^^^^^^^^^^^^^^^^^^^^^ File "/home/xxx/env/lib/python3.12/site-packages/ultralytics/data/dataset.py", line 298, in collate_fn value = torch.cat(value, 0) ^^^^^^^^^^^^^^^^^^^ RuntimeError: Tensors must have same number of dimensions: got 1 and 2

      All my transforms are correctly defined, and the spatial transforms (horizontalflip, verticalflip and rotate) exist in the spatial_transforms list. Could you please point where this is going wrong?

    4. supriamirGitHub

      Hi Glen,

      I would like to optimize the hyperparameters using model.tune(). My goal is to identify the most important augmentations from Albumentations.

      If I am not mistaken, the default hyperparameter optimization only includes a limited set of augmentation parameters, as described in the following link: https://docs.ultralytics.com/integrations/ray-tune/#tune-method-parameters

      Could you advise how I can include and optimize additional Albumentations transforms beyond the default settings?

    5. Glenn JocherUltralytics

      Yes, but not directly through the default model.tune() search set: custom Albumentations are a Python-only augmentations list passed to model.train(), while the built-in tuner mutates the numeric space, so the usual workflow is to keep one fixed augmentations= pipeline per tuning run and compare the best result across several candidate pipelines; if you want to search the pipeline itself, use a small custom Ray Tune wrapper around model.train() instead, and keep the standard YOLO augmentations fixed so you isolate the Albumentations effect—see the hyperparameter tuning guide and the Albumentations integration guide.

  2. UltralyticsAssistantGitHubUltralytics

    👋 Hello, thank you for your interest in Ultralytics 🚀! We recommend visiting the Docs for guidance—there you’ll find many Python and CLI usage examples, and answers to many common questions.

    If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us investigate.

    If you have a custom training ❓ Question, please share as much relevant information as possible, including dataset image examples and training logs. Also, make sure to review our Tips for Best Training Results.

    You’re welcome to join the Ultralytics community where it fits you best:

    • For real-time chat, join us on Discord 🎧
    • For in-depth discussions, visit Discourse
    • For community sharing, check out our Subreddit

    Upgrade

    Upgrade to the latest ultralytics package and all requirements in a Python>=3.8 environment with PyTorch>=1.8 to ensure you’re on the latest version:

    pip install -U ultralytics

    Environments

    YOLO can be run in any of the following up-to-date verified environments (with all dependencies like CUDA/CUDNN, Python, and PyTorch preinstalled):

    Status

    Ultralytics CI

    If this badge is green, all Ultralytics CI tests are currently passing. These tests confirm correct operation of all YOLO Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

    This is an automated response 🤖. An Ultralytics engineer will assist you here soon!

    1. Glenn JocherUltralytics

      欢迎来到 Ultralytics 中文文档的 Albumentations 集成讨论区!如果您对使用 Albumentations 来增强 YOLO11 训练数据有任何问题或想法,请在这里提出。

      Albumentations 与 YOLO11 的集成非常简便,只需安装 albumentations 包,就会在训练过程中自动应用多种图像增强技术,如模糊、中值模糊、灰度转换和 CLAHE,帮助您的模型更好地适应各种真实场景。

      您是否在特定项目中使用过 Albumentations?或者您对如何最佳配置这些增强技术有疑问?请随时在这里分享您的经验或提出问题,Ultralytics 团队将很乐意提供帮助!

  3. UltralyticsAssistantGitHubUltralytics

    👋 Hello, thank you for your interest in Ultralytics 🚀! We recommend visiting the Docs for guidance on integrations like Albumentations with YOLO11. You can also review many Python and CLI examples, and frequently asked questions may already be addressed there.

    If this is a 🐛 Bug Report, please include a minimum reproducible example to help us investigate further.

    If you have a custom training ❓ Question, please provide detailed info such as dataset image samples, training logs, and confirm you are following our Tips for Best Training Results.

    Join the Ultralytics community wherever you prefer—real-time chat on Discord 🎧, in-depth discussions on Discourse, or knowledge-sharing on our Subreddit.

    Upgrade

    Upgrade to the latest ultralytics package and all requirements in a Python>=3.8 environment with PyTorch>=1.8 to ensure your issue is not already fixed in the latest version:

    pip install -U ultralytics

    Environments

    YOLO may be run in any of the following verified and up-to-date environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

    Status

    Ultralytics CI

    If this badge is green, all Ultralytics CI tests are currently passing. These tests verify correct operation of all YOLO Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

    This is an automated response. An Ultralytics engineer will review and assist you soon!

    1. Glenn JocherUltralytics

      Bonjour! N'hésitez pas à poser vos questions sur l'intégration d'Albumentations avec YOLO11 dans cette discussion. Cette intégration vous permet d'améliorer automatiquement votre jeu de données pendant l'entraînement avec diverses transformations comme le flou, le flou médian, la conversion en niveaux de gris et CLAHE.

      L'avantage principal est sa simplicité d'utilisation - il suffit d'installer les packages requis et les augmentations sont appliquées automatiquement pendant l'entraînement:

      pip install albumentations ultralytics

      Si vous rencontrez des difficultés avec cette intégration ou si vous avez des questions sur l'augmentation de données pour améliorer les performances de vos modèles YOLO11, n'hésitez pas à les partager ici!

  4. manuelescobar5036GitHub(تم التعديل)

    Dear Ultralytics team,

    I’m working on a project focused on detecting the behavior of workers in underground mines. The classes and the number of labels per class in the training set are as follows:

    • Sitting → 2500
    • Standing → 9000
    • Operation → 700
    • Lean Against → 4000
    • Tumble → 400

    Since the dataset is imbalanced, I would like to apply data augmentation to avoid overfitting and improve accuracy. While researching YOLO's data augmentation capabilities, a few questions came up:

    1. As far as I understand, YOLO currently supports two methods for performing data augmentation:
    • Modifying individual hyperparameters such as hsv_h, hsv_s, hsv_v, degrees, translate, etc., in the ultralytics/cfg/default.yaml file (does not require the Albumentations Python Library).
    • Using the Albumentations Python Library (previously installed).

    Is this correct? If so, what are the differences between the two methods, and which one is currently recommended?

    1. Considering both options from question 1, does YOLO apply data augmentation only to images from the classes with less labels, or to images from all classes? I ask because if I have an imbalanced dataset and YOLO applies data augmentation to images from all classes, the imbalance would remain, wouldn’t it?

    2. If I choose to use an older YOLO model, such as yolov8n.yaml, and I have Albumentations installed, will Albumentations-based data augmentation be applied during training?

    3. What other suggestions would you recommend for dealing with imbalanced classes?

    1. Glenn JocherUltralytics

      @deox1994 Thanks for your detailed questions about data augmentation in YOLO for handling your imbalanced mining worker dataset. Let me address each point:

      1. Yes, you're correct about the two augmentation approaches:
        • Built-in YOLO augmentations (hsv_h, translate, scale, etc.) which are always available
        • Albumentations integration which activates automatically when the library is installed

      The key difference is that built-in augmentations focus primarily on geometric and color transformations, while Albumentations adds more specialized transformations like blur, grayscale, and CLAHE with carefully tuned probabilities (typically 0.01 as shown in the reference code). Both work together complementarily rather than being exclusive options.

      1. Both augmentation methods apply to all images regardless of class. To address your imbalance specifically, consider:

        • Using a weighted loss function
        • Implementing class-aware sampling during training
        • Creating custom data pipeline that applies additional augmentations to underrepresented classes
      2. Yes, if Albumentations is installed, it will be automatically applied when training YOLOv8 models too. The integration is part of the Ultralytics framework, not specific to YOLO11.

      3. For handling imbalanced classes beyond augmentation:

        • Apply weighted loss based on inverse class frequency
        • Use focal loss which naturally handles class imbalance better
        • Consider different evaluation metrics (precision/recall per class rather than just mAP)
        • Experiment with undersampling majority classes or oversampling minority classes

      You can find implementation details for these approaches in the data augment reference documentation.

    2. safwene-bahrounGitHub

      Good morning ,@glenn-jocher, do you can help me ?

      { "total_images": 39152, "total_detections": 70910, "instances_per_class": { "Dress": 52999, "Skirt": 1259, "Handbag": 2495, "High heels": 3124, "Swimwear": 10079, "Miniskirt": 954 } } i will train this with yolo11n.pt and with albumentation the code : from ultralytics import YOLO import torch

      def main(): # Load a pretrained YOLO model model = YOLO("yolo11n.pt") # Set device device = "cuda" if torch.cuda.is_available() else "cpu" print(f"Using device: {device}")

      if device == "cuda":
          print(f"GPU name: {torch.cuda.get_device_name(0)}")
      
      # Debug: Print dataset configuration
      print("Training with dataset: OpenImagesV7-women.yaml")
      
      # Train the model with enhanced hyperparameters
      results = model.train(
      data="OpenImagesV7-woman.yaml",
      epochs=150,
      imgsz=640,
      device=device,
      batch=16,
      optimizer ="auto"

      )

      Dataset configuration

      path: ../datasets/open-images-v7 train: c:\Users\GIGABYTE\datasets\open-images-v7\train val: C:/Users/GIGABYTE/datasets/open-images-v7/val

      nc: 6 names: 0: Dress 1: High heels 2: Miniskirt 3: Skirt 4: Swimwear 5: Handbag

      Hyperparameters for extreme imbalance

      loss: cls_weight: [0.3, 0.5, 7.0, 5.0, 0.4, 0.6] # Calculated weights below box: 0.05 obj: 1.0 label_smoothing: 0.1

      Strategic augmentation

      augment:

      For rare classes (Miniskirt, Skirt)

      copy_paste: 0.7 # High frequency for rare classes paste_classes: [2, 3] # Only Miniskirt(class2)/Skirt(class3) paste_scale: [0.3, 0.7] # Realistic resizing of pasted objects

      General augmentations (applied to all)

      mosaic: 1.0 # Helps context learning mixup: 0.05 # Reduced to avoid label confusion fliplr: 0.5 hsv_h: 0.015 # Mild color variation degrees: 5.0 # Small rotation for fashion items

      Training parameters

      batch: 16 # Match GPU capacity accumulate: 4 # Simulates batch=64 epochs: 150 # Longer training for rare classes patience: 50 # Early stopping if no improveme

      but i trained untill now :
      Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size 104/150 2.92G 1.026 0.9478 1.206 55 640: 100%|██████████| 2447/2447 [07:51<00:00, Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 32/32 [00:06 all 1016 1987 0.581 0.525 0.536 0.423

      Can you help me please to reach all metrics above 0.8

      THANKS

  5. hillsonghimireGitHub

    Even when I turned off augment=False, albumentation-related operations were still performed in yolo11. How to completely turn it off/disable?

    1. Glenn JocherUltralytics

      @hillsonghimire to completely disable Albumentations augmentations in YOLO11, uninstall the Albumentations package since its presence automatically enables the integration. Run pip uninstall albumentations and verify it's removed from your environment. This will prevent any Albumentations transformations from being applied regardless of other settings. For more details, see the Albumentations integration guide.

  6. DP1701GitHub

    Thanks for this explanation. But if I understand correctly, not all functions of Albuminations are directly supported, or am I misunderstanding?

    The explanation says: The integration includes optimized augmentations like blur, median blur, grayscale conversion, and CLAHE with carefully tuned probabilities to enhance model performance.

    So only blur, median blur, grayscale conversion and CLAHE are applied and the others cannot be individually selected and adjusted?

    1. Glenn JocherUltralytics(تم التعديل)

      The integration with Albumentations in YOLO11 automatically applies specific augmentations like blur, median blur, grayscale conversion, and CLAHE. While these are the default transformations used to enhance model performance, you can pass your own Albumentations transforms to model.train() with the augmentations argument (Python only).