فهرست منبع

Merge pull request #1789 from Zheng-Bicheng/patch-1

Fixed the potential errors that may occur in PaddleX when the Pillow version is greater than 10.0.0
cuicheng01 1 سال پیش
والد
کامیت
22b4667ada
1فایلهای تغییر یافته به همراه7 افزوده شده و 1 حذف شده
  1. 7 1
      paddlex/modules/object_detection/dataset_checker/dataset_src/utils/visualizer.py

+ 7 - 1
paddlex/modules/object_detection/dataset_checker/dataset_src/utils/visualizer.py

@@ -11,6 +11,7 @@ import os
 import numpy as np
 import json
 from pathlib import Path
+import PIL
 from PIL import Image, ImageDraw, ImageFont
 from pycocotools.coco import COCO
 
@@ -113,7 +114,12 @@ def draw_bbox(image, coco_info: COCO, img_id):
         # draw label
         label = coco_info.loadCats(catid)[0]['name']
         text = "{}".format(label)
-        tw, th = draw.textsize(text, font=font)
+        if tuple(map(int, PIL.__version__.split('.'))) <= (10, 0, 0):
+            tw, th = draw.textsize(text, font=font)
+        else:
+            left, top, right, bottom = draw.textbbox((0, 0), text, font)
+            tw, th = right - left, bottom - top
+        
         if ymin < th:
             draw.rectangle(
                 [(xmin, ymin), (xmin + tw + 4, ymin + th + 1)], fill=color)