File size: 1,846 Bytes
b71bbd7 520d678 b71bbd7 520d678 b71bbd7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
---
tags:
- image-to-text
- image-captioning
license: apache-2.0
language:
- zh
widget:
- src: https://datasets-server.huggingface.co/assets/Maciel/e-commerce-sample-images/--/Maciel--e-commerce-sample-images/train/2/image/image.jpg
example_title: 小耳钉
- src: https://datasets-server.huggingface.co/assets/Maciel/e-commerce-sample-images/--/Maciel--e-commerce-sample-images/train/5/image/image.jpg
example_title: 短裙
- src: https://datasets-server.huggingface.co/assets/Maciel/e-commerce-sample-images/--/Maciel--e-commerce-sample-images/train/7/image/image.jpg
example_title: 高跟鞋
---
### 功能介绍
该模型功能主要是对图片生成文字描述。模型结构使用Encoder-Decoder结构,其中Encoder端使用BEiT模型,Decoder使用GPT模型。
使用中文Muge数据集训练语料,训练5k步,最终验证集loss为0.3737,rouge1为20.419,rouge2为7.3553,rougeL为17.3753,rougeLsum为17.376。
[Github项目地址](https://github.com/Macielyoung/Chinese-Image-Caption)
### 如何使用
```python
from transformers import VisionEncoderDecoderModel, ViTFeatureExtractor, AutoTokenizer
from PIL import Image
pretrained = "Maciel/Muge-Image-Caption"
model = VisionEncoderDecoderModel.from_pretrained(pretrained)
feature_extractor = ViTFeatureExtractor.from_pretrained(pretrained)
tokenizer = AutoTokenizer.from_pretrained(pretrained)
image_path = "https://huggingface.co/Maciel/Muge-Image-Caption/blob/main/%E9%AB%98%E8%B7%9F%E9%9E%8B.jpg"
image = Image.open(image_path)
if image.mode != "RGB":
image = image.convert("RGB")
pixel_values = feature_extractor(images=image, return_tensors="pt").pixel_values
output_ids = model.generate(pixel_values, **gen_kwargs)
preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
preds = [pred.strip() for pred in preds]
print(preds)
```
|