[GH-ISSUE #54] 怎么进行多图联合推理 #44

Open
opened 2026-10-26 21:10:41 +00:00 by bsakaguchi · 3 comments
Owner

Originally created by @LiLiLiam on GitHub (Jan 28, 2025).
Original GitHub issue: https://github.com/deepseek-ai/Janus/issues/54

我需要在一个question中对多张图进行联合推理,以下是我的部分代码:
content_images = []
for idx in range(len(image_files)):
# content.append({"type": "image", "image": image_files[idx]})
content_images.append("data:image,{}".format(image_to_base64(image_files[idx], max_size=1024)))

conversation = [
    {
        "role": "<|User|>",
        "content": f"<image_placeholder>\n{query}",
        "images": content_images,
    },
    {"role": "<|Assistant|>", "content": ""},
]

目前会提示问题:
RuntimeError: The expanded size of the tensor (1) must match the existing size (2) at non-singleton dimension 0. Target sizes: [1, 3, 384, 384]. Tensor sizes: [2, 3, 384, 384]
要如何改进我的代码,使其可以实现多图联合推理

Originally created by @LiLiLiam on GitHub (Jan 28, 2025). Original GitHub issue: https://github.com/deepseek-ai/Janus/issues/54 我需要在一个question中对多张图进行联合推理,以下是我的部分代码: content_images = [] for idx in range(len(image_files)): # content.append({"type": "image", "image": image_files[idx]}) content_images.append("data:image,{}".format(image_to_base64(image_files[idx], max_size=1024))) conversation = [ { "role": "<|User|>", "content": f"<image_placeholder>\n{query}", "images": content_images, }, {"role": "<|Assistant|>", "content": ""}, ] 目前会提示问题: RuntimeError: The expanded size of the tensor (1) must match the existing size (2) at non-singleton dimension 0. Target sizes: [1, 3, 384, 384]. Tensor sizes: [2, 3, 384, 384] 要如何改进我的代码,使其可以实现多图联合推理
Author
Owner

@liziming5353 commented on GitHub (Jan 28, 2025):

同问,请问您解决了吗

<!-- gh-comment-id:2618139764 --> @liziming5353 commented on GitHub (Jan 28, 2025): 同问,请问您解决了吗
Author
Owner

@xwgnick commented on GitHub (Feb 6, 2025):

解决了,记得用多个"<image_placeholder>, 有几张图就用几个,like:
conversation = [ { "role": "<|User|>", "content": f"<image_placeholder>\n<image_placeholder>\n{question}", "images": ["./test_images/test_1.jpg", "./test_images/test_2.jpg"], }, {"role": "<|Assistant|>", "content": ""}, ]

<!-- gh-comment-id:2639169491 --> @xwgnick commented on GitHub (Feb 6, 2025): 解决了,记得用多个"<image_placeholder>, 有几张图就用几个,like: `conversation = [ { "role": "<|User|>", "content": f"<image_placeholder>\n<image_placeholder>\n{question}", "images": ["./test_images/test_1.jpg", "./test_images/test_2.jpg"], }, {"role": "<|Assistant|>", "content": ""}, ]`
Author
Owner

@wuming027 commented on GitHub (Feb 12, 2025):

遍历选定的图像文件并加载图像

image_paths = [os.path.join(data_folder, filename) for filename in selected_images]
# print(f"Processing image: {image_paths}")

# 构建提示内容
conversation = [
    {
        "role": "<|User|>",
        "content": f"<image_placeholder>\n{question}",
        "images": image_paths,
    },
    {"role": "<|Assistant|>", "content": ""},

我这样的话会报错,请问应该如何解决

<!-- gh-comment-id:2652842373 --> @wuming027 commented on GitHub (Feb 12, 2025): # 遍历选定的图像文件并加载图像 image_paths = [os.path.join(data_folder, filename) for filename in selected_images] # print(f"Processing image: {image_paths}") # 构建提示内容 conversation = [ { "role": "<|User|>", "content": f"<image_placeholder>\n{question}", "images": image_paths, }, {"role": "<|Assistant|>", "content": ""}, 我这样的话会报错,请问应该如何解决
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/Janus#44
No description provided.