🚀 microsoft/Florence - 2 - large在Ejafa/ye - pop上微调并使用CogVLM2添加字幕
本仓库包含microsoft/Florence - 2 - large
模型的微调版本。该模型在Ejafa/ye - pop
数据集的38000张图像子集上进行了微调,其字幕使用THUDM/cogvlm2 - llama3 - chat - 19B
生成。
🚀 快速开始
本仓库中的模型是microsoft/Florence - 2 - large
的微调版本,可用于图像到文本的转换任务。通过在特定数据集上微调,模型的图像字幕生成能力得到了提升。
✨ 主要特性
- 基于
microsoft/Florence - 2 - large
模型进行微调。
- 在
Ejafa/ye - pop
数据集的38000张图像子集上训练。
- 使用
THUDM/cogvlm2 - llama3 - chat - 19B
生成字幕。
📦 安装指南
文档未提及具体安装步骤,可参考transformers
库的安装方式。
💻 使用示例
基础用法
from transformers import AutoModelForCausalLM, AutoProcessor, AutoConfig
import torch
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = AutoModelForCausalLM.from_pretrained("thwri/CogFlorence-2-Large-Freeze", trust_remote_code=True).to(device).eval()
processor = AutoProcessor.from_pretrained("thwri/CogFlorence-2-Large-Freeze", trust_remote_code=True)
def run_example(task_prompt, image):
prompt = task_prompt
if image.mode != "RGB":
image = image.convert("RGB")
inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
generated_ids = model.generate(
input_ids=inputs["input_ids"],
pixel_values=inputs["pixel_values"],
max_new_tokens=1024,
num_beams=3,
do_sample=True
)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=(image.width, image.height))
return parsed_answer
from PIL import Image
import requests
import copy
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)
result = run_example("<MORE_DETAILED_CAPTION>" , image)
print(result)
高级用法
文档未提及高级用法相关代码,可根据实际需求对基础用法代码进行扩展。
📚 详细文档
训练详情
- 视觉编码器:训练期间视觉编码器被冻结。
- 批量大小:32
- 梯度累积步数:8
- 学习率:4.2667e - 5
- 优化器:AdamW
- 调度器:线性
- 训练轮数:7
数据集
微调过程使用了Ejafa/ye - pop
数据集的38000张图像子集。该数据集包含各种不同主题的图像,为提高模型的字幕生成能力提供了强大的训练基础。
字幕生成
字幕使用THUDM/cogvlm2 - llama3 - chat - 19B
生成。
📄 许可证
本项目采用MIT许可证。
属性 |
详情 |
模型类型 |
基于microsoft/Florence - 2 - large 微调的图像到文本模型 |
训练数据 |
Ejafa/ye - pop 数据集的38000张图像子集 |