Maciel commited on
Commit
b71bbd7
1 Parent(s): 175be79

Upload README.md

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