update
Browse files- tokenization_qwen.py +5 -9
tokenization_qwen.py
CHANGED
@@ -26,7 +26,7 @@ from matplotlib.font_manager import FontProperties
|
|
26 |
logger = logging.getLogger(__name__)
|
27 |
|
28 |
|
29 |
-
VOCAB_FILES_NAMES = {"vocab_file": "qwen.tiktoken"}
|
30 |
|
31 |
PAT_STR = r"""(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+"""
|
32 |
ENDOFTEXT = "<|endoftext|>"
|
@@ -169,9 +169,6 @@ class QWenTokenizer(PreTrainedTokenizer):
|
|
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 |
|
@@ -417,8 +414,8 @@ class QWenTokenizer(PreTrainedTokenizer):
|
|
417 |
h, w = image.height, image.width
|
418 |
else:
|
419 |
image = plt.imread(image)
|
420 |
-
|
421 |
-
visualizer = Visualizer(image
|
422 |
|
423 |
boxes = self._fetch_all_box_with_ref(response)
|
424 |
if not boxes:
|
@@ -493,9 +490,8 @@ class VisImage:
|
|
493 |
|
494 |
|
495 |
class Visualizer:
|
496 |
-
def __init__(self, img_rgb,
|
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,7 +523,7 @@ class Visualizer:
|
|
527 |
y,
|
528 |
text,
|
529 |
size=font_size * self.output.scale,
|
530 |
-
fontproperties=FontProperties(fname=
|
531 |
bbox={"facecolor": "black", "alpha": 0.8, "pad": 0.7, "edgecolor": "none"},
|
532 |
verticalalignment="top",
|
533 |
horizontalalignment=horizontal_alignment,
|
|
|
26 |
logger = logging.getLogger(__name__)
|
27 |
|
28 |
|
29 |
+
VOCAB_FILES_NAMES = {"vocab_file": "qwen.tiktoken", "ttf": "SimSun.ttf"}
|
30 |
|
31 |
PAT_STR = r"""(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+"""
|
32 |
ENDOFTEXT = "<|endoftext|>"
|
|
|
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 |
|
|
|
414 |
h, w = image.height, image.width
|
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:
|
|
|
490 |
|
491 |
|
492 |
class Visualizer:
|
493 |
+
def __init__(self, img_rgb, metadata=None, scale=1.0):
|
494 |
self.img = np.asarray(img_rgb).clip(0, 255).astype(np.uint8)
|
|
|
495 |
self.output = VisImage(self.img, scale=scale)
|
496 |
self.cpu_device = torch.device("cpu")
|
497 |
|
|
|
523 |
y,
|
524 |
text,
|
525 |
size=font_size * self.output.scale,
|
526 |
+
fontproperties=FontProperties(fname=r"SimSun.ttf"),
|
527 |
bbox={"facecolor": "black", "alpha": 0.8, "pad": 0.7, "edgecolor": "none"},
|
528 |
verticalalignment="top",
|
529 |
horizontalalignment=horizontal_alignment,
|