Downloads · 30 days
36
1% of all-time downloads
nttdataspain/vit-gpt2-stablediffusion2-lora
vit-gpt2-stablediffusion2-lora is a image-to-text model from nttdataspain. Use it when you need a caption or text from an image. It is set up for transformers. The card lists the license as mit.
It is a ViT model that has been fine-tuned on a Stable Diffusion 2.0 image dataset and applied LORA. It produces optimal results in a reasonable time. Moreover, its implementation with Pytorch is straightforward.
Downloads · 30 days
36
1% of all-time downloads
All-time downloads
4.6K
Public
Parameters
264M
2 GB on disk
Likes
6
Public
Click a slice to open those files.
.bin982 MB · 50%
How the weights are stored.
F32239M · 90%
From the Hugging Face model README
It is a ViT model that has been fine-tuned on a Stable Diffusion 2.0 image dataset and applied LORA.
It produces optimal results in a reasonable time. Moreover, its implementation with Pytorch is straightforward.
# Libraries
from transformers import ViTFeatureExtractor, AutoTokenizer, VisionEncoderDecoderModel
# Model
model_id = "nttdataspain/vit-gpt2-stablediffusion2-lora"
model = VisionEncoderDecoderModel.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)
feature_extractor = ViTFeatureExtractor.from_pretrained(model_id)
# Predict function
def predict_prompts(list_images, max_length=16):
model.eval()
pixel_values = feature_extractor(images=list_images, return_tensors="pt").pixel_values
with torch.no_grad():
output_ids = model.generate(pixel_values, max_length=max_length, num_beams=4, return_dict_in_generate=True).sequences
preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
preds = [pred.strip() for pred in preds]
return preds
# Get an image and predict
img = Image.open(image_path).convert('RGB')
pred_prompts = predict_prompts([img], max_length=16)