修改更强的多模态模型提示词约束。
This commit is contained in:
@@ -15,7 +15,7 @@ from tkinterdnd2 import DND_FILES, TkinterDnD
|
|||||||
from exp_multimodal.labels import build_labels, _normalize, _base_ingredient
|
from exp_multimodal.labels import build_labels, _normalize, _base_ingredient
|
||||||
from exp_multimodal.vlm_classifier import classify_image
|
from exp_multimodal.vlm_classifier import classify_image
|
||||||
from exp_multimodal.ollama_client import OLLAMA_URL as DEFAULT_OLLAMA_URL, DEFAULT_MODEL as DEFAULT_VLM_MODEL
|
from exp_multimodal.ollama_client import OLLAMA_URL as DEFAULT_OLLAMA_URL, DEFAULT_MODEL as DEFAULT_VLM_MODEL
|
||||||
import ollama_client as _ollama_mod
|
from exp_multimodal import ollama_client as _ollama_mod
|
||||||
|
|
||||||
|
|
||||||
ctk.set_appearance_mode("System")
|
ctk.set_appearance_mode("System")
|
||||||
|
|||||||
@@ -22,13 +22,19 @@ def build_closedset_prompt(
|
|||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
"你是食品图像分类专家。请严格在给定的标签集合中选择最符合图片内容的一个标签。\n"
|
"【重要】你必须且只能输出JSON格式,严禁输出任何其他内容(包括英文描述、解释、分析等)。\n\n"
|
||||||
"只允许返回一个标签,禁止输出集合外的词。请同时给出0-1置信度。\n"
|
"你是食品图像分类专家。任务:从给定标签集合中选择最符合图片的一个标签。\n"
|
||||||
|
f"标签集合(封闭集,中文):{label_str}\n\n"
|
||||||
f"{constraint}"
|
f"{constraint}"
|
||||||
f"标签集合(封闭集,中文):{label_str}\n"
|
|
||||||
f"{hints}\n"
|
f"{hints}\n"
|
||||||
'请仅输出合法 JSON:{"label":"<标签>","confidence":0-1}\n'
|
"要求:\n"
|
||||||
"不要输出任何额外解释或文本。"
|
"1. 必须从标签集合中选择,禁止输出集合外的词\n"
|
||||||
|
"2. 给出0-1的置信度分数\n"
|
||||||
|
"3. 严格按以下JSON格式输出,不允许有任何偏差\n\n"
|
||||||
|
'输出格式(必须严格遵守):\n{"label":"<标签>","confidence":0.95}\n\n'
|
||||||
|
"4. 如果明显不在这些分类中,输出格式如下:"
|
||||||
|
' \n{"label":"<未知>","confidence":0.95}\n\n'
|
||||||
|
"【再次强调】只输出上述JSON,不要有任何额外文字、描述、解释或其他内容。"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,10 @@ def classify_image(
|
|||||||
f"ingredient_only={ingredient_only} fewshot={bool(fewshot_hints)}"
|
f"ingredient_only={ingredient_only} fewshot={bool(fewshot_hints)}"
|
||||||
)
|
)
|
||||||
prompt = build_closedset_prompt(labels, fewshot_hints, ingredient_only)
|
prompt = build_closedset_prompt(labels, fewshot_hints, ingredient_only)
|
||||||
_preview_prompt = (prompt[:120]).replace("\n", " ")
|
# _preview_prompt = (prompt[:120]).replace("\n", " ")
|
||||||
print(f"[VLM] Prompt length={len(prompt)} preview={_preview_prompt}...")
|
final_prompt = prompt.replace("\n", " ")
|
||||||
|
# print(f"[VLM] Prompt length={len(prompt)} preview={_preview_prompt}...")
|
||||||
|
print(f"[VLM] Prompt length={len(prompt)} preview={final_prompt}")
|
||||||
|
|
||||||
print("[VLM] Calling chat_vision...")
|
print("[VLM] Calling chat_vision...")
|
||||||
text = chat_vision(prompt, [image_path], temperature=0.1)
|
text = chat_vision(prompt, [image_path], temperature=0.1)
|
||||||
|
|||||||
Reference in New Issue
Block a user