{"id":53743,"date":"2025-02-16T15:05:20","date_gmt":"2025-02-16T07:05:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53743\/"},"modified":"2025-02-16T15:05:20","modified_gmt":"2025-02-16T07:05:20","slug":"%e5%a4%9a%e6%a8%a1%e6%80%81%e6%96%87%e6%a1%a3%e5%9b%be%e5%83%8f%e6%95%b0%e6%8d%ae%e5%a2%9e%e5%bc%ba","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53743\/","title":{"rendered":"\u591a\u6a21\u6001\u6587\u6863\u56fe\u50cf\u6570\u636e\u589e\u5f3a"},"content":{"rendered":"<p>\u5728\u8fd9\u7bc7\u535a\u6587\u4e2d\uff0c\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u4e2a\u6559\u7a0b\uff0c\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u4e0e Albumentations AI \u5408\u4f5c\u5f00\u53d1\u7684\u4e00\u79cd\u65b0\u7684\u6587\u6863\u56fe\u50cf\u6570\u636e\u589e\u5f3a\u6280\u672f\u3002<\/p>\n<h2>1\u3001\u52a8\u673a<\/h2>\n<p>\u89c6\u89c9\u8bed\u8a00\u6a21\u578b (VLM) \u5177\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u8303\u56f4\uff0c\u4f46\u5b83\u4eec\u901a\u5e38\u9700\u8981\u9488\u5bf9\u7279\u5b9a\u200b\u200b\u7528\u4f8b\u8fdb\u884c\u5fae\u8c03\uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u5305\u542b\u6587\u6863\u56fe\u50cf\u7684\u6570\u636e\u96c6\uff0c\u5373\u5177\u6709\u5927\u91cf\u6587\u672c\u5185\u5bb9\u7684\u56fe\u50cf\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6587\u672c\u548c\u56fe\u50cf\u5728\u6a21\u578b\u8bad\u7ec3\u7684\u6240\u6709\u9636\u6bb5\u76f8\u4e92\u4f5c\u7528\u81f3\u5173\u91cd\u8981\uff0c\u800c\u5bf9\u4e24\u79cd\u6a21\u5f0f\u5e94\u7528\u589e\u5f3a\u53ef\u786e\u4fdd\u8fd9\u79cd\u76f8\u4e92\u4f5c\u7528\u3002\u672c\u8d28\u4e0a\uff0c\u6211\u4eec\u5e0c\u671b\u6a21\u578b\u80fd\u591f\u5b66\u4f1a\u6b63\u786e\u9605\u8bfb\uff0c\u8fd9\u5728\u6700\u5e38\u89c1\u7684\u6570\u636e\u7f3a\u5931\u60c5\u51b5\u4e0b\u5177\u6709\u6311\u6218\u6027\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u5728\u89e3\u51b3\u6570\u636e\u96c6\u6709\u9650\u7684\u5fae\u8c03\u6a21\u578b\u4e2d\u7684\u6311\u6218\u65f6\uff0c\u5bf9\u6587\u6863\u56fe\u50cf\u7684\u6709\u6548\u6570\u636e\u589e\u5f3a\u6280\u672f\u7684\u9700\u6c42\u53d8\u5f97\u663e\u800c\u6613\u89c1\u3002\u4e00\u4e2a\u5e38\u89c1\u7684\u62c5\u5fe7\u662f\uff0c\u5178\u578b\u7684\u56fe\u50cf\u8f6c\u6362\uff08\u4f8b\u5982\u8c03\u6574\u5927\u5c0f\u3001\u6a21\u7cca\u6216\u66f4\u6539\u80cc\u666f\u989c\u8272\uff09\u4f1a\u5bf9\u6587\u672c\u63d0\u53d6\u51c6\u786e\u6027\u4ea7\u751f\u8d1f\u9762\u5f71\u54cd\u3002<\/p>\n<p>\u6211\u4eec\u8ba4\u8bc6\u5230\u9700\u8981\u6570\u636e\u589e\u5f3a\u6280\u672f\uff0c\u5728\u589e\u5f3a\u6570\u636e\u96c6\u7684\u540c\u65f6\u4fdd\u7559\u6587\u672c\u7684\u5b8c\u6574\u6027\u3002\u8fd9\u79cd\u6570\u636e\u589e\u5f3a\u53ef\u4ee5\u4fc3\u8fdb\u65b0\u6587\u6863\u7684\u751f\u6210\u6216\u73b0\u6709\u6587\u6863\u7684\u4fee\u6539\uff0c\u540c\u65f6\u4fdd\u6301\u5176\u6587\u672c\u8d28\u91cf\u3002<\/p>\n<h2>2\u3001\u7b80\u4ecb<\/h2>\n<p>\u4e3a\u4e86\u6ee1\u8db3\u8fd9\u4e00\u9700\u6c42\uff0c\u6211\u4eec\u5f15\u5165\u4e86\u4e0e Albumentations AI \u5408\u4f5c\u5f00\u53d1\u7684\u65b0\u6570\u636e\u589e\u5f3a\u7ba1\u9053\u3002\u8be5\u7ba1\u9053\u5904\u7406\u56fe\u50cf\u548c\u5176\u4e2d\u7684\u6587\u672c\uff0c\u4e3a\u6587\u6863\u56fe\u50cf\u63d0\u4f9b\u5168\u9762\u7684\u89e3\u51b3\u65b9\u6848\u3002\u6b64\u7c7b\u6570\u636e\u589e\u5f3a\u662f\u591a\u6a21\u6001\u7684\uff0c\u56e0\u4e3a\u5b83\u540c\u65f6\u4fee\u6539\u56fe\u50cf\u5185\u5bb9\u548c\u6587\u672c\u6807\u6ce8\u3002<\/p>\n<p>\u6b63\u5982\u4e4b\u524d\u7684\u535a\u5ba2\u6587\u7ae0\u4e2d\u6240\u8ba8\u8bba\u7684\uff0c\u6211\u4eec\u7684\u76ee\u6807\u662f\u68c0\u9a8c\u8fd9\u6837\u4e00\u4e2a\u5047\u8bbe\uff1a\u5728 VLM \u7684\u9884\u8bad\u7ec3\u671f\u95f4\u96c6\u6210\u5bf9\u6587\u672c\u548c\u56fe\u50cf\u7684\u589e\u5f3a\u662f\u6709\u6548\u7684\u3002\u8be6\u7ec6\u53c2\u6570\u548c\u7528\u4f8b\u8bf4\u660e\u53ef\u5728 Albumentations AI \u6587\u6863\u4e2d\u627e\u5230\u3002Albumentations AI \u652f\u6301\u52a8\u6001\u8bbe\u8ba1\u8fd9\u4e9b\u589e\u5f3a\u5e76\u5c06\u5176\u4e0e\u5176\u4ed6\u7c7b\u578b\u7684\u589e\u5f3a\u96c6\u6210\u3002<\/p>\n<h2>3\u3001\u5b9e\u73b0\u65b9\u6cd5<\/h2>\n<p>\u4e3a\u4e86\u589e\u5f3a\u6587\u6863\u56fe\u50cf\uff0c\u6211\u4eec\u9996\u5148\u968f\u673a\u9009\u62e9\u6587\u6863\u4e2d\u7684\u884c\u3002\u8d85\u53c2\u6570 <code>fraction_range<\/code> \u63a7\u5236\u8981\u4fee\u6539\u7684\u8fb9\u754c\u6846\u5206\u6570\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u51e0\u79cd\u6587\u672c\u589e\u5f3a\u65b9\u6cd5\u4e2d\u7684\u4e00\u79cd\u5e94\u7528\u4e8e\u76f8\u5e94\u7684\u6587\u672c\u884c\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u901a\u5e38\u7528\u4e8e\u6587\u672c\u751f\u6210\u4efb\u52a1\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5305\u62ec\u968f\u673a\u63d2\u5165\u3001\u5220\u9664\u548c\u4ea4\u6362\u4ee5\u53ca\u505c\u7528\u8bcd\u66ff\u6362\u3002<\/p>\n<p>\u4fee\u6539\u6587\u672c\u540e\uff0c\u6211\u4eec\u5c06\u63d2\u5165\u6587\u672c\u7684\u56fe\u50cf\u90e8\u5206\u6d82\u9ed1\u5e76\u5bf9\u5176\u8fdb\u884c\u4fee\u590d\uff0c\u4f7f\u7528\u539f\u59cb\u8fb9\u754c\u6846\u5927\u5c0f\u4f5c\u4e3a\u65b0\u6587\u672c\u5b57\u4f53\u5927\u5c0f\u7684\u4ee3\u7406\u3002\u53ef\u4ee5\u4f7f\u7528\u53c2\u6570 <code>font_size_fraction_range<\/code> \u6307\u5b9a\u5b57\u4f53\u5927\u5c0f\uff0c\u8be5\u53c2\u6570\u786e\u5b9a\u9009\u62e9\u5b57\u4f53\u5927\u5c0f\u7684\u8303\u56f4\u4f5c\u4e3a\u8fb9\u754c\u6846\u9ad8\u5ea6\u7684\u5206\u6570\u3002\u8bf7\u6ce8\u610f\uff0c\u53ef\u4ee5\u68c0\u7d22\u4fee\u6539\u540e\u7684\u6587\u672c\u548c\u76f8\u5e94\u7684\u8fb9\u754c\u6846\u5e76\u5c06\u5176\u7528\u4e8e\u8bad\u7ec3\u3002\u6b64\u8fc7\u7a0b\u4f1a\u4ea7\u751f\u4e00\u4e2a\u5177\u6709\u8bed\u4e49\u76f8\u4f3c\u6587\u672c\u5185\u5bb9\u548c\u89c6\u89c9\u626d\u66f2\u56fe\u50cf\u7684\u6570\u636e\u96c6\u3002<\/p>\n<h2>4\u3001\u4e3b\u8981\u529f\u80fd<\/h2>\n<p>TextImage Augmentation\u5e93\u53ef\u7528\u4e8e\u4e24\u4e2a\u4e3b\u8981\u76ee\u7684\uff1a<\/p>\n<p>a) \u5728\u56fe\u50cf\u4e0a\u63d2\u5165\u4efb\u4f55\u6587\u672c\uff1a\u6b64\u529f\u80fd\u5141\u8bb8\u4f60\u5728\u6587\u6863\u56fe\u50cf\u4e0a\u53e0\u52a0\u6587\u672c\uff0c\u4ece\u800c\u6709\u6548\u5730\u751f\u6210\u5408\u6210\u6570\u636e\u3002\u901a\u8fc7\u4f7f\u7528\u4efb\u4f55\u968f\u673a\u56fe\u50cf\u4f5c\u4e3a\u80cc\u666f\u5e76\u6e32\u67d3\u5168\u65b0\u7684\u6587\u672c\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u591a\u6837\u5316\u7684\u8bad\u7ec3\u6837\u672c\u3002\u4e2d\u5f15\u5165\u4e86\u4e00\u79cd\u7c7b\u4f3c\u7684\u6280\u672f\uff0c\u79f0\u4e3a SynthDOG\u3002<\/p>\n<p>b) \u5728\u56fe\u50cf\u4e0a\u63d2\u5165\u589e\u5f3a\u6587\u672c\uff1a\u8fd9\u5305\u62ec\u4ee5\u4e0b\u6587\u672c\u589e\u5f3a\uff1a<\/p>\n<ul>\n<li>\u968f\u673a\u5220\u9664\uff1a\u968f\u673a\u4ece\u6587\u672c\u4e2d\u5220\u9664\u5355\u8bcd\u3002<\/li>\n<li>\u968f\u673a\u4ea4\u6362\uff1a\u5728\u6587\u672c\u4e2d\u4ea4\u6362\u5355\u8bcd\u3002<\/li>\n<li>\u505c\u7528\u8bcd\u63d2\u5165\uff1a\u5c06\u5e38\u7528\u505c\u7528\u8bcd\u63d2\u5165\u6587\u672c\u3002<\/li>\n<\/ul>\n<p>\u5c06\u8fd9\u4e9b\u589e\u5f3a\u4e0e Albumentations \u4e2d\u7684\u5176\u4ed6\u56fe\u50cf\u8f6c\u6362\u76f8\u7ed3\u5408\uff0c\u53ef\u4ee5\u540c\u65f6\u4fee\u6539\u56fe\u50cf\u548c\u6587\u672c\u3002\u4f60\u4e5f\u53ef\u4ee5\u68c0\u7d22\u589e\u5f3a\u6587\u672c\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u6b64 repo \u4e2d\u4ecb\u7ecd\u7684\u6570\u636e\u589e\u5f3a\u7ba1\u9053\u7684\u521d\u59cb\u7248\u672c\u5305\u62ec\u540c\u4e49\u8bcd\u66ff\u6362\u3002\u5b83\u5728\u6b64\u7248\u672c\u4e2d\u88ab\u5220\u9664\uff0c\u56e0\u4e3a\u5b83\u4f1a\u9020\u6210\u5927\u91cf\u65f6\u95f4\u5f00\u9500\u3002<\/p>\n<h2>5\u3001\u5feb\u901f\u4e0a\u624b<\/h2>\n<p>\u4f7f\u7528\u5982\u4e0b\u4ee3\u7801\u5b89\u88c5TextImage Augmentation\uff1a<\/p>\n<pre><code>!pip install -U pillow\n!pip install albumentations\n!pip install nltk\n<\/code><\/pre>\n<p>\u4f7f\u7528\u5982\u4e0b\u4ee3\u7801\u5bfc\u5165\u4f9d\u8d56\u5305\uff1a<\/p>\n<pre><code>import albumentations as A\nimport cv2\nfrom matplotlib import pyplot as plt\nimport json\nimport nltk\n\nnltk.download('stopwords')\nfrom nltk.corpus import stopwords\n<\/code><\/pre>\n<p>\u53ef\u89c6\u5316\uff1a<\/p>\n<pre><code>def visualize(image):\n    plt.figure(figsize=(20, 15))\n    plt.axis('off')\n    plt.imshow(image)\n<\/code><\/pre>\n<h3>5.1 \u52a0\u8f7d\u6570\u636e<\/h3>\n<p>\u8bf7\u6ce8\u610f\uff0c\u5bf9\u4e8e\u8fd9\u79cd\u7c7b\u578b\u7684\u589e\u5f3a\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 IDL \u548c PDFA \u6570\u636e\u96c6\u3002\u5b83\u4eec\u63d0\u4f9b\u4f60\u8981\u4fee\u6539\u7684\u7ebf\u6761\u7684\u8fb9\u754c\u6846\u3002\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u91cd\u70b9\u4ecb\u7ecd IDL \u6570\u636e\u96c6\u4e2d\u7684\u6837\u672c\u3002<\/p>\n<pre><code>bgr_image = cv2.imread(\"examples\/original\/fkhy0236.tif\")\nimage = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB)\n\nwith open(\"examples\/original\/fkhy0236.json\") as f:\n    labels = json.load(f)\n\nfont_path = \"\/usr\/share\/fonts\/truetype\/liberation\/LiberationSerif-Regular.ttf\"\n\nvisualize(image)\n<\/code><\/pre>\n<p>\u6211\u4eec\u9700\u8981\u6b63\u786e\u5730\u9884\u5904\u7406\u6570\u636e\uff0c\u56e0\u4e3a\u8fb9\u754c\u6846\u7684\u8f93\u5165\u683c\u5f0f\u662f\u6807\u51c6\u5316\u7684 Pascal VOC\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u6309\u5982\u4e0b\u65b9\u5f0f\u6784\u5efa\u5143\u6570\u636e\uff1a<\/p>\n<pre><code>page = labels['pages'][0]\n\ndef prepare_metadata(page: dict, image_height: int, image_width: int) -&gt; list:\n    metadata = []\n\n    for text, box in zip(page['text'], page['bbox']):\n        left, top, width_norm, height_norm = box\n\n        metadata.append({\n            \"bbox\": [left, top, left + width_norm, top + height_norm],\n            \"text\": text\n        })\n    \n    return metadata\n\nimage_height, image_width = image.shape[:2]\nmetadata = prepare_metadata(page, image_height, image_width)\n<\/code><\/pre>\n<h3>5.2 \u968f\u673a\u4ea4\u6362<\/h3>\n<pre><code>transform = A.Compose([A.TextImage(font_path=font_path, p=1, augmentations=[\"swap\"], clear_bg=True, font_color = 'red', fraction_range = (0.5,0.8), font_size_fraction_range=(0.8, 0.9))])\ntransformed = transform(image=image, textimage_metadata=metadata)\nvisualize(transformed[\"image\"])\n<\/code><\/pre>\n<h3>5.3 \u968f\u673a\u5220\u9664<\/h3>\n<pre><code>transform = A.Compose([A.TextImage(font_path=font_path, p=1, augmentations=[\"deletion\"], clear_bg=True, font_color = 'red', fraction_range = (0.5,0.8), font_size_fraction_range=(0.8, 0.9))])\ntransformed = transform(image=image, textimage_metadata=metadata)\nvisualize(transformed['image'])\n<\/code><\/pre>\n<h3>5.4 \u968f\u673a\u63d2\u5165<\/h3>\n<p>\u5728\u968f\u673a\u63d2\u5165\u4e2d\uff0c\u6211\u4eec\u5c06\u968f\u673a\u5355\u8bcd\u6216\u77ed\u8bed\u63d2\u5165\u6587\u672c\u4e2d\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4f7f\u7528\u505c\u7528\u8bcd\uff0c\u5373\u8bed\u8a00\u4e2d\u7684\u5e38\u7528\u8bcd\uff0c\u5728\u81ea\u7136\u8bed\u8a00\u5904\u7406 (NLP) \u4efb\u52a1\u4e2d\u7ecf\u5e38\u88ab\u5ffd\u7565\u6216\u8fc7\u6ee4\u6389\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0e\u5176\u4ed6\u8bcd\u76f8\u6bd4\u6240\u5305\u542b\u7684\u4fe1\u606f\u8f83\u5c11\u3002\u505c\u7528\u8bcd\u7684\u793a\u4f8b\u5305\u62ec \u201cis\u201d\u3001 \u201cthe\u201d\u3001 \u201cin\u201d\u3001 \u201cand\u201d\u3001 \u201cof\u201d\u7b49\u3002<\/p>\n<pre><code>stops = stopwords.words('english')\ntransform = A.Compose([A.TextImage(font_path=font_path, p=1, augmentations=[\"insertion\"], stopwords = stops, clear_bg=True, font_color = 'red', fraction_range = (0.5,0.8), font_size_fraction_range=(0.8, 0.9))])\ntransformed = transform(image=image, textimage_metadata=metadata)\nvisualize(transformed['image'])\n<\/code><\/pre>\n<h2>6\u3001\u6211\u4eec\u53ef\u4ee5\u4e0e\u5176\u4ed6\u8f6c\u6362\u7ed3\u5408\u5417\uff1f<\/h2>\n<p>\u8ba9\u6211\u4eec\u4f7f\u7528 A.Compose \u5b9a\u4e49\u4e00\u4e2a\u590d\u6742\u7684\u8f6c\u6362\u7ba1\u9053\uff0c\u5176\u4e2d\u5305\u62ec\u4f7f\u7528\u6307\u5b9a\u5b57\u4f53\u5c5e\u6027\u548c\u505c\u7528\u8bcd\u63d2\u5165\u6587\u672c\u3001\u666e\u6717\u514b\u6296\u52a8\u548c\u4eff\u5c04\u53d8\u6362\u3002\u9996\u5148\uff0c\u4f7f\u7528 <code>A.TextImage<\/code>\uff0c\u6211\u4eec\u4f7f\u7528\u6307\u5b9a\u7684\u5b57\u4f53\u5c5e\u6027\u5c06\u6587\u672c\u63d2\u5165\u56fe\u50cf\u4e2d\uff0c\u80cc\u666f\u6e05\u6670\uff0c\u5b57\u4f53\u989c\u8272\u4e3a\u7ea2\u8272\u3002\u8fd8\u8981\u6307\u5b9a\u8981\u63d2\u5165\u7684\u6587\u672c\u7684\u6bd4\u4f8b\u548c\u5927\u5c0f\u3002\u7136\u540e\u4f7f\u7528 <code>A.PlanckianJitter<\/code> \u6539\u53d8\u56fe\u50cf\u7684\u8272\u5f69\u5e73\u8861\u3002\u6700\u540e\uff0c\u4f7f\u7528 <code>A.Affine<\/code> \u5e94\u7528\u4eff\u5c04\u53d8\u6362\uff0c\u5176\u4e2d\u5305\u62ec\u7f29\u653e\u3001\u65cb\u8f6c\u548c\u5e73\u79fb\u56fe\u50cf\u3002<\/p>\n<pre><code>transform_complex = A.Compose([A.TextImage(font_path=font_path, p=1, augmentations=[\"insertion\"], stopwords = stops, clear_bg=True, font_color = 'red', fraction_range = (0.5,0.8), font_size_fraction_range=(0.8, 0.9)),\n                               A.PlanckianJitter(p=1),\n                               A.Affine(p=1)\n                              ])\ntransformed = transform_complex(image=image, textimage_metadata=metadata)\nvisualize(transformed[\"image\"])\n<\/code><\/pre>\n<h2>7\u3001\u5982\u4f55\u83b7\u53d6\u66f4\u6539\u540e\u7684\u6587\u672c\uff1f<\/h2>\n<p>\u8981\u63d0\u53d6\u66f4\u6539\u6587\u672c\u7684\u8fb9\u754c\u6846\u7d22\u5f15\u4fe1\u606f\u4ee5\u53ca\u76f8\u5e94\u7684\u8f6c\u6362\u6587\u672c\u6570\u636e\uff0c\u8bf7\u8fd0\u884c\u4ee5\u4e0b\u5355\u5143\u683c\u3002\u6b64\u6570\u636e\u53ef\u6709\u6548\u7528\u4e8e\u8bad\u7ec3\u6a21\u578b\u4ee5\u8bc6\u522b\u548c\u5904\u7406\u56fe\u50cf\u4e2d\u7684\u6587\u672c\u53d8\u5316\u3002<\/p>\n<pre><code>transformed['overlay_data']\n<\/code><\/pre>\n<pre><code>[{'bbox_coords': (375, 1149, 2174, 1196),\n  'text': \"Lionberger, Ph.D., (Title: if Introduction to won i FDA's yourselves Draft Guidance once of the wasn't General Principles\",\n  'original_text': \"Lionberger, Ph.D., (Title: Introduction to FDA's Draft Guidance of the General Principles\",\n  'bbox_index': 12,\n  'font_color': 'red'},\n {'bbox_coords': (373, 1677, 2174, 1724),\n  'text': \"After off needn't were a brief break, ADC member mustn Jeffrey that Dayno, MD, Chief Medical Officer for at their Egalet\",\n  'original_text': 'After a brief break, ADC member Jeffrey Dayno, MD, Chief Medical Officer at Egalet',\n  'bbox_index': 19,\n  'font_color': 'red'},\n {'bbox_coords': (525, 2109, 2172, 2156),\n  'text': 'll Brands recognize the has importance and of a generics ADF guidance to ensure which after',\n  'original_text': 'Brands recognize the importance of a generics ADF guidance to ensure',\n  'bbox_index': 23,\n  'font_color': 'red'}]\n<\/code><\/pre>\n<h2>8\u3001\u5408\u6210\u6570\u636e\u751f\u6210<\/h2>\n<p>\u6b64\u589e\u5f3a\u65b9\u6cd5\u53ef\u4ee5\u6269\u5c55\u5230\u5408\u6210\u6570\u636e\u7684\u751f\u6210\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u5728\u4efb\u4f55\u80cc\u666f\u6216\u6a21\u677f\u4e0a\u5448\u73b0\u6587\u672c\u3002<\/p>\n<pre><code>template = cv2.imread('template.png')\nimage_template = cv2.cvtColor(template, cv2.COLOR_BGR2RGB)\ntransform = A.Compose([A.TextImage(font_path=font_path, p=1, clear_bg=True, font_color = 'red', font_size_fraction_range=(0.5, 0.7))])\n\nmetadata = [{\n    \"bbox\": [0.1, 0.4, 0.5, 0.48],\n    \"text\": \"Some smart text goes here.\",\n}, {\n    \"bbox\": [0.1, 0.5, 0.5, 0.58],\n    \"text\": \"Hope you find it helpful.\",\n}]\n\ntransformed = transform(image=image_template, textimage_metadata=metadata)\nvisualize(transformed['image'])\n<\/code><\/pre>\n<h2>9\u3001\u7ed3\u675f\u8bed<\/h2>\n<p>\u6211\u4eec\u4e0e Albumentations AI \u5408\u4f5c\uff0c\u63a8\u51fa\u4e86 TextImage Augmentation\uff0c\u8fd9\u662f\u4e00\u79cd\u591a\u6a21\u6001\u6280\u672f\uff0c\u53ef\u4fee\u6539\u6587\u6863\u56fe\u50cf\u548c\u6587\u672c\u3002\u901a\u8fc7\u5c06\u6587\u672c\u589e\u5f3a\uff08\u4f8b\u5982\u968f\u673a\u63d2\u5165\u3001\u5220\u9664\u3001\u4ea4\u6362\u548c\u505c\u7528\u8bcd\u66ff\u6362\uff09\u4e0e\u56fe\u50cf\u4fee\u6539\u76f8\u7ed3\u5408\uff0c\u6b64\u7ba1\u9053\u5141\u8bb8\u751f\u6210\u4e0d\u540c\u7684\u8bad\u7ec3\u6837\u672c\u3002<\/p>\n<p>\u6709\u5173\u8be6\u7ec6\u53c2\u6570\u548c\u7528\u4f8b\u8bf4\u660e\uff0c\u8bf7\u53c2\u9605\u3002\u6211\u4eec\u5e0c\u671b\u4f60\u53d1\u73b0\u8fd9\u4e9b\u589e\u5f3a\u529f\u80fd\u5bf9\u589e\u5f3a\u6587\u6863\u56fe\u50cf\u5904\u7406\u5de5\u4f5c\u6d41\u7a0b\u6709\u7528\u3002<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u8fd9\u7bc7\u535a\u6587\u4e2d\uff0c\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u4e2a\u6559\u7a0b\uff0c\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u4e0e Albumentations AI \u5408\u4f5c\u5f00\u53d1\u7684\u4e00\u79cd\u65b0\u7684\u6587\u6863\u56fe\u50cf\u6570\u636e\u589e\u5f3a\u6280\u672f\u3002 1\u3001\u52a8\u673a \u89c6\u89c9\u8bed\u8a00\u6a21\u578b (VLM) \u5177\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u8303\u56f4\uff0c\u4f46\u5b83\u4eec\u901a\u5e38\u9700\u8981\u9488\u5bf9\u7279\u5b9a\u200b\u200b\u7528\u4f8b\u8fdb\u884c\u5fae\u8c03\uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u5305\u542b\u6587\u6863\u56fe\u50cf\u7684\u6570\u636e\u96c6\uff0c\u5373\u5177\u6709\u5927\u91cf\u6587\u672c\u5185\u5bb9\u7684\u56fe\u50cf\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6587\u672c\u548c\u56fe\u50cf\u5728\u6a21\u578b\u8bad\u7ec3\u7684\u6240\u6709\u9636\u6bb5\u76f8\u4e92\u4f5c\u7528\u81f3\u5173\u91cd\u8981\uff0c\u800c\u5bf9\u4e24\u79cd\u6a21\u5f0f\u5e94\u7528\u589e\u5f3a\u53ef\u786e\u4fdd\u8fd9\u79cd\u76f8\u4e92\u4f5c\u7528\u3002\u672c\u8d28\u4e0a\uff0c\u6211\u4eec\u5e0c\u671b\u6a21\u578b\u80fd\u591f\u5b66\u4f1a\u6b63\u786e\u9605\u8bfb\uff0c\u8fd9\u5728\u6700\u5e38\u89c1\u7684\u6570\u636e\u7f3a\u5931\u60c5\u51b5\u4e0b\u5177\u6709\u6311\u6218\u6027\u3002 \u56e0\u6b64\uff0c\u5728\u89e3\u51b3\u6570\u636e\u96c6\u6709\u9650\u7684\u5fae\u8c03\u6a21\u578b\u4e2d\u7684\u6311\u6218\u65f6\uff0c\u5bf9\u6587\u6863\u56fe\u50cf\u7684\u6709\u6548\u6570\u636e\u589e\u5f3a\u6280\u672f\u7684\u9700\u6c42\u53d8\u5f97\u663e\u800c\u6613\u89c1\u3002\u4e00\u4e2a\u5e38\u89c1\u7684\u62c5\u5fe7\u662f\uff0c\u5178\u578b\u7684\u56fe\u50cf\u8f6c\u6362\uff08\u4f8b\u5982\u8c03\u6574\u5927\u5c0f\u3001\u6a21\u7cca\u6216\u66f4\u6539\u80cc\u666f\u989c\u8272\uff09\u4f1a\u5bf9\u6587\u672c\u63d0\u53d6\u51c6\u786e\u6027\u4ea7\u751f\u8d1f\u9762\u5f71\u54cd\u3002 \u6211\u4eec\u8ba4\u8bc6\u5230\u9700\u8981\u6570\u636e\u589e\u5f3a\u6280\u672f\uff0c\u5728\u589e\u5f3a\u6570\u636e\u96c6\u7684\u540c\u65f6\u4fdd\u7559\u6587\u672c\u7684\u5b8c\u6574\u6027\u3002\u8fd9\u79cd\u6570\u636e\u589e\u5f3a\u53ef\u4ee5\u4fc3\u8fdb\u65b0\u6587\u6863\u7684\u751f\u6210\u6216\u73b0\u6709\u6587\u6863\u7684\u4fee\u6539\uff0c\u540c\u65f6\u4fdd\u6301\u5176\u6587\u672c\u8d28\u91cf\u3002 2\u3001\u7b80\u4ecb \u4e3a\u4e86\u6ee1\u8db3\u8fd9\u4e00\u9700\u6c42\uff0c\u6211\u4eec\u5f15\u5165\u4e86\u4e0e Albumentations AI \u5408\u4f5c\u5f00\u53d1\u7684\u65b0\u6570\u636e\u589e\u5f3a\u7ba1\u9053\u3002\u8be5\u7ba1\u9053\u5904\u7406\u56fe\u50cf\u548c\u5176\u4e2d\u7684\u6587\u672c\uff0c\u4e3a\u6587\u6863\u56fe\u50cf\u63d0\u4f9b\u5168\u9762\u7684\u89e3\u51b3\u65b9\u6848\u3002\u6b64\u7c7b\u6570\u636e\u589e\u5f3a\u662f\u591a\u6a21\u6001\u7684\uff0c\u56e0\u4e3a\u5b83\u540c\u65f6\u4fee\u6539\u56fe\u50cf\u5185\u5bb9\u548c\u6587\u672c\u6807\u6ce8\u3002 \u6b63\u5982\u4e4b\u524d\u7684\u535a\u5ba2\u6587\u7ae0\u4e2d\u6240\u8ba8\u8bba\u7684\uff0c\u6211\u4eec\u7684\u76ee\u6807\u662f\u68c0\u9a8c\u8fd9\u6837\u4e00\u4e2a\u5047\u8bbe\uff1a\u5728 VLM \u7684\u9884\u8bad\u7ec3\u671f\u95f4\u96c6\u6210\u5bf9\u6587\u672c\u548c\u56fe\u50cf\u7684\u589e\u5f3a\u662f\u6709\u6548\u7684\u3002\u8be6\u7ec6\u53c2\u6570\u548c\u7528\u4f8b\u8bf4\u660e\u53ef\u5728 Albumentations AI \u6587\u6863\u4e2d\u627e\u5230\u3002Albumentations AI \u652f\u6301\u52a8\u6001\u8bbe\u8ba1\u8fd9\u4e9b\u589e\u5f3a\u5e76\u5c06\u5176\u4e0e\u5176\u4ed6\u7c7b\u578b\u7684\u589e\u5f3a\u96c6\u6210\u3002 3\u3001\u5b9e\u73b0\u65b9\u6cd5 \u4e3a\u4e86\u589e\u5f3a\u6587\u6863\u56fe\u50cf\uff0c\u6211\u4eec\u9996\u5148\u968f\u673a\u9009\u62e9\u6587\u6863\u4e2d\u7684\u884c\u3002\u8d85\u53c2\u6570 fraction_range \u63a7\u5236\u8981\u4fee\u6539\u7684\u8fb9\u754c\u6846\u5206\u6570\u3002 \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u51e0\u79cd\u6587\u672c\u589e\u5f3a\u65b9\u6cd5\u4e2d\u7684\u4e00\u79cd\u5e94\u7528\u4e8e\u76f8\u5e94\u7684\u6587\u672c\u884c\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u901a\u5e38\u7528\u4e8e\u6587\u672c\u751f\u6210\u4efb\u52a1\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5305\u62ec\u968f\u673a\u63d2\u5165\u3001\u5220\u9664\u548c\u4ea4\u6362\u4ee5\u53ca\u505c\u7528\u8bcd\u66ff\u6362\u3002 \u4fee\u6539\u6587\u672c\u540e\uff0c\u6211\u4eec\u5c06\u63d2\u5165\u6587\u672c\u7684\u56fe\u50cf\u90e8\u5206\u6d82\u9ed1\u5e76\u5bf9\u5176\u8fdb\u884c\u4fee\u590d\uff0c\u4f7f\u7528\u539f\u59cb\u8fb9\u754c\u6846\u5927\u5c0f\u4f5c\u4e3a\u65b0\u6587\u672c\u5b57\u4f53\u5927\u5c0f\u7684\u4ee3\u7406\u3002\u53ef\u4ee5\u4f7f\u7528\u53c2\u6570 font_size_fraction_range \u6307\u5b9a\u5b57\u4f53\u5927\u5c0f\uff0c\u8be5\u53c2\u6570\u786e\u5b9a\u9009\u62e9\u5b57\u4f53\u5927\u5c0f\u7684\u8303\u56f4\u4f5c\u4e3a\u8fb9\u754c\u6846\u9ad8\u5ea6\u7684\u5206\u6570\u3002\u8bf7\u6ce8\u610f\uff0c\u53ef\u4ee5\u68c0\u7d22\u4fee\u6539\u540e\u7684\u6587\u672c\u548c\u76f8\u5e94\u7684\u8fb9\u754c\u6846\u5e76\u5c06\u5176\u7528\u4e8e\u8bad\u7ec3\u3002\u6b64\u8fc7\u7a0b\u4f1a\u4ea7\u751f\u4e00\u4e2a\u5177\u6709\u8bed\u4e49\u76f8\u4f3c\u6587\u672c\u5185\u5bb9\u548c\u89c6\u89c9\u626d\u66f2\u56fe\u50cf\u7684\u6570\u636e\u96c6\u3002 4\u3001\u4e3b\u8981\u529f\u80fd TextImage Augmentation\u5e93\u53ef\u7528\u4e8e\u4e24\u4e2a\u4e3b\u8981\u76ee\u7684\uff1a a) \u5728\u56fe\u50cf\u4e0a\u63d2\u5165\u4efb\u4f55\u6587\u672c\uff1a\u6b64\u529f\u80fd\u5141\u8bb8\u4f60\u5728\u6587\u6863\u56fe\u50cf\u4e0a\u53e0\u52a0\u6587\u672c\uff0c\u4ece\u800c\u6709\u6548\u5730\u751f\u6210\u5408\u6210\u6570\u636e\u3002\u901a\u8fc7\u4f7f\u7528\u4efb\u4f55\u968f\u673a\u56fe\u50cf\u4f5c\u4e3a\u80cc\u666f\u5e76\u6e32\u67d3\u5168\u65b0\u7684\u6587\u672c\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u591a\u6837\u5316\u7684\u8bad\u7ec3\u6837\u672c\u3002\u4e2d\u5f15\u5165\u4e86\u4e00\u79cd\u7c7b\u4f3c\u7684\u6280\u672f\uff0c\u79f0\u4e3a SynthDOG\u3002 b) \u5728\u56fe\u50cf\u4e0a\u63d2\u5165\u589e\u5f3a\u6587\u672c\uff1a\u8fd9\u5305\u62ec\u4ee5\u4e0b\u6587\u672c\u589e\u5f3a\uff1a \u968f\u673a\u5220\u9664\uff1a\u968f\u673a\u4ece\u6587\u672c\u4e2d\u5220\u9664\u5355\u8bcd\u3002 \u968f\u673a\u4ea4\u6362\uff1a\u5728\u6587\u672c\u4e2d\u4ea4\u6362\u5355\u8bcd\u3002 \u505c\u7528\u8bcd\u63d2\u5165\uff1a\u5c06\u5e38\u7528\u505c\u7528\u8bcd\u63d2\u5165\u6587\u672c\u3002 \u5c06\u8fd9\u4e9b\u589e\u5f3a\u4e0e Albumentations \u4e2d\u7684\u5176\u4ed6\u56fe\u50cf\u8f6c\u6362\u76f8\u7ed3\u5408\uff0c\u53ef\u4ee5\u540c\u65f6\u4fee\u6539\u56fe\u50cf\u548c\u6587\u672c\u3002\u4f60\u4e5f\u53ef\u4ee5\u68c0\u7d22\u589e\u5f3a\u6587\u672c\u3002 \u6ce8\u610f\uff1a\u6b64 repo \u4e2d\u4ecb\u7ecd\u7684\u6570\u636e\u589e\u5f3a\u7ba1\u9053\u7684\u521d\u59cb\u7248\u672c\u5305\u62ec\u540c\u4e49\u8bcd\u66ff\u6362\u3002\u5b83\u5728\u6b64\u7248\u672c\u4e2d\u88ab\u5220\u9664\uff0c\u56e0\u4e3a\u5b83\u4f1a\u9020\u6210\u5927\u91cf\u65f6\u95f4\u5f00\u9500\u3002 5\u3001\u5feb\u901f\u4e0a\u624b \u4f7f\u7528\u5982\u4e0b\u4ee3\u7801\u5b89\u88c5TextImage Augmentation\uff1a !pip install -U pillow [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-53743","post","type-post","status-publish","format-standard","hentry","category-ai"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=53743"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53743\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}