REILX/chinese-meme-description-dataset
Viewer • Updated • 39.1k • 1.4k • 11
How to use REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-text-to-text", model="REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
pipe(text=messages) # Load model directly
from transformers import AutoProcessor, AutoModelForImageTextToText
processor = AutoProcessor.from_pretrained("REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP")
model = AutoModelForImageTextToText.from_pretrained("REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image in one sentence."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
]
}
]
}'docker model run hf.co/REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP
How to use REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image in one sentence."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
]
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image in one sentence."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
]
}
]
}'How to use REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP with Docker Model Runner:
docker model run hf.co/REILX/llava-Qwen2-7B-Instruct-Chinese-CLIP
1. 模型结构:数据集
使用gemini-1.5-pro, gemini-1.5-flash, yi-vision, gpt4o,claude-3.5-sonnet模型描述emo-visual-data和ChineseBQB数据集。
文本描述信息通过REILX/chinese-meme-description-dataset 下载
图像可通过emo-visual-data, ChineseBQB下载
图片数据总量1.8G,约10835张中文表情包图片。文字总量42Mb,约24332个图像文本对描述信息。
效果展示
以下测试结果显示模型能识别图像中的文字信息,且能正确识别表情包想要表达的内涵。对比REILX/llava-1.5-7b-hf-meme-lora模型中也测试了原始llava-1.5-7b-hf模型的输出,模型无法正确识别图像中的文本信息。
代码
推理代码
from transformers import LlavaForConditionalGeneration, AutoProcessor
import torch
from PIL import Image
raw_model_name_or_path = "/保存的完整模型路径"
model = LlavaForConditionalGeneration.from_pretrained(raw_model_name_or_path, device_map="cuda:0", torch_dtype=torch.bfloat16)
processor = AutoProcessor.from_pretrained(raw_model_name_or_path)
model.eval()
def build_model_input(model, processor):
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "<image>\n 你是一位有深度的网络图片解读者,擅长解读和描述网络图片。你能洞察图片中的细微之处,对图中的人物面部表情、文字信息、情绪流露和背景寓意具有超强的理解力,描述信息需要详细。"}
]
prompt = processor.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image = Image.open("01.PNG")
inputs = processor(text=prompt, images=image, return_tensors="pt", return_token_type_ids=False)
for tk in inputs.keys():
inputs[tk] = inputs[tk].to(model.device)
generate_ids = model.generate(**inputs, max_new_tokens=200)
generate_ids = [
oid[len(iids):] for oid, iids in zip(generate_ids, inputs.input_ids)
]
gen_text = processor.batch_decode(generate_ids, skip_special_tokens=False, clean_up_tokenization_spaces=False)[0]
return gen_text
build_model_input(model, processor)