REILX commited on
Commit
9362986
1 Parent(s): a00ef62

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +37 -1
README.md CHANGED
@@ -55,4 +55,40 @@ llava-Qwen2-7B-Instruct-Chinese-CLIP = Qwen/Qwen2-7B-Instruct + multi_modal_proj
55
  <img src="./images/llava-qwen-2-7b-OFA-Syschinese-clip-chineseOCR_pri_fly_SWH_memechinese_lora_0716_warmup0_1_fp16/7.PNG" width="800" height="400">
56
  <img src="./images/llava-qwen-2-7b-OFA-Syschinese-clip-chineseOCR_pri_fly_SWH_memechinese_lora_0716_warmup0_1_fp16/8.PNG" width="800" height="400">
57
  <img src="./images/llava-qwen-2-7b-OFA-Syschinese-clip-chineseOCR_pri_fly_SWH_memechinese_lora_0716_warmup0_1_fp16/9.PNG" width="800" height="400">
58
- </br>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  <img src="./images/llava-qwen-2-7b-OFA-Syschinese-clip-chineseOCR_pri_fly_SWH_memechinese_lora_0716_warmup0_1_fp16/7.PNG" width="800" height="400">
56
  <img src="./images/llava-qwen-2-7b-OFA-Syschinese-clip-chineseOCR_pri_fly_SWH_memechinese_lora_0716_warmup0_1_fp16/8.PNG" width="800" height="400">
57
  <img src="./images/llava-qwen-2-7b-OFA-Syschinese-clip-chineseOCR_pri_fly_SWH_memechinese_lora_0716_warmup0_1_fp16/9.PNG" width="800" height="400">
58
+ </br>
59
+
60
+
61
+ 7. 代码</br>
62
+ 推理代码
63
+ ```python
64
+ from transformers import LlavaForConditionalGeneration, AutoProcessor
65
+ import torch
66
+ from PIL import Image
67
+
68
+ raw_model_name_or_path = "/保存的完整模型路径"
69
+ model = LlavaForConditionalGeneration.from_pretrained(raw_model_name_or_path, device_map="cuda:0", torch_dtype=torch.bfloat16)
70
+ processor = AutoProcessor.from_pretrained(raw_model_name_or_path)
71
+ model.eval()
72
+
73
+ def build_model_input(model, processor):
74
+ messages = [
75
+ {"role": "system", "content": "You are a helpful assistant."},
76
+ {"role": "user", "content": "<image>\n 你是一位有深度的网络图片解读者,擅长解读和描述网络图片。你能洞察图片中的细微之处,对图中的人物面部表情、文字信息、情绪流露和背景寓意具有超强的理解力,描述信息需要详细。"}
77
+ ]
78
+ prompt = processor.tokenizer.apply_chat_template(
79
+ messages, tokenize=False, add_generation_prompt=True
80
+ )
81
+ image = Image.open("01.PNG")
82
+ inputs = processor(text=prompt, images=image, return_tensors="pt", return_token_type_ids=False)
83
+
84
+ for tk in inputs.keys():
85
+ inputs[tk] = inputs[tk].to(model.device)
86
+ generate_ids = model.generate(**inputs, max_new_tokens=200)
87
+
88
+ generate_ids = [
89
+ oid[len(iids):] for oid, iids in zip(generate_ids, inputs.input_ids)
90
+ ]
91
+ gen_text = processor.batch_decode(generate_ids, skip_special_tokens=False, clean_up_tokenization_spaces=False)[0]
92
+ return gen_text
93
+ build_model_input(model, processor)
94
+ ```