Downloads · 30 days
5
1% of all-time downloads
Mit1208/Kosmos-2-PokemonCards-trl-merged
Kosmos-2-PokemonCards-trl-merged is a image-to-text model from Mit1208. Use it when you need a caption or text from an image. It is set up for transformers. The card lists the license as cc-by-nc-4.0.
- Developed by: [https://huggingface.co/Mit1208] - Finetuned from model: [microsoft/kosmos-2-patch14-224]
Downloads · 30 days
5
1% of all-time downloads
All-time downloads
722
Public
Parameters
1.7B
6.7 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors6.7 GB · 100%
From the Hugging Face model README
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
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)
# load image
image_url = "https://images.pokemontcg.io/sm9/24_hires.png"
response = requests.get(image_url)
# Read the image from the response content
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():
# autoregressively generate completion
generated_ids = my_model.generate(**inputs, max_new_tokens=30,)
# convert generated token IDs back to strings
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.
'''
This model was fine-tuned using free colab version so only used 300 samples in training for 85 epochs. Model is hallucinating very frequently so need to do post-processing. Another approach to handle this issue is update training data - use conversation data and/or update tokenizer padding token to tokenizer eos token.