{
  "id": 574663,
  "title": "Augmentations in Ultralytics",
  "url": "/competitions/byu-locating-bacterial-flagellar-motors-2025/discussion/574663",
  "author_name": "",
  "post_date": "2025-04-23T06:17:57.799894700Z",
  "votes": 13,
  "comment_count": 8,
  "views": 0,
  "content": "<p>Is anyone else having a hard time understanding how augmentations work in Ultralytics? The documentation is not very clear, and most of the questions on GitHub regarding augmentation are answered by AI. I thought I'd write this post in case anyone else has faced the same problem, and has found some clever solution.</p>\n<h3>Disabling Augmentations</h3>\n<p>First off, there doesn't seem to be any reliable way to disable augmentations. Setting <code>augment=False</code> in the <code>.train()</code> method doesn't seem to have any effect, nor does setting all augmentation parameters to 0. No matter which augmentation parameters I change, this line always appears in the logs:</p>\n<pre><code>albumentations: Blur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01, blur_limit=(3, 7)), ToGray(p=0.01, num_output_channels=3, method=), CLAHE(p=0.01, clip_limit=(1.0, 4.0), tile_grid_size=(8, 8))\n</code></pre>\n<p>The only way I've found to remove this line is by uninstalling albumentations.</p>\n<h3>Customizing Augmentations Provided by Ultralytics</h3>\n<p>From what I understand, augmentations can be configured either via the YAML config file or by passing parameters directly to the <code>.train()</code> method. I've tried both approaches, but neither seems to work. Nothing I've done affects what is printed in the albumentations section of the logs. Either the augmentations I defined are being applied and not shown in the logs, or they're not being applied at all.</p>\n<h3>Custom Augmentations</h3>\n<p>I've also struggled with implementing custom augmentations, as the options Ultralytics provides are quite limited. Based on <a href=\"https://github.com/ultralytics/ultralytics/issues/9192#issuecomment-2708507624\" target=\"_blank\">this discussion</a>, it seems there's no clean way to use custom augmentations other than modifying the source code. If anyone has found a better solution, I'd be grateful to hear about it.</p>",
  "messages": [
    {
      "id": "3185309",
      "postDate": "04/23/2025 06:17:57",
      "content": "<p>Is anyone else having a hard time understanding how augmentations work in Ultralytics? The documentation is not very clear, and most of the questions on GitHub regarding augmentation are answered by AI. I thought I'd write this post in case anyone else has faced the same problem, and has found some clever solution.</p>\n<h3>Disabling Augmentations</h3>\n<p>First off, there doesn't seem to be any reliable way to disable augmentations. Setting <code>augment=False</code> in the <code>.train()</code> method doesn't seem to have any effect, nor does setting all augmentation parameters to 0. No matter which augmentation parameters I change, this line always appears in the logs:</p>\n<pre><code>albumentations: Blur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01, blur_limit=(3, 7)), ToGray(p=0.01, num_output_channels=3, method=), CLAHE(p=0.01, clip_limit=(1.0, 4.0), tile_grid_size=(8, 8))\n</code></pre>\n<p>The only way I've found to remove this line is by uninstalling albumentations.</p>\n<h3>Customizing Augmentations Provided by Ultralytics</h3>\n<p>From what I understand, augmentations can be configured either via the YAML config file or by passing parameters directly to the <code>.train()</code> method. I've tried both approaches, but neither seems to work. Nothing I've done affects what is printed in the albumentations section of the logs. Either the augmentations I defined are being applied and not shown in the logs, or they're not being applied at all.</p>\n<h3>Custom Augmentations</h3>\n<p>I've also struggled with implementing custom augmentations, as the options Ultralytics provides are quite limited. Based on <a href=\"https://github.com/ultralytics/ultralytics/issues/9192#issuecomment-2708507624\" target=\"_blank\">this discussion</a>, it seems there's no clean way to use custom augmentations other than modifying the source code. If anyone has found a better solution, I'd be grateful to hear about it.</p>",
      "rawMarkdown": "Is anyone else having a hard time understanding how augmentations work in Ultralytics? The documentation is not very clear, and most of the questions on GitHub regarding augmentation are answered by AI. I thought I'd write this post in case anyone else has faced the same problem, and has found some clever solution.\n\n### Disabling Augmentations\nFirst off, there doesn't seem to be any reliable way to disable augmentations. Setting `augment=False` in the `.train()` method doesn't seem to have any effect, nor does setting all augmentation parameters to 0. No matter which augmentation parameters I change, this line always appears in the logs:\n\n```bash\nalbumentations: Blur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01, blur_limit=(3, 7)), ToGray(p=0.01, num_output_channels=3, method='weighted_average'), CLAHE(p=0.01, clip_limit=(1.0, 4.0), tile_grid_size=(8, 8))\n```\nThe only way I've found to remove this line is by uninstalling albumentations.\n\n\n### Customizing Augmentations Provided by Ultralytics\nFrom what I understand, augmentations can be configured either via the YAML config file or by passing parameters directly to the `.train()` method. I've tried both approaches, but neither seems to work. Nothing I've done affects what is printed in the albumentations section of the logs. Either the augmentations I defined are being applied and not shown in the logs, or they're not being applied at all.\n\n\n### Custom Augmentations\nI've also struggled with implementing custom augmentations, as the options Ultralytics provides are quite limited. Based on [this discussion](https://github.com/ultralytics/ultralytics/issues/9192#issuecomment-2708507624), it seems there's no clean way to use custom augmentations other than modifying the source code. If anyone has found a better solution, I'd be grateful to hear about it.",
      "votes": null
    },
    {
      "id": "3185419",
      "postDate": "04/23/2025 09:30:44",
      "content": "<p>You are correct with the conclusion that those albumentations are applied automatically unless you uninstall the library. Use this code snippet to create your own pipeline.</p>\n<pre><code> ultralytics.data.augment  Albumentations\n ultralytics.utils  LOGGER, colorstr\n albumentations  A\n\n ():\n        .p = p\n        .transform = \n        prefix = colorstr()\n        :\n             albumentations  A\n\n            \n\n            \n            T = [\n                A.RandomRotate90(p=),\n                A.HorizontalFlip(p=),\n                A.VerticalFlip(p=),\n                A.Rotate(limit=, p=),\n            ]\n            .transform = A.Compose(T, bbox_params=A.BboxParams(=, label_fields=[]))\n\n            LOGGER.info(prefix + .join(.replace(, )  x  T  x.p))\n         ImportError:  \n            \n         Exception  e:\n            LOGGER.info()\n\nAlbumentations.__init__ = __init__\n</code></pre>",
      "rawMarkdown": "You are correct with the conclusion that those albumentations are applied automatically unless you uninstall the library. Use this code snippet to create your own pipeline.\n\n```\nfrom ultralytics.data.augment import Albumentations\nfrom ultralytics.utils import LOGGER, colorstr\nimport albumentations as A\n\ndef __init__(self, p=1.0):\n        self.p = p\n        self.transform = None\n        prefix = colorstr(\"albumentations: \")\n        try:\n            import albumentations as A\n\n            # check_version(A.__version__, \"1.0.3\", hard=True)  # version requirement\n\n            # Transforms\n            T = [\n                A.RandomRotate90(p=0.8),\n                A.HorizontalFlip(p=0.5),\n                A.VerticalFlip(p=0.5),\n                A.Rotate(limit=15, p=0.3),\n            ]\n            self.transform = A.Compose(T, bbox_params=A.BboxParams(format=\"yolo\", label_fields=[\"class_labels\"]))\n\n            LOGGER.info(prefix + \", \".join(f\"{x}\".replace(\"always_apply=False, \", \"\") for x in T if x.p))\n        except ImportError:  # package not installed, skip\n            pass\n        except Exception as e:\n            LOGGER.info(f\"{prefix}{e}\")\n\nAlbumentations.__init__ = __init__\n```",
      "votes": null
    },
    {
      "id": "3185441",
      "postDate": "04/23/2025 10:08:35",
      "content": "<p>Hacky, but it works! Thank you <a href=\"https://www.kaggle.com/andreizamfir\" target=\"_blank\">@andreizamfir</a>!</p>",
      "rawMarkdown": "Hacky, but it works! Thank you @andreizamfir!",
      "votes": null
    },
    {
      "id": "3186160",
      "postDate": "04/24/2025 09:33:56",
      "content": "<p>Full Discussion : <a href=\"https://github.com/ultralytics/ultralytics/issues/257\" target=\"_blank\">https://github.com/ultralytics/ultralytics/issues/257</a></p>",
      "rawMarkdown": "Full Discussion : [https://github.com/ultralytics/ultralytics/issues/257](https://github.com/ultralytics/ultralytics/issues/257)",
      "votes": null
    },
    {
      "id": "3186172",
      "postDate": "04/24/2025 09:56:32",
      "content": "<p>For newer versions:</p>\n<pre><code> ():\n    .p = p\n    .transform = \n    prefix = colorstr()\n\n    :\n        spatial_transforms = {\n            ,\n            ,\n            \n        }\n\n        T = [\n            A.HorizontalFlip(p=),\n            A.RandomRotate90(p=),\n            A.VerticalFlip(p=)\n        ]\n\n        .contains_spatial = (transform.__class__.__name__  spatial_transforms  transform  T)\n\n        .transform = (\n            A.Compose(T, bbox_params=A.BboxParams(=, label_fields=[]))\n             .contains_spatial\n             A.Compose(T)\n        )\n\n         (.transform, ):\n            .transform.set_random_seed(torch.initial_seed())\n\n        LOGGER.info(prefix + .join(.replace(, )  x  T  x.p))\n\n     Exception  e:\n        LOGGER.info()\n\nAlbumentations.__init__ = __init__\n</code></pre>",
      "rawMarkdown": "For newer versions:\n```python\ndef __init__(self, p=1.0):\n    self.p = p\n    self.transform = None\n    prefix = colorstr(\"albumentations: \")\n\n    try:\n        spatial_transforms = {\n            \"HorizontalFlip\",\n            \"RandomRotate90\",\n            \"VerticalFlip\"\n        }\n        \n        T = [\n            A.HorizontalFlip(p=0.3),\n            A.RandomRotate90(p=0.3),\n            A.VerticalFlip(p=0.3)\n        ]\n\n        self.contains_spatial = any(transform.__class__.__name__ in spatial_transforms for transform in T)\n        \n        self.transform = (\n            A.Compose(T, bbox_params=A.BboxParams(format=\"yolo\", label_fields=[\"class_labels\"]))\n            if self.contains_spatial\n            else A.Compose(T)\n        )\n        \n        if hasattr(self.transform, \"set_random_seed\"):\n            self.transform.set_random_seed(torch.initial_seed())\n        \n        LOGGER.info(prefix + \", \".join(f\"{x}\".replace(\"always_apply=False, \", \"\") for x in T if x.p))\n        \n    except Exception as e:\n        LOGGER.info(f\"{prefix}{e}\")\n\nAlbumentations.__init__ = __init__\n```",
      "votes": null
    },
    {
      "id": "3186398",
      "postDate": "04/24/2025 15:43:55",
      "content": "<p>Have you tried to fine tune with this custom augmentations?<br>\nI recently used tune from yolo was too comput cost for me.</p>",
      "rawMarkdown": "Have you tried to fine tune with this custom augmentations?\nI recently used tune from yolo was too comput cost for me.",
      "votes": null
    },
    {
      "id": "3188089",
      "postDate": "04/27/2025 03:28:22",
      "content": "<p>Thanks for your insight, that is right we can have full control over augmentations during our training this way.</p>",
      "rawMarkdown": "Thanks for your insight, that is right we can have full control over augmentations during our training this way.",
      "votes": null
    },
    {
      "id": "3188814",
      "postDate": "04/28/2025 08:46:53",
      "content": "<p>Thanks for your contribution </p>",
      "rawMarkdown": "Thanks for your contribution",
      "votes": null
    },
    {
      "id": "3189212",
      "postDate": "04/29/2025 00:30:05",
      "content": "<p>Very informative 😃</p>",
      "rawMarkdown": "Very informative 😃",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 3185419,
      "author_name": "andreizamfir",
      "author_url": "",
      "post_date": "04/23/2025 09:30:44",
      "content": "<p>You are correct with the conclusion that those albumentations are applied automatically unless you uninstall the library. Use this code snippet to create your own pipeline.</p>\n<pre><code> ultralytics.data.augment  Albumentations\n ultralytics.utils  LOGGER, colorstr\n albumentations  A\n\n ():\n        .p = p\n        .transform = \n        prefix = colorstr()\n        :\n             albumentations  A\n\n            \n\n            \n            T = [\n                A.RandomRotate90(p=),\n                A.HorizontalFlip(p=),\n                A.VerticalFlip(p=),\n                A.Rotate(limit=, p=),\n            ]\n            .transform = A.Compose(T, bbox_params=A.BboxParams(=, label_fields=[]))\n\n            LOGGER.info(prefix + .join(.replace(, )  x  T  x.p))\n         ImportError:  \n            \n         Exception  e:\n            LOGGER.info()\n\nAlbumentations.__init__ = __init__\n</code></pre>",
      "votes": null,
      "replies": [
        {
          "id": 3185441,
          "author_name": "ravaghi",
          "author_url": "",
          "post_date": "04/23/2025 10:08:35",
          "content": "<p>Hacky, but it works! Thank you <a href=\"https://www.kaggle.com/andreizamfir\" target=\"_blank\">@andreizamfir</a>!</p>",
          "votes": null,
          "replies": [
            {
              "id": 3186172,
              "author_name": "ravaghi",
              "author_url": "",
              "post_date": "04/24/2025 09:56:32",
              "content": "<p>For newer versions:</p>\n<pre><code> ():\n    .p = p\n    .transform = \n    prefix = colorstr()\n\n    :\n        spatial_transforms = {\n            ,\n            ,\n            \n        }\n\n        T = [\n            A.HorizontalFlip(p=),\n            A.RandomRotate90(p=),\n            A.VerticalFlip(p=)\n        ]\n\n        .contains_spatial = (transform.__class__.__name__  spatial_transforms  transform  T)\n\n        .transform = (\n            A.Compose(T, bbox_params=A.BboxParams(=, label_fields=[]))\n             .contains_spatial\n             A.Compose(T)\n        )\n\n         (.transform, ):\n            .transform.set_random_seed(torch.initial_seed())\n\n        LOGGER.info(prefix + .join(.replace(, )  x  T  x.p))\n\n     Exception  e:\n        LOGGER.info()\n\nAlbumentations.__init__ = __init__\n</code></pre>",
              "votes": null,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 3186160,
      "author_name": "sangrampatil5150",
      "author_url": "",
      "post_date": "04/24/2025 09:33:56",
      "content": "<p>Full Discussion : <a href=\"https://github.com/ultralytics/ultralytics/issues/257\" target=\"_blank\">https://github.com/ultralytics/ultralytics/issues/257</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 3186398,
      "author_name": "mathieuduverne",
      "author_url": "",
      "post_date": "04/24/2025 15:43:55",
      "content": "<p>Have you tried to fine tune with this custom augmentations?<br>\nI recently used tune from yolo was too comput cost for me.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 3188089,
      "author_name": "achievement",
      "author_url": "",
      "post_date": "04/27/2025 03:28:22",
      "content": "<p>Thanks for your insight, that is right we can have full control over augmentations during our training this way.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 3188814,
      "author_name": "mohanapavanbezawada",
      "author_url": "",
      "post_date": "04/28/2025 08:46:53",
      "content": "<p>Thanks for your contribution </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 3189212,
      "author_name": "dataneed99",
      "author_url": "",
      "post_date": "04/29/2025 00:30:05",
      "content": "<p>Very informative 😃</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "3185309": "Is anyone else having a hard time understanding how augmentations work in Ultralytics? The documentation is not very clear, and most of the questions on GitHub regarding augmentation are answered by AI. I thought I'd write this post in case anyone else has faced the same problem, and has found some clever solution.\n\n### Disabling Augmentations\nFirst off, there doesn't seem to be any reliable way to disable augmentations. Setting `augment=False` in the `.train()` method doesn't seem to have any effect, nor does setting all augmentation parameters to 0. No matter which augmentation parameters I change, this line always appears in the logs:\n\n```bash\nalbumentations: Blur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01, blur_limit=(3, 7)), ToGray(p=0.01, num_output_channels=3, method='weighted_average'), CLAHE(p=0.01, clip_limit=(1.0, 4.0), tile_grid_size=(8, 8))\n```\nThe only way I've found to remove this line is by uninstalling albumentations.\n\n\n### Customizing Augmentations Provided by Ultralytics\nFrom what I understand, augmentations can be configured either via the YAML config file or by passing parameters directly to the `.train()` method. I've tried both approaches, but neither seems to work. Nothing I've done affects what is printed in the albumentations section of the logs. Either the augmentations I defined are being applied and not shown in the logs, or they're not being applied at all.\n\n\n### Custom Augmentations\nI've also struggled with implementing custom augmentations, as the options Ultralytics provides are quite limited. Based on [this discussion](https://github.com/ultralytics/ultralytics/issues/9192#issuecomment-2708507624), it seems there's no clean way to use custom augmentations other than modifying the source code. If anyone has found a better solution, I'd be grateful to hear about it.",
    "3185419": "You are correct with the conclusion that those albumentations are applied automatically unless you uninstall the library. Use this code snippet to create your own pipeline.\n\n```\nfrom ultralytics.data.augment import Albumentations\nfrom ultralytics.utils import LOGGER, colorstr\nimport albumentations as A\n\ndef __init__(self, p=1.0):\n        self.p = p\n        self.transform = None\n        prefix = colorstr(\"albumentations: \")\n        try:\n            import albumentations as A\n\n            # check_version(A.__version__, \"1.0.3\", hard=True)  # version requirement\n\n            # Transforms\n            T = [\n                A.RandomRotate90(p=0.8),\n                A.HorizontalFlip(p=0.5),\n                A.VerticalFlip(p=0.5),\n                A.Rotate(limit=15, p=0.3),\n            ]\n            self.transform = A.Compose(T, bbox_params=A.BboxParams(format=\"yolo\", label_fields=[\"class_labels\"]))\n\n            LOGGER.info(prefix + \", \".join(f\"{x}\".replace(\"always_apply=False, \", \"\") for x in T if x.p))\n        except ImportError:  # package not installed, skip\n            pass\n        except Exception as e:\n            LOGGER.info(f\"{prefix}{e}\")\n\nAlbumentations.__init__ = __init__\n```",
    "3185441": "Hacky, but it works! Thank you @andreizamfir!",
    "3186160": "Full Discussion : [https://github.com/ultralytics/ultralytics/issues/257](https://github.com/ultralytics/ultralytics/issues/257)",
    "3186172": "For newer versions:\n```python\ndef __init__(self, p=1.0):\n    self.p = p\n    self.transform = None\n    prefix = colorstr(\"albumentations: \")\n\n    try:\n        spatial_transforms = {\n            \"HorizontalFlip\",\n            \"RandomRotate90\",\n            \"VerticalFlip\"\n        }\n        \n        T = [\n            A.HorizontalFlip(p=0.3),\n            A.RandomRotate90(p=0.3),\n            A.VerticalFlip(p=0.3)\n        ]\n\n        self.contains_spatial = any(transform.__class__.__name__ in spatial_transforms for transform in T)\n        \n        self.transform = (\n            A.Compose(T, bbox_params=A.BboxParams(format=\"yolo\", label_fields=[\"class_labels\"]))\n            if self.contains_spatial\n            else A.Compose(T)\n        )\n        \n        if hasattr(self.transform, \"set_random_seed\"):\n            self.transform.set_random_seed(torch.initial_seed())\n        \n        LOGGER.info(prefix + \", \".join(f\"{x}\".replace(\"always_apply=False, \", \"\") for x in T if x.p))\n        \n    except Exception as e:\n        LOGGER.info(f\"{prefix}{e}\")\n\nAlbumentations.__init__ = __init__\n```",
    "3186398": "Have you tried to fine tune with this custom augmentations?\nI recently used tune from yolo was too comput cost for me.",
    "3188089": "Thanks for your insight, that is right we can have full control over augmentations during our training this way.",
    "3188814": "Thanks for your contribution",
    "3189212": "Very informative 😃"
  },
  "source": "meta"
}