simonJJJ commited on
Commit
123dfa3
1 Parent(s): 234db1e

fix ttf path

Browse files
Files changed (1) hide show
  1. tokenization_qwen.py +7 -5
tokenization_qwen.py CHANGED
@@ -169,6 +169,9 @@ class QWenTokenizer(PreTrainedTokenizer):
169
  self.im_start_id = self.special_tokens[IMSTART]
170
  self.im_end_id = self.special_tokens[IMEND]
171
 
 
 
 
172
  def __len__(self) -> int:
173
  return self.tokenizer.n_vocab
174
 
@@ -415,13 +418,11 @@ class QWenTokenizer(PreTrainedTokenizer):
415
  else:
416
  image = plt.imread(image)
417
  h, w = image.shape[0], image.shape[1]
418
- visualizer = Visualizer(image)
419
 
420
  boxes = self._fetch_all_box_with_ref(response)
421
  if not boxes:
422
  return None
423
- # fnt = ImageFont.truetype("SimSun.ttf", 50)
424
- # draw = ImageDraw.Draw(image)
425
  color = random.choice([_ for _ in mcolors.TABLEAU_COLORS.keys()]) # init color
426
  for box in boxes:
427
  if 'ref' in box: # random new color for new refexps
@@ -492,8 +493,9 @@ class VisImage:
492
 
493
 
494
  class Visualizer:
495
- def __init__(self, img_rgb, metadata=None, scale=1.0):
496
  self.img = np.asarray(img_rgb).clip(0, 255).astype(np.uint8)
 
497
  self.output = VisImage(self.img, scale=scale)
498
  self.cpu_device = torch.device("cpu")
499
 
@@ -525,7 +527,7 @@ class Visualizer:
525
  y,
526
  text,
527
  size=font_size * self.output.scale,
528
- fontproperties=FontProperties(fname=r"SimSun.ttf"),
529
  bbox={"facecolor": "black", "alpha": 0.8, "pad": 0.7, "edgecolor": "none"},
530
  verticalalignment="top",
531
  horizontalalignment=horizontal_alignment,
 
169
  self.im_start_id = self.special_tokens[IMSTART]
170
  self.im_end_id = self.special_tokens[IMEND]
171
 
172
+ model_dir = getattr(self, 'model_dir', '')
173
+ self.font_path = os.path.join(model_dir, "SimSun.ttf")
174
+
175
  def __len__(self) -> int:
176
  return self.tokenizer.n_vocab
177
 
 
418
  else:
419
  image = plt.imread(image)
420
  h, w = image.shape[0], image.shape[1]
421
+ visualizer = Visualizer(image, font_path=self.font_path)
422
 
423
  boxes = self._fetch_all_box_with_ref(response)
424
  if not boxes:
425
  return None
 
 
426
  color = random.choice([_ for _ in mcolors.TABLEAU_COLORS.keys()]) # init color
427
  for box in boxes:
428
  if 'ref' in box: # random new color for new refexps
 
493
 
494
 
495
  class Visualizer:
496
+ def __init__(self, img_rgb, font_path, metadata=None, scale=1.0):
497
  self.img = np.asarray(img_rgb).clip(0, 255).astype(np.uint8)
498
+ self.font_path = font_path
499
  self.output = VisImage(self.img, scale=scale)
500
  self.cpu_device = torch.device("cpu")
501
 
 
527
  y,
528
  text,
529
  size=font_size * self.output.scale,
530
+ fontproperties=FontProperties(fname=self.font_path),
531
  bbox={"facecolor": "black", "alpha": 0.8, "pad": 0.7, "edgecolor": "none"},
532
  verticalalignment="top",
533
  horizontalalignment=horizontal_alignment,