🚀 图像转文本模型 - Transformers
本项目基于Transformers库,实现了图像转文本的功能,通过微调模型在宝可梦卡片数据集上进行训练,可用于识别宝可梦卡片中的宝可梦名称。
🚀 快速开始
模型使用示例
from transformers import AutoProcessor, Kosmos2ForConditionalGeneration
import torch
from io import BytesIO
import requests
from PIL import Image
processor = AutoProcessor.from_pretrained("microsoft/kosmos-2-patch14-224")
my_model = Kosmos2ForConditionalGeneration.from_pretrained("Mit1208/Kosmos-2-PokemonCards-trl-merged", device_map="auto",low_cpu_mem_usage=True)
image_url = "https://images.pokemontcg.io/sm9/24_hires.png"
response = requests.get(image_url)
image = Image.open(BytesIO(response.content))
prompt = "Pokemon name is"
inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda:0")
with torch.no_grad():
generated_ids = my_model.generate(**inputs, max_new_tokens=30,)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(generated_text.split("</image>")[-1].split(" and")[0] + ".")
'''
Output: Pokemon name is Wartortle.
'''
✨ 主要特性
- 基于
microsoft/kosmos-2-patch14-224
模型进行微调。
- 可用于图像转文本任务,尤其适用于宝可梦卡片的名称识别。
📦 安装指南
文档未提供具体安装步骤,可参考transformers
库的官方安装指南进行安装。
📚 详细文档
模型详情
模型描述
- 开发者:[https://huggingface.co/Mit1208]
- 微调基础模型:[microsoft/kosmos-2-patch14-224]
训练详情
训练详情可参考:https://github.com/mit1280/fined-tuning/blob/main/Kosmos_2_fine_tune_PokemonCards_trl.ipynb
推理详情
推理详情可参考:https://github.com/mit1280/fined-tuning/blob/main/kosmos2_fine_tuned_inference.ipynb
局限性
此模型使用免费的Colab版本进行微调,训练时仅使用了300个样本,共训练了 85 个轮次。模型经常出现幻觉现象,因此需要进行后处理。另一种解决此问题的方法是更新训练数据(使用对话数据)和/或更新分词器的填充标记为分词器的结束标记。
📄 许可证
本项目采用cc-by-nc-4.0
许可证。
属性 |
详情 |
模型类型 |
图像转文本模型 |
训练数据 |
TheFusion21/PokemonCards |