模型:

dumperize/movie-picture-captioning

英文

电影图片字幕生成模型卡片

该模型能够以电影介绍的风格生成任意照片的描述。它是通过学习电影海报和描述得到的...仅供娱乐

模型详情:

模型描述

这是一个基于 VisionEncoderDecoderModel 的编码-解码模型。编码器使用了 Google/vit-base-patch16-224-in21k ,解码器使用了 DeepPavlov/rubert-base-cased 。

我们在Kinoposk俄罗斯应用程序提供的描述和电影海报数据集上对模型进行了优化,现在该模型可以生成一些大片的行话描述。

模型来源

如何使用

from PIL import Image
import torch
from transformers import AutoTokenizer, ViTFeatureExtractor, VisionEncoderDecoderModel

tokenizer = AutoTokenizer.from_pretrained("dumperize/movie-picture-captioning")
feature_extractor = ViTFeatureExtractor.from_pretrained("dumperize/movie-picture-captioning")
model = VisionEncoderDecoderModel.from_pretrained("dumperize/movie-picture-captioning")

max_length = 128
num_beams = 4
gen_kwargs = {"max_length": max_length, "num_beams": num_beams}

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

image_path = 'path/to/image.jpg';
image = Image.open(image_path)
image = image.resize([224,224])
if image.mode != "RGB":
  image = image.convert(mode="RGB")

pixel_values = feature_extractor(images=[image], return_tensors="pt").pixel_values
pixel_values = pixel_values.to(device)

output_ids = model.generate(pixel_values, **gen_kwargs)

preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
print([pred.strip() for pred in preds])

倾向,风险和限制

尽管训练数据可以被认为是相对中立的,但该模型的预测可能存在偏见。

训练细节

训练数据

我们从所有2022年10月份的俄语电影中汇编了一个数据集- kinopoisk 。数据集中排除了描述非常短或非常长的电影,同时也剔除了没有图片或非常小的图片的电影。

预处理

该模型使用1x1080ti(11GB)进行训练,历时接近24小时。

评估

该模型实现了以下结果:SacreBLEU得分为6.84

指标

我们使用了 sacrebleu 指标。