{"id":10532,"date":"2022-11-22T11:41:46","date_gmt":"2022-11-22T03:41:46","guid":{"rendered":"http:\/\/139.9.1.231\/?p=10532"},"modified":"2022-11-22T11:50:13","modified_gmt":"2022-11-22T03:50:13","slug":"albumentations","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/11\/22\/albumentations\/","title":{"rendered":"albumentations \u6570\u636e\u589e\u5f3a\u5de5\u5177"},"content":{"rendered":"\n<h2>\u7b80\u4ecb &amp; \u5b89\u88c5<\/h2>\n\n\n\n<ul><li><a rel=\"noreferrer noopener\" href=\"https:\/\/albumentations.readthedocs.io\/en\/latest\/\" target=\"_blank\">\u5b98\u65b9\u6587\u6863 albumentations<\/a><\/li><li>\u53c2\u8003\uff1a<a href=\"https:\/\/zhuanlan.zhihu.com\/p\/107399127\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/zhuanlan.zhihu.com\/p\/107399127<\/a><\/li><\/ul>\n\n\n\n<p>albumentations \u662f\u4e00\u4e2a\u7ed9\u4e88 OpenCV\u7684\u5feb\u901f\u8bad\u7ec3\u6570\u636e\u589e\u5f3a\u5e93\uff0c\u62e5\u6709\u975e\u5e38\u7b80\u5355\u4e14\u5f3a\u5927\u7684\u53ef\u4ee5\u7528\u4e8e\u591a\u79cd\u4efb\u52a1\uff08\u5206\u5272\u3001\u68c0\u6d4b\uff09\u7684\u63a5\u53e3\uff0c\u6613\u4e8e\u5b9a\u5236\u4e14\u6dfb\u52a0\u5176\u4ed6\u6846\u67b6\u975e\u5e38\u65b9\u4fbf\u3002\u652f\u6301\u6240\u6709\u5e38\u89c1\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u4efb\u52a1\uff0c\u4f8b\u5982\u5206\u7c7b\uff0c\u8bed\u4e49\u5206\u5272\uff0c\u5b9e\u4f8b\u5206\u5272\uff0c\u5bf9\u8c61\u68c0\u6d4b\u548c\u59ff\u52bf\u4f30\u8ba1\u3002<\/p>\n\n\n\n<p class=\"has-bright-blue-background-color has-background\"><strong>albumentations<\/strong>\u5305\u662f\u4e00\u79cd\u9488\u5bf9\u6570\u636e\u589e\u5f3a\u4e13\u95e8\u5199\u7684API\uff0c\u91cc\u9762\u57fa\u672c\u5305\u542b\u5927\u91cf\u7684\u6570\u636e\u589e\u5f3a\u624b\u6bb5\uff0c\u5176\u7279\u70b9\uff1a<\/p>\n\n\n\n<p>1\u3001Albumentations\u652f\u6301\u6240\u6709\u5e38\u89c1\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u4efb\u52a1\uff0c<strong>\u5982\u5206\u7c7b\u3001\u8bed\u4e49\u5206\u5272\u3001\u5b9e\u4f8b\u5206\u5272\u3001\u76ee\u6807\u68c0\u6d4b\u548c\u59ff\u6001\u4f30\u8ba1<\/strong>\u3002<\/p>\n\n\n\n<p>2\u3001\u8be5\u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7b80\u5355\u7edf\u4e00\u7684API\uff0c\u7528\u4e8e\u5904\u7406\u6240\u6709\u6570\u636e\u7c7b\u578b:\u56fe\u50cf(rbg\u56fe\u50cf\u3001\u7070\u5ea6\u56fe\u50cf\u3001\u591a\u5149\u8c31\u56fe\u50cf)\u3001\u5206\u5272\u63a9\u7801\u3001\u8fb9\u754c\u6846\u548c\u5173\u952e\u70b9\u3002<\/p>\n\n\n\n<p>3\u3001<strong>\u8be5\u5e93\u5305\u542b70\u591a\u79cd\u4e0d\u540c\u7684\u589e\u5f3a\u529f\u80fd\uff0c\u53ef\u4ee5<\/strong>\u4ece\u73b0\u6709\u6570\u636e\u4e2d\u751f\u6210\u65b0\u7684\u8bad\u7ec3\u6837\u672c\u3002<\/p>\n\n\n\n<p>4\u3001Albumentations\u5feb\u3002\u6211\u4eec\u5bf9\u6bcf\u4e2a\u65b0\u7248\u672c\u8fdb\u884c\u57fa\u51c6\u6d4b\u8bd5\uff0c\u4ee5\u786e\u4fdd\u589e\u5f3a\u529f\u80fd\u63d0\u4f9b\u6700\u5927\u7684\u901f\u5ea6\u3002<\/p>\n\n\n\n<p>5\u3001\u5b83\u4e0e\u6d41\u884c\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6(\u5982PyTorch\u548cTensorFlow)\u4e00\u8d77\u5de5\u4f5c\u3002\u987a\u4fbf\u8bf4\u4e00\u4e0b\uff0cAlbumentations\u662fPyTorch\u751f\u6001\u7cfb\u7edf\u7684\u4e00\u90e8\u5206\u3002<\/p>\n\n\n\n<p>6\u3001\u7531\u4e13\u5bb6\u5199\u7684\u3002\u4f5c\u8005\u65e2\u6709\u751f\u4ea7\u8ba1\u7b97\u673a\u89c6\u89c9\u7cfb\u7edf\u7684\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u4e5f\u6709\u53c2\u4e0e\u7ade\u4e89\u6027\u673a\u5668\u5b66\u4e60\u7684\u7ecf\u9a8c\u3002\u8bb8\u591a\u6838\u5fc3\u56e2\u961f\u6210\u5458\u662fKaggle Masters\u548cGrandmasters\u3002<\/p>\n\n\n\n<p>7\u3001\u8be5\u5e93\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5de5\u4e1a\u3001\u6df1\u5ea6\u5b66\u4e60\u7814\u7a76\u3001\u673a\u5668\u5b66\u4e60\u7ade\u8d5b\u548c\u5f00\u6e90\u9879\u76ee\u3002<\/p>\n\n\n\n<p>github\u53ca\u5176\u793a\u4f8b\u5730\u5740\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul><li>GitHub\uff1a&nbsp;<a href=\"https:\/\/github.com\/albumentations-team\/albumentations\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/albumentations-team\/albumentations<\/a><\/li><li>\u793a\u4f8b\uff1a<a href=\"https:\/\/github.com\/albumentations-team\/albumentations_examples\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/albumentations-team\/albumentations_examples<\/a><\/li><\/ul>\n\n\n\n<p>\u53ef\u4ee5\u901a\u8fc7&nbsp;<code>pip<\/code>&nbsp;\u7684\u65b9\u5f0f\u76f4\u63a5\u5b89\u88c5\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7&nbsp;<code>pip + github<\/code>&nbsp;\u7684\u65b9\u5f0f\uff0c\u6216\u8005<code>conda<\/code>\uff1a<\/p>\n\n\n\n<ul><li>pip \u65b9\u5f0f\uff1a<code>pip install albumentations<\/code><\/li><li>pip + github\uff1a<code>pip install -U git+https:\/\/github.com\/albu\/albumentations<\/code><\/li><li>conda\u65b9\u5f0f\uff0c\u6b64\u65b9\u5f0f\u9700\u8981\u5148\u5b89\u88c5 imgaug\uff0c\u7136\u540e\u5728\u5b89\u88c5 albumentations<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>conda install -c conda-forge imgaug\nconda install albumentations -c albumentations\n<\/code><\/pre>\n\n\n\n<h5>\u5b89\u88c5\u95ee\u9898<\/h5>\n\n\n\n<p>\u5728\u5b89\u88c5\u90e8\u5206\u6709\u4e2a\u5c0f\u95ee\u9898\uff0c\u6211\u7684\u672c\u673a\u5df2\u7ecf\u5b89\u88c5\u5b8copencv-python\uff0c\u7136\u540e\u6211\u4eec\u518d\u53bb\u5b89\u88c5albumentations\u7684\u65f6\u5019\uff0c\u51fa\u73b0\u4e86\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u6211\u4eec\u7684opencv-python\u963b\u6b62albumentations\u7684\u5b89\u88c5\uff0c\u62a5\u9519\u5982\u4e0b\uff1a<code># Could not install packages due to anEnvironmentError: [WinError 5] \u62d2\u7edd\u8bbf\u95ee<\/code>\uff0c\u662f\u56e0\u4e3a\u5728\u5b89\u88c5albumentations\u7684\u65f6\u5019\u8fd8\u8981\u5b89\u88c5opencv-python-headless\uff0c\u8fd9\u4e2a\u5e93\u548copencv\u51b2\u7a81\u3002<\/p>\n\n\n\n<h5>\u89e3\u51b3\u65b9\u5f0f<\/h5>\n\n\n\n<p>\u5bf9\u4e8e\u8fd9\u4e2a\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u5f0f\u662f\u6211\u4eec\u5728\u65b0\u7684\u865a\u62df\u73af\u5883\u4e2d\uff0c\u5148\u5b89\u88c5albumentations\uff0c\u5b89\u88c5albumentations\u7684\u65f6\u5019\uff0c\u6211\u4eec\u4f1a\u4f34\u968f\u5b89\u88c5\u4e0a\u4e00\u4e2a<strong>opencv-python-headless<\/strong>\uff0c\u8fd9\u4e2a\u5b8c\u5168\u53ef\u4ee5\u66ff\u4ee3opencv-python\u7684\u529f\u80fd\uff0c\u6240\u4ee5\u6211\u4eec\u5c31\u4e0d\u7528\u5b89\u88c5opencv\u4e86\u3002<\/p>\n\n\n\n<h3>Spatial-level transforms\uff08\u7a7a\u95f4\u5c42\u6b21\u8f6c\u6362\uff09<\/h3>\n\n\n\n<p>\u7a7a\u95f4\u7ea7\u8f6c\u6362\u5c06\u540c\u65f6\u6539\u53d8\u8f93\u5165\u56fe\u50cf\u548c\u9644\u52a0\u76ee\u6807\uff0c\u5982\u63a9\u6a21\u3001\u8fb9\u754c\u6846\u548c\u5173\u952e\u70b9\u3002\u4e0b\u8868\u663e\u793a\u4e86\u6bcf\u4e2a\u8f6c\u6362\u652f\u6301\u54ea\u4e9b\u9644\u52a0\u76ee\u6807\u3002<\/p>\n\n\n\n<p>Spatial-level transforms\uff08\u7a7a\u95f4\u5c42\u6b21\u8f6c\u6362\uff09 \u7a7a\u95f4\u7ea7\u8f6c\u6362\u5c06\u540c\u65f6\u6539\u53d8\u8f93\u5165\u56fe\u50cf\u548c\u9644\u52a0\u76ee\u6807\uff0c\u5982\u63a9\u6a21\u3001\u8fb9\u754c\u6846\u548c\u5173\u952e\u70b9\u3002\u4e0b\u8868\u663e\u793a\u4e86\u6bcf\u4e2a\u8f6c\u6362\u652f\u6301\u54ea\u4e9b\u9644\u52a0\u76ee\u6807\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u652f\u6301\u7684\u5217\u8868\n\nBlur\nCLAHE\nChannelDropout\nChannelShuffle\nColorJitter\nDownscale\nEmboss\nEqualize\nFDA\nFancyPCA\nFromFloat\nGaussNoise\nGaussianBlur\nGlassBlur\nHistogramMatching\nHueSaturationValue\nISONoise\nImageCompression\nInvertImg\nMedianBlur\nMotionBlur\nMultiplicativeNoise\nNormalize\nPosterize\nRGBShift\nRandomBrightnessContrast\nRandomFog\nRandomGamma\nRandomRain\nRandomShadow\nRandomSnow\nRandomSunFlare\nRandomToneCurve\nSharpen\nSolarize\nSuperpixels\nToFloat\nToGray\nToSepia\n<\/code><\/pre>\n\n\n\n<p>how to use\uff1a\u7c7b\u4f3ctotch\u4e2d\u7684 transform  \u6a21\u5757<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\n \nimport matplotlib.pyplot as plt\n \n# Declare an augmentation pipeline\ntransform = A.Compose(&#91;\n    A.RandomCrop(width=512, height=512),\n    A.HorizontalFlip(p=0.8),\n    A.RandomBrightnessContrast(p=0.5),\n])\n \n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n \n# Augment an image\ntransformed = transform(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>\u8be6\u7ec6\u4f7f\u7528\u6848\u4f8b\uff1a<\/p>\n\n\n\n<p>1\u3001VerticalFlip \u56f4\u7ed5X\u8f74\u5782\u76f4\u7ffb\u8f6c\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n#\u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898\nplt.rcParams&#91;'font.sans-serif']=&#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n# Augment an image\ntransformed = A.VerticalFlip(always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')   #\u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title('Blur\u540e\u7684\u56fe\u50cf')\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>2\u3001Blur\u6a21\u7cca\u8f93\u5165\u56fe\u50cf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n#\u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898\nplt.rcParams&#91;'font.sans-serif']=&#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n# Augment an image\ntransformed = A.Blur(blur_limit=15,always_apply=False, p=1)(image=image) \ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')   #\u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title('Blur\u540e\u7684\u56fe\u50cf')\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>3\u3001HorizontalFlip \u56f4\u7ed5y\u8f74\u6c34\u5e73\u7ffb\u8f6c\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n#\u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898\nplt.rcParams&#91;'font.sans-serif']=&#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n# Augment an image\ntransformed = A.HorizontalFlip(always_apply=False, p=1)(image=image) \ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')   #\u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title('HorizontalFlip\u540e\u7684\u56fe\u50cf')\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>4\u3001Flip\u6c34\u5e73\uff0c\u5782\u76f4\u6216\u6c34\u5e73\u548c\u5782\u76f4\u7ffb\u8f6c\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n#\u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898\nplt.rcParams&#91;'font.sans-serif']=&#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n# Augment an image\ntransformed = A.Flip(always_apply=False, p=1)(image=image) \ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')   #\u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title('Flip\u540e\u7684\u56fe\u50cf')\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>5\u3001Transpose\uff0c \u901a\u8fc7\u4ea4\u6362\u884c\u548c\u5217\u6765\u8f6c\u7f6e\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n#\u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898\nplt.rcParams&#91;'font.sans-serif']=&#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n# Augment an image\ntransformed = A.Transpose(always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')   #\u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title('Transpose\u540e\u7684\u56fe\u50cf')\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>6\u3001RandomCrop&nbsp;\u968f\u673a\u88c1\u526a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n#\u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898\nplt.rcParams&#91;'font.sans-serif']=&#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n# Augment an image\ntransformed = A.RandomCrop(512, 512,always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')   #\u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title('RandomCrop\u540e\u7684\u56fe\u50cf')\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>7\u3001RandomGamma \u968f\u673a\u7070\u5ea6\u7cfb\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n#\u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898\nplt.rcParams&#91;'font.sans-serif']=&#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n# Augment an image\ntransformed = A.RandomGamma(gamma_limit=(20, 20), eps=None, always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')   #\u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title('RandomGamma\u540e\u7684\u56fe\u50cf')\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>8\u3001RandomRotate90 \u5c06\u8f93\u5165\u968f\u673a\u65cb\u8f6c90\u5ea6\uff0cN\u6b21<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n#\u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898\nplt.rcParams&#91;'font.sans-serif']=&#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n# Augment an image\ntransformed = A.RandomRotate90(always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')   #\u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title('RandomRotate90\u540e\u7684\u56fe\u50cf')\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>10\u3001ShiftScaleRotate \u968f\u673a\u5e73\u79fb\uff0c\u7f29\u653e\u548c\u65cb\u8f6c\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n#\u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898\nplt.rcParams&#91;'font.sans-serif']=&#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n# Augment an image\ntransformed = A.ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.1, rotate_limit=45, interpolation=1, border_mode=4, value=None, mask_value=None, always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')   #\u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title('ShiftScaleRotate\u540e\u7684\u56fe\u50cf')\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>11\u3001CenterCrop \u88c1\u526a\u56fe\u50cf\u7684\u4e2d\u5fc3\u90e8\u5206<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n<em># \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898<\/em>\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\nplt.rcParams&#91;'axes.unicode_minus'] = False\n<em># Read an image with OpenCV and convert it to the RGB colorspace<\/em>\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n<em># Augment an image<\/em>\ntransformed = A.CenterCrop(256, 256, always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  <em># \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898<\/em>\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"CenterCrop\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>12\u3001GridDistortion\u7f51\u683c\u5931\u771f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n \n# \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n# Augment an image\ntransformed = A.GridDistortion(num_steps=10, distort_limit=0.3,border_mode=4, always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  # \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"GridDistortion\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>13\u3001ElasticTransform \u5f39\u6027\u53d8\u6362<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n \n# \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n# Augment an image\ntransformed = A.ElasticTransform(alpha=5, sigma=50, alpha_affine=50, interpolation=1, border_mode=4,always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  # \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"ElasticTransform\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<p>14\u3001RandomGridShuffle\u628a\u56fe\u50cf\u5207\u6210\u7f51\u683c\u5355\u5143\u968f\u673a\u6392\u5217<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import albumentations as A\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\n \n# \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n# Read an image with OpenCV and convert it to the RGB colorspace\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n# Augment an image\ntransformed = A.RandomGridShuffle(grid=(3, 3), always_apply=False, p=1) (image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  # \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"RandomGridShuffle\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<h4>15\u3001HueSaturationValue\u968f\u673a\u66f4\u6539\u56fe\u50cf\u7684\u989c\u8272\uff0c\u9971\u548c\u5ea6\u548c\u503c<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import<\/strong> albumentations <strong>as<\/strong> A\n<strong>import<\/strong> cv2\n<strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> matplotlib.pyplot <strong>as<\/strong> plt\n \n<em># \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898<\/em>\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n<em># Read an image with OpenCV and convert it to the RGB colorspace<\/em>\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n<em># Augment an image<\/em>\ntransformed = A.HueSaturationValue(hue_shift_limit=20, sat_shift_limit=30, val_shift_limit=20, always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  <em># \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898<\/em>\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"HueSaturationValue\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<h4>16\u3001PadIfNeeded \u586b\u5145\u56fe\u50cf<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import<\/strong> albumentations <strong>as<\/strong> A\n<strong>import<\/strong> cv2\n<strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> matplotlib.pyplot <strong>as<\/strong> plt\n \n<em># \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898<\/em>\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n<em># Read an image with OpenCV and convert it to the RGB colorspace<\/em>\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n<em># Augment an image<\/em>\ntransformed = A.PadIfNeeded(min_height=2048, min_width=2048, border_mode=4, always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  <em># \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898<\/em>\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"PadIfNeeded\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<h4>17\u3001RGBShift\uff0c\u5bf9\u56fe\u50cfRGB\u7684\u6bcf\u4e2a\u901a\u9053\u968f\u673a\u79fb\u52a8\u503c<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import<\/strong> albumentations <strong>as<\/strong> A\n<strong>import<\/strong> cv2\n<strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> matplotlib.pyplot <strong>as<\/strong> plt\n \n<em># \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898<\/em>\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n<em># Read an image with OpenCV and convert it to the RGB colorspace<\/em>\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n<em># Augment an image<\/em>\ntransformed = A.RGBShift(r_shift_limit=10, g_shift_limit=20, b_shift_limit=20, always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  <em># \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898<\/em>\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"RGBShift\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<h4>18\u3001GaussianBlur \u4f7f\u7528\u968f\u673a\u6838\u5927\u5c0f\u7684\u9ad8\u65af\u6ee4\u6ce2\u5668\u5bf9\u56fe\u50cf\u8fdb\u884c\u6a21\u7cca\u5904\u7406<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import<\/strong> albumentations <strong>as<\/strong> A\n<strong>import<\/strong> cv2\n<strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> matplotlib.pyplot <strong>as<\/strong> plt\n \n<em># \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898<\/em>\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n<em># Read an image with OpenCV and convert it to the RGB colorspace<\/em>\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n<em># Augment an image<\/em>\ntransformed = A.GaussianBlur(blur_limit=11, always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  <em># \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898<\/em>\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"GaussianBlur\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<h4>CLAHE\u81ea\u9002\u5e94\u76f4\u65b9\u56fe\u5747\u8861<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import<\/strong> albumentations <strong>as<\/strong> A\n<strong>import<\/strong> cv2\n<strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> matplotlib.pyplot <strong>as<\/strong> plt\n \n<em># \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898<\/em>\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n<em># Read an image with OpenCV and convert it to the RGB colorspace<\/em>\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n<em># Augment an image<\/em>\ntransformed = A.CLAHE(clip_limit=4.0, tile_grid_size=(8, 8), always_apply=False, p=0.5)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  <em># \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898<\/em>\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"CLAHE\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<h4>ChannelShuffle\u968f\u673a\u91cd\u65b0\u6392\u5217\u8f93\u5165RGB\u56fe\u50cf\u7684\u901a\u9053<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import<\/strong> albumentations <strong>as<\/strong> A\n<strong>import<\/strong> cv2\n<strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> matplotlib.pyplot <strong>as<\/strong> plt\n \n<em># \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898<\/em>\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n<em># Read an image with OpenCV and convert it to the RGB colorspace<\/em>\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n<em># Augment an image<\/em>\ntransformed = A.ChannelShuffle(always_apply=False, p=0.5)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  <em># \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898<\/em>\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"ChannelShuffle\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<h4>InvertImg\u53cd\u8272<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import<\/strong> albumentations <strong>as<\/strong> A\n<strong>import<\/strong> cv2\n<strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> matplotlib.pyplot <strong>as<\/strong> plt\n \n<em># \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898<\/em>\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n<em># Read an image with OpenCV and convert it to the RGB colorspace<\/em>\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n<em># Augment an image<\/em>\ntransformed = A.InvertImg(always_apply=False, p=0.5)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  <em># \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898<\/em>\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"InvertImg\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()\n<\/code><\/pre>\n\n\n\n<h4>Cutout \u968f\u673a\u64e6\u9664<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import<\/strong> albumentations <strong>as<\/strong> A\n<strong>import<\/strong> cv2\n<strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> matplotlib.pyplot <strong>as<\/strong> plt\n \n<em># \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898<\/em>\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n<em># Read an image with OpenCV and convert it to the RGB colorspace<\/em>\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n<em># Augment an image<\/em>\ntransformed = A.Cutout(num_holes=20, max_h_size=20, max_w_size=20, fill_value=0, always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  <em># \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898<\/em>\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"Cutout\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<h4>RandomFog\u968f\u673a\u96fe\u5316<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import<\/strong> albumentations <strong>as<\/strong> A\n<strong>import<\/strong> cv2\n<strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> matplotlib.pyplot <strong>as<\/strong> plt\n \n<em># \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898<\/em>\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n<em># Read an image with OpenCV and convert it to the RGB colorspace<\/em>\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n<em># Augment an image<\/em>\ntransformed = A.RandomFog(fog_coef_lower=0.3, fog_coef_upper=1, alpha_coef=0.08, always_apply=False, p=1)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  <em># \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898<\/em>\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"RandomFog\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<h4>GridDropout\u7f51\u683c\u64e6\u9664<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import<\/strong> albumentations <strong>as<\/strong> A\n<strong>import<\/strong> cv2\n<strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> matplotlib.pyplot <strong>as<\/strong> plt\n \n<em># \u89e3\u51b3\u4e2d\u6587\u663e\u793a\u95ee\u9898<\/em>\nplt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']\nplt.rcParams&#91;'axes.unicode_minus'] = False\n<em># Read an image with OpenCV and convert it to the RGB colorspace<\/em>\nimage = cv2.imread(\"aa.jpg\")\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n<em># Augment an image<\/em>\ntransformed = A.GridDropout(ratio=0.5, unit_size_min=None, unit_size_max=None, holes_number_x=None, holes_number_y=None,\n                            shift_x=0, shift_y=0, always_apply=False, p=0.5)(image=image)\ntransformed_image = transformed&#91;\"image\"]\nplt.subplot(1, 2, 1)\nplt.title('\u539f\u56fe')  <em># \u7b2c\u4e00\u5e45\u56fe\u7247\u6807\u9898<\/em>\nplt.imshow(image)\nplt.subplot(1, 2, 2)\nplt.title(\"GridDropout\u540e\u7684\u56fe\u50cf\")\nplt.imshow(transformed_image)\nplt.show()<\/code><\/pre>\n\n\n\n<h3><code>\u7ec4\u5408\u53d8\u6362\uff08Compose\uff09<\/code><\/h3>\n\n\n\n<p>\u53d8\u6362\u4e0d\u4ec5\u53ef\u4ee5\u5355\u72ec\u4f7f\u7528\uff0c\u8fd8\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u7ec4\u5408\u8d77\u6765\uff0c\u8fd9\u5c31\u9700\u8981\u7528\u5230 Compose \u7c7b\uff0c\u8be5\u7c7b\u7ee7\u627f\u81ea BaseCompose\u3002Compose \u7c7b\u542b\u6709\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul><li>transforms\uff1a\u8f6c\u6362\u7c7b\u7684\u6570\u7ec4\uff0clist\u7c7b\u578b<\/li><li>bbox_params\uff1a\u7528\u4e8e bounding boxes \u8f6c\u6362\u7684\u53c2\u6570\uff0cBboxPoarams \u7c7b\u578b<\/li><li>keypoint_params\uff1a\u7528\u4e8e keypoints \u8f6c\u6362\u7684\u53c2\u6570\uff0c KeypointParams \u7c7b\u578b<\/li><li>additional_targets\uff1akey\u65b0target \u540d\u5b57\uff0cvalue \u4e3a\u65e7 target \u540d\u5b57\u7684 dict\uff0c\u5982 {&#8216;image2&#8217;: &#8216;image&#8217;}\uff0cdict \u7c7b\u578b<\/li><li>p\uff1a\u4f7f\u7528\u8fd9\u4e9b\u53d8\u6362\u7684\u6982\u7387\uff0c\u9ed8\u8ba4\u503c\u4e3a 1.0<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>image3 = Compose(&#91;\n        <em># \u5bf9\u6bd4\u5ea6\u53d7\u9650\u76f4\u65b9\u56fe\u5747\u8861<\/em>\n            <em>#\uff08Contrast Limited Adaptive Histogram Equalization\uff09<\/em>\n        CLAHE(),\n        <em># \u968f\u673a\u65cb\u8f6c 90\u00b0<\/em>\n        RandomRotate90(),\n        <em># \u8f6c\u7f6e<\/em>\n        Transpose(),\n        <em># \u968f\u673a\u4eff\u5c04\u53d8\u6362<\/em>\n        ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.50, rotate_limit=45, p=.75),\n        <em># \u6a21\u7cca<\/em>\n        Blur(blur_limit=3),\n        <em># \u5149\u5b66\u7578\u53d8<\/em>\n        OpticalDistortion(),\n        <em># \u7f51\u683c\u7578\u53d8<\/em>\n        GridDistortion(),\n        <em># \u968f\u673a\u6539\u53d8\u56fe\u7247\u7684 HUE\u3001\u9971\u548c\u5ea6\u548c\u503c<\/em>\n        HueSaturationValue()\n    ], p=1.0)(image=image)&#91;'image']<\/code><\/pre>\n\n\n\n<h4>\u968f\u673a\u9009\u62e9\uff08OneOf\uff09<\/h4>\n\n\n\n<p>\u5b83\u540cCompose\u4e00\u6837\uff0c\u90fd\u662f\u505a\u7ec4\u5408\u7684\uff0c\u90fd\u6709\u6982\u7387\u3002\u533a\u522b\u5c31\u5728\u4e8e\uff1a<strong>Compose\u7ec4\u5408\u4e0b\u7684\u53d8\u6362\u662f\u8981\u6328\u7740\u987a\u5e8f\u505a\u7684\uff0c\u800cOneOf\u7ec4\u5408\u91cc\u9762\u7684\u53d8\u6362\u662f\u7cfb\u7edf\u81ea\u52a8\u9009\u62e9\u5176\u4e2d\u4e00\u4e2a\u6765\u505a\uff0c\u800c\u8fd9\u91cc\u7684\u6982\u7387\u53c2\u6570p\u662f\u6307\u9009\u5b9a\u540e\u7684\u53d8\u6362\u88ab\u505a\u7684\u6982\u7387\u3002\u4f8b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>image4 = Compose(&#91;\n        RandomRotate90(),\n        <em># \u7ffb\u8f6c<\/em>\n        Flip(),\n        Transpose(),\n        OneOf(&#91;\n            <em># \u9ad8\u65af\u566a\u70b9<\/em>\n            IAAAdditiveGaussianNoise(),\n            GaussNoise(),\n        ], p=0.2),\n        OneOf(&#91;\n            <em># \u6a21\u7cca\u76f8\u5173\u64cd\u4f5c<\/em>\n            MotionBlur(p=.2),\n            MedianBlur(blur_limit=3, p=0.1),\n            Blur(blur_limit=3, p=0.1),\n        ], p=0.2),\n        ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.2, rotate_limit=45, p=0.2),\n        OneOf(&#91;\n            <em># \u7578\u53d8\u76f8\u5173\u64cd\u4f5c<\/em>\n            OpticalDistortion(p=0.3),\n            GridDistortion(p=.1),\n            IAAPiecewiseAffine(p=0.3),\n        ], p=0.2),\n        OneOf(&#91;\n            <em># \u9510\u5316\u3001\u6d6e\u96d5\u7b49\u64cd\u4f5c<\/em>\n            CLAHE(clip_limit=2),\n            IAASharpen(),\n            IAAEmboss(),\n            RandomBrightnessContrast(),            \n        ], p=0.3),\n        HueSaturationValue(p=0.3),\n    ], p=1.0)(image=image)&#91;'image']<\/code><\/pre>\n\n\n\n<h3>\u5728\u7a0b\u5e8f\u4e2d\u7684\u4f7f\u7528<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>def<\/strong> <strong>get_transform<\/strong>(phase: str):\n    <strong>if<\/strong> phase == 'train':\n        <strong>return<\/strong> Compose(&#91;\n            A.RandomResizedCrop(height=CFG.img_size, width=CFG.img_size),\n            A.Flip(p=0.5),\n            A.RandomRotate90(p=0.5),\n            A.ShiftScaleRotate(p=0.5),\n            A.HueSaturationValue(p=0.5),\n            A.OneOf(&#91;\n                A.RandomBrightnessContrast(p=0.5),\n                A.RandomGamma(p=0.5),\n            ], p=0.5),\n            A.OneOf(&#91;\n                A.Blur(p=0.1),\n                A.GaussianBlur(p=0.1),\n                A.MotionBlur(p=0.1),\n            ], p=0.1),\n            A.OneOf(&#91;\n                A.GaussNoise(p=0.1),\n                A.ISONoise(p=0.1),\n                A.GridDropout(ratio=0.5, p=0.2),\n                A.CoarseDropout(max_holes=16, min_holes=8, max_height=16, max_width=16, min_height=8, min_width=8, p=0.2)\n            ], p=0.2),\n            A.Normalize(\n                mean=&#91;0.485, 0.456, 0.406],\n                std=&#91;0.229, 0.224, 0.225],\n            ),\n            ToTensorV2(),\n        ])\n    <strong>else<\/strong>:\n        <strong>return<\/strong> Compose(&#91;\n            A.Resize(height=CFG.img_size, width=CFG.img_size),\n            A.Normalize(\n                mean=&#91;0.485, 0.456, 0.406],\n                std=&#91;0.229, 0.224, 0.225],\n            ),\n            ToTensorV2(),\n        ])<\/code><\/pre>\n\n\n\n<h2>\u5206\u7c7b\u95ee\u9898\u4e2d\u7684\u4f7f\u7528<\/h2>\n\n\n\n<p>\u5728 albumentations \u4e2d\u53ef\u4ee5\u7528\u4e8e\u5206\u7c7b\u95ee\u9898\u4e2d\u7684\u64cd\u4f5c\u5305\u62ec\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HorizontalFlip, IAAPerspective, ShiftScaleRotate, CLAHE, RandomRotate90,\r\nTranspose, ShiftScaleRotate, Blur, OpticalDistortion, GridDistortion, HueSaturationValue, IAAAdditiveGaussianNoise, GaussNoise, MotionBlur, MedianBlur, RandomBrightnessContrast, IAAPiecewiseAffine, IAASharpen, IAAEmboss, Flip, OneOf, Compose<\/code><\/pre>\n\n\n\n<h2>\u5206\u5272\u95ee\u9898\u4e2d\u7684\u4f7f\u7528<\/h2>\n\n\n\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u9700\u8981\u4f7f\u7528\u5230\u5982\u4e0b\u7684\u7c7b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PadIfNeeded, HorizontalFlip, VerticalFlip, CenterCrop, Crop, Compose, Transpose, RandomRotate90, ElasticTransform, GridDistortion, OpticalDistortion, RandomSizedCrop, OneOf, CLAHE, RandomBrightnessContrast, RandomGamma<\/code><\/pre>\n\n\n\n<h2>\u586b\u5145\uff08Padding\uff09<\/h2>\n\n\n\n<p>\u5728&nbsp;<code>Unet<\/code>&nbsp;\u8fd9\u6837\u7684\u7f51\u7edc\u67b6\u6784\u4e2d\uff0c\u8f93\u5165\u56fe\u7247\u7684\u5c3a\u5bf8\u9700\u8981\u5c3a\u5bf8\u9700\u8981\u80fd\u88ab $2^N$ \u6574\u9664\uff0c\u5176\u4e2d $N$ \u662f\u6c60\u5316\u5c42\uff08maxpooling\uff09\u7684\u5c42\u6570\u3002\u5728\u6700\u7b80\u5355\u7684&nbsp;<code>Unet<\/code>&nbsp;\u7ed3\u6784\u4e2d $N$ \u7684\u503c\u4e3a 5\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u9700\u8981\u5c06\u8f93\u5165\u7684\u56fe\u7247\u586b\u5145\u5230\u80fd\u88ab $2^5=32$ \u9664\u5c3d\u7684\u6570\u5b57\uff0c\u5e94\u8be5\u4e0a\u9762\u56fe\u7247\u7684\u5927\u5c0f\u4e3a 101\uff0c\u56e0\u6b64\u6700\u63a5\u8fd1\u7684\u5927\u5c0f\u4e3a 128\u3002\u8981\u8fdb\u884c\u6b64\u64cd\u4f5c\u5c31\u9700\u8981\u7528\u5230&nbsp;<code>PadIfNeeded<\/code>&nbsp;\u7c7b\uff0c\u5176\u542b\u6709\u5982\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul><li><code>min_height<\/code>\uff1a\u6700\u7ec8\u56fe\u7247\u7684\u6700\u5c0f\u9ad8\u5ea6\uff0cint \u7c7b\u578b<\/li><li><code>min_width<\/code>\uff1a\u6700\u7ec8\u56fe\u7247\u7684\u6700\u5c0f\u5bbd\u5ea6\uff0cint \u7c7b\u578b<\/li><li><code>border_mode<\/code>\uff1aOpenCV \u8fb9\u754c\u6a21\u5f0f\uff0c\u9ed8\u8ba4\u503c\u4e3a&nbsp;<code>cv2.BORDER_REFLECT_101<\/code><\/li><li><code>value<\/code>\uff1a\u5982\u679c<code>border_mode<\/code>&nbsp;\u503c\u4e3a&nbsp;<code>cv2.BORDER_CONSTANT<\/code>&nbsp;\u65f6\u7684\u586b\u5145\u503c\uff0cint\u3001float\u6216\u8005 int\u3001float\u6570\u7ec4\u7c7b\u578b<\/li><li><code>mask_value<\/code>\uff1a\u5982\u679c<code>border_mode<\/code>&nbsp;\u503c\u4e3a&nbsp;<code>cv2.BORDER_CONSTANT<\/code>&nbsp;\u65f6 mask \u7684\u586b\u5145\u503c\uff0cint\u3001float\u6216\u8005 int\u3001float\u6570\u7ec4\u7c7b\u578b<\/li><li><code>p<\/code>\uff1a\u8fdb\u884c\u6b64\u8f6c\u6362\u7684\u6982\u7387\uff0c\u9ed8\u8ba4\u503c\u4e3a 1.0<\/li><\/ul>\n\n\n\n<p>\u9ed8\u8ba4\u6761\u4ef6\u4e0b&nbsp;<code>PadIfNeeded<\/code>&nbsp;\u4f1a\u5bf9\u56fe\u7247\u548cmask\u7684\u56db\u6761\u8fb9\u90fd\u8fdb\u884c\u586b\u5145\uff0c\u586b\u5145\u7684\u7c7b\u578b\u5305\u62ec\u96f6\u586b\u5145\uff08zero\uff09\u3001\u5e38\u91cf\u586b\u5145\uff08constant\uff09\u548c\u53cd\u5c04\u586b\u5145\uff08reflection\uff09\uff0c\u9ed8\u8ba4\u4e3a\u53cd\u5c04\u586b\u5145\u3002\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>image1 = PadIfNeeded(p=1, min_height=128, min_width=128)(image=image, mask=mask)\nimage11_padded = image1&#91;'image']\nmask11_padded = image1&#91;'mask']\n<em># (128, 128, 3) (128, 128)<\/em>\nprint(image11_padded.shape, mask11_padded.shape)<\/code><\/pre>\n\n\n\n<h2>\u88c1\u526a\u4e0e\u4e2d\u5fc3\u88c1\u526a\uff08Crop &amp; CenterCrop\uff09<\/h2>\n\n\n\n<p>\u4e0a\u9762\u6211\u4eec\u4f7f\u7528\u4e86&nbsp;<code>PadIfNeeded<\/code>&nbsp;\u5bf9\u56fe\u7247\u8fdb\u884c\u4e86\u586b\u5145\uff0c\u60f3\u8981\u6062\u590d\u539f\u59cb\u7684\u5927\u5c0f\u8fd9\u65f6\u5019\u5c31\u53ef\u4ee5\u4f7f\u7528\u76f8\u5173\u7684\u88c1\u526a\u65b9\u6cd5\uff1a<code>CenterCrop<\/code>\u3001<code>Crop<\/code>&nbsp;\u7b49\u7c7b\u3002<\/p>\n\n\n\n<p>\u5148\u6765\u770b&nbsp;<code>CenterCrop<\/code>&nbsp;\u7684\u4f7f\u7528\uff0c\u5b83\u4e3b\u8981\u4ece\u8f93\u5165\u7684\u56fe\u7247\u4e2d\u95f4\u8fdb\u884c\u88c1\u526a\uff0c\u4e3b\u8981\u542b\u6709\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul><li><code>height<\/code>\uff1a\u88c1\u526a\u7684\u9ad8\u5ea6\uff0cint \u7c7b\u578b<\/li><li><code>width<\/code>\uff1a\u88c1\u526a\u7684\u5bbd\u5ea6\uff0cint \u7c7b\u578b<\/li><li><code>p<\/code>\uff1a\u4f7f\u7528\u6b64\u8f6c\u6362\u65b9\u6cd5\u7684\u6982\u7387\uff0c\u9ed8\u8ba4\u503c\u4e3a 1.0<\/li><\/ul>\n\n\n\n<p>\u539f\u59cb\u7684\u56fe\u7247\u548cmask\u5927\u5c0f\u4e3a 101\uff0c\u56e0\u6b64\u6b64\u5904\u8bbe\u7f6e\u9700\u8981\u88c1\u526a\u7684\u5bbd\u9ad8\uff08original_height\/original_width\uff09\u4e3a 101\uff0c\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>image2 = CenterCrop(p=1.0, height=original_height, \n                    width=original_width)(image=image11_padded, mask=mask11_padded)\n\nimage22_center_cropped = image2&#91;'image']\nmask22_center_cropped = image2&#91;'mask']\n<em># (101, 101, 3) (101, 101)<\/em>\nprint(image22_center_cropped.shape, mask22_center_cropped.shape)<\/code><\/pre>\n\n\n\n<h2>\u975e\u7834\u574f\u6027\u8f6c\u6362<\/h2>\n\n\n\n<p>\u4ece\u4e0a\u9762\u7684\u8f6c\u6362\u64cd\u4f5c\u4e2d\u53ef\u4ee5\u770b\u5230\u64cd\u4f5c\u7834\u574f\u4e86\u56fe\u50cf\u7684\u7a7a\u95f4\u4fe1\u606f\uff0c\u5bf9\u4e8e\u60f3\u536b\u661f\u3001\u822a\u7a7a\u6216\u8005\u533b\u5b66\u56fe\u7247\u6211\u4eec\u5e76\u4e0d\u5e0c\u671b\u7834\u574f\u5b83\u539f\u6709\u7684\u7a7a\u95f4\u7ed3\u6784\uff0c\u5982\u4ee5\u4e0b\u7684\u516b\u79cd\u64cd\u4f5c\u5c31\u4e0d\u4f1a\u7834\u574f\u539f\u6709\u56fe\u7247\u7684\u7a7a\u95f4\u7ed3\u6784\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/pic3.zhimg.com\/v2-510d4aa24f963fee263f773028e6f252_r.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u901a\u8fc7&nbsp;<a href=\"https:\/\/albumentations.readthedocs.io\/en\/latest\/api\/augmentations.html#albumentations.augmentations.transforms.HorizontalFlip\" target=\"_blank\" rel=\"noreferrer noopener\">HorizontalFlip<\/a>,&nbsp;<a href=\"https:\/\/albumentations.readthedocs.io\/en\/latest\/api\/augmentations.html#albumentations.augmentations.transforms.VerticalFlip\" target=\"_blank\" rel=\"noreferrer noopener\">VerticalFlip<\/a>,&nbsp;<a href=\"https:\/\/albumentations.readthedocs.io\/en\/latest\/api\/augmentations.html#albumentations.augmentations.transforms.Transpose\" target=\"_blank\" rel=\"noreferrer noopener\">Transpose<\/a>,&nbsp;<a href=\"https:\/\/albumentations.readthedocs.io\/en\/latest\/api\/augmentations.html#albumentations.augmentations.transforms.RandomRotate90\" target=\"_blank\" rel=\"noreferrer noopener\">RandomRotate90<\/a>&nbsp;\u56db\u79cd\u64cd\u4f5c\u7684\u7ec4\u5408\u5c31\u53ef\u4ee5\u5f97\u5230\u4e0a\u9762\u7684\u516b\u79cd\u64cd\u4f5c\u3002\u8fd9\u4e9b\u64cd\u4f5c\u53ef\u4ee5\u53c2\u8003\u4e0a\u9762\u300a\u5206\u7c7b\u95ee\u9898\u4e2d\u7684\u4f7f\u7528\u300b\u7ae0\u8282\u3002<\/p>\n\n\n\n<h2>\u975e\u521a\u4f53\u8f6c\u6362<\/h2>\n\n\n\n<p>\u5728\u533b\u5b66\u5f71\u50cf\u95ee\u9898\u4e2d\u975e\u521a\u4f53\u88c5\u6362\u53ef\u4ee5\u5e2e\u52a9\u589e\u5f3a\u6570\u636e\u3002albumentations \u4e2d\u4e3b\u8981\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u51e0\u79cd\u975e\u521a\u4f53\u53d8\u6362\u7c7b\uff1a<code>ElasticTransform<\/code>\u3001<code>GridDistortion<\/code>&nbsp;\u548c&nbsp;<code>OpticalDistortion<\/code>\u3002\u4e09\u4e2a\u7c7b\u7684\u4e3b\u8981\u53c2\u6570\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>ElasticTransform \u7c7b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul><li><code>alpha<\/code>\u3001<code>sigma<\/code>\uff1a\u9ad8\u65af\u8fc7\u6ee4\u53c2\u6570\uff0cfloat\u7c7b\u578b<\/li><li><code>alpha_affine<\/code>\uff1a\u8303\u56f4\u4e3a (-alpha_affine, alpha_affine)\uff0cfloat \u7c7b\u578b<\/li><li><code>interpolation<\/code>\u3001<code>border_mode<\/code>\u3001<code>value<\/code>\u3001<code>mask_value<\/code>\uff1a\u4e0e\u5176\u4ed6\u7c7b\u542b\u4e49\u4e00\u6837<\/li><li><code>approximate<\/code>\uff1a\u662f\u5426\u5e94\u5e73\u6ed1\u5177\u6709\u56fa\u5b9a\u5927\u5c0f\u6838\u7684\u66ff\u6362\u6620\u5c04\uff08displacement map\uff09\uff0c\u82e5\u542f\u7528\u6b64\u9009\u9879\uff0c\u5728\u5927\u56fe\u4e0a\u4f1a\u6709\u4e24\u500d\u7684\u901f\u5ea6\u63d0\u5347\uff0cboolean\u7c7b\u578b\u3002<\/li><li><code>p<\/code>\uff1a\u4f7f\u7528\u6b64\u8f6c\u6362\u7684\u6982\u7387\uff0c\u9ed8\u8ba4\u503c\u4e3a 0.5<\/li><\/ul>\n\n\n\n<p>GridDistortion \u7c7b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul><li><code>num_steps<\/code>\uff1a\u5728\u6bcf\u4e00\u6761\u8fb9\u4e0a\u7f51\u683c\u5355\u5143\u7684\u6570\u91cf\uff0c\u9ed8\u8ba4\u503c\u4e3a 5\uff0cint \u7c7b\u578b<\/li><li><code>distort_limit<\/code>\uff1a\u5982\u679c\u662f\u5355\u503c\uff0c\u90a3\u4e48\u4f1a\u88ab\u8f6c\u6210 (-distort_limit, distort_limit)\uff0c\u9ed8\u8ba4\u503c\u4e3a (-0.03, 0.03)\uff0cfloat\u6216float\u6570\u7ec4\u7c7b\u578b<\/li><li><code>interpolation<\/code>\u3001<code>border_mode<\/code>\u3001<code>value<\/code>\u3001<code>mask_value<\/code>\uff1a\u4e0e\u5176\u4ed6\u7c7b\u542b\u4e49\u4e00\u6837<\/li><li><code>p<\/code>\uff1a\u4f7f\u7528\u6b64\u8f6c\u6362\u7684\u6982\u7387\uff0c\u9ed8\u8ba4\u503c\u4e3a 0.5<\/li><\/ul>\n\n\n\n<p>OpticalDistortion \u7c7b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul><li><code>distort_limit<\/code>\uff1a\u5982\u679c\u662f\u5355\u503c\uff0c\u90a3\u4e48\u4f1a\u88ab\u8f6c\u6210 (-distort_limit, distort_limit)\uff0c\u9ed8\u8ba4\u503c\u4e3a (-0.05, 0.05)\uff0cfloat\u6216float\u6570\u7ec4\u7c7b\u578b<\/li><li><code>shift_limit<\/code>\uff1a\u5982\u679c\u662f\u5355\u503c\uff0c\u90a3\u4e48\u4f1a\u88ab\u8f6c\u6210 (-shift_limit, shift_limit)\uff0c\u9ed8\u8ba4\u503c\u4e3a (-0.05, 0.05)\uff0cfloat\u6216float\u6570\u7ec4\u7c7b\u578b<\/li><li><code>interpolation<\/code>\u3001<code>border_mode<\/code>\u3001<code>value<\/code>\u3001<code>mask_value<\/code>\uff1a\u4e0e\u5176\u4ed6\u7c7b\u542b\u4e49\u4e00\u6837<\/li><li><code>p<\/code>\uff1a\u4f7f\u7528\u6b64\u8f6c\u6362\u7684\u6982\u7387\uff0c\u9ed8\u8ba4\u503c\u4e3a 0.5<\/li><\/ul>\n\n\n\n<p>\u4f7f\u7528\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em># \u5f39\u6027\u88c5\u6362<\/em>\nimage41 = ElasticTransform(p=1, alpha=120, sigma=120 * 0.05, \n                          alpha_affine=120 * 0.03)(image=image, mask=mask)\nimage_elastic = image41&#91;'image']\nmask_elastic = image41&#91;'mask']\n\n<em># \u7f51\u683c\u7578\u53d8<\/em>\nimage42 = GridDistortion(p=1, num_steps=10)(image=image, mask=mask)\n\nimage_grid = image42&#91;'image']\nmask_grid = image42&#91;'mask']\n\n<em># \u5149\u5b66\u7578\u53d8<\/em>\nimage43 = OpticalDistortion(p=1, distort_limit=2, shift_limit=0.5)(image=image, mask=mask)\n\nimage_optical = image43&#91;'image']\nmask_optical = image43&#91;'mask']<\/code><\/pre>\n\n\n\n<p>\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/pic3.zhimg.com\/v2-383c12a1d43c121a2e34578b0b37e07a_r.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u7ec4\u5408\u591a\u79cd\u8f6c\u6362<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u5c06\u4e0a\u9762\u7684\u586b\u5145\u3001\u88c1\u526a\u3001\u975e\u521a\u4f53\u8f6c\u6362\u3001\u975e\u7834\u574f\u6027\u8f6c\u6362\u7ec4\u5408\u8d77\u6765\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>image5 = Compose(&#91;\n   <em># \u975e\u521a\u4f53\u8f6c\u6362<\/em>\n    OneOf(&#91;RandomSizedCrop(min_max_height=(50, 101), \n                           height=original_height, width=original_width, p=0.5),\n          PadIfNeeded(min_height=original_height, \n                      min_width=original_width, p=0.5)], p=1),\n    <em># \u975e\u7834\u574f\u6027\u8f6c\u6362<\/em>\n    VerticalFlip(p=0.5),              \n    RandomRotate90(p=0.5),\n    <em># \u975e\u521a\u4f53\u8f6c\u6362<\/em>\n    OneOf(&#91;\n        ElasticTransform(p=0.5, alpha=120, sigma=120 * 0.05, alpha_affine=120 * 0.03),\n        GridDistortion(p=0.5),\n        OpticalDistortion(p=1, distort_limit=2, shift_limit=0.5)                  \n        ], p=0.8),\n    <em># \u975e\u7a7a\u95f4\u6027\u8f6c\u6362<\/em>\n    CLAHE(p=0.8),\n    RandomBrightnessContrast(p=0.8),    \n    RandomGamma(p=0.8)])(image=image, mask=mask)\n\nimage_heavy = image5&#91;'image']\nmask_heavy = image5&#91;'mask']<\/code><\/pre>\n\n\n\n<p>\u8fd0\u884c\u7684\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/pic3.zhimg.com\/v2-12e5dbafd7f6fd3c1824899f3dea42fa_r.jpg\" alt=\"\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb &amp; \u5b89\u88c5 \u5b98\u65b9\u6587\u6863 albumentations \u53c2\u8003\uff1ahttps:\/\/zhuanlan.zhi &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/11\/22\/albumentations\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">albumentations \u6570\u636e\u589e\u5f3a\u5de5\u5177<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,11],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/10532"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=10532"}],"version-history":[{"count":27,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/10532\/revisions"}],"predecessor-version":[{"id":10560,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/10532\/revisions\/10560"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=10532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=10532"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=10532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}