Fix isascii() method calls for python 3.6 (#4958)

* fix isascii for python3.6

* update comment with python 3.7 note

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Diego MontesandGlenn Jocher authored and GitHub committed 2021-09-27 20:16:23 -07:00
1 parent 2993c3fa7a
commit c1bed601e9
2 files changed
+8 -3

No files matched your search

+3 -3
View File
@@ -17,7 +17,7 @@ import seaborn as sn
import torch
from PIL import Image, ImageDraw, ImageFont
from utils.general import user_config_dir, is_chinese, xywh2xyxy, xyxy2xywh
from utils.general import user_config_dir, is_ascii, is_chinese, xywh2xyxy, xyxy2xywh
from utils.metrics import fitness
# Settings
@@ -68,7 +68,7 @@ class Annotator:
# YOLOv5 Annotator for train/val mosaics and jpgs and detect/hub inference annotations
def __init__(self, im, line_width=None, font_size=None, font='Arial.ttf', pil=False, example='abc'):
assert im.data.contiguous, 'Image not contiguous. Apply np.ascontiguousarray(im) to Annotator() input images.'
self.pil = pil or not example.isascii() or is_chinese(example)
self.pil = pil or not is_ascii(example) or is_chinese(example)
if self.pil: # use PIL
self.im = im if isinstance(im, Image.Image) else Image.fromarray(im)
self.draw = ImageDraw.Draw(self.im)
@@ -80,7 +80,7 @@ class Annotator:
def box_label(self, box, label='', color=(128, 128, 128), txt_color=(255, 255, 255)):
# Add one xyxy box to image with label
if self.pil or not label.isascii():
if self.pil or not is_ascii(label):
self.draw.rectangle(box, width=self.lw, outline=color) # box
if label:
w, h = self.font.getsize(label) # text width, height