Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongpei committed Mar 11, 2024
1 parent 48453ab commit eb54ef3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions image2text.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .wd_v3_model import WdV3Model
from PIL import Image
import numpy as np
from .utils import remove_specific_patterns
from .utils import remove_specific_patterns,tensor2pil

GLOBAL_WdV3Model = None

Expand Down Expand Up @@ -81,13 +81,13 @@ def get_value(self, model, image, query, custom_query, print_log):
# Iterate over each batch of images
for img in image:
# Convert Tensor to image
img = Image.fromarray(
np.clip(255.0 * img.cpu().numpy(), 0, 255).astype(np.uint8)
)

img = tensor2pil(img)
img = img.convert("RGB")
# Additional processing for specific models
if model.name == "internlm":
query = f"<ImageHere>{query}"

result = model.answer_question(img, query)
if print_log:
print(result)
Expand Down
1 change: 1 addition & 0 deletions text2prompt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .qwen_model import QwenModel


class LoadText2PromptModel:
def __init__(self):
pass
Expand Down
4 changes: 4 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def tensor2pil(image):
return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8))






def remove_specific_patterns(text):
# 构建一个匹配特定词汇前面有数字的正则表达式
pattern = r"\d+(girl|boy|man|person|woman|men|women|girls|boys|mans),*\b"
Expand Down

0 comments on commit eb54ef3

Please sign in to comment.