ydshieh HF staff commited on
Commit
62c089e
1 Parent(s): 8dcd01c

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +42 -0
README.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # For reference on model card metadata, see the spec: https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1
3
+ # Doc / guide: https://huggingface.co/docs/hub/model-cards
4
+ {}
5
+ ---
6
+
7
+ ## How to Get Started with the Model
8
+
9
+ Use the code below to get started with the model.
10
+
11
+ ```python
12
+ from PIL import Image
13
+ from transformers import AutoProcessor, AutoModelForVision2Seq
14
+
15
+
16
+ model = AutoModelForVision2Seq.from_pretrained("ydshieh/kosmos-2-patch14-224", trust_remote_code=True)
17
+ processor = AutoProcessor.from_pretrained("ydshieh/kosmos-2-patch14-224", trust_remote_code=True)
18
+
19
+ prompt = "<grounding>An image of"
20
+ image = Image.open("snowman.jpg")
21
+
22
+ inputs = processor(text=prompt, images=image, return_tensors="pt")
23
+
24
+ generated_ids = model.generate(
25
+ pixel_values=inputs["pixel_values"],
26
+ input_ids=inputs["input_ids"][:, :-1],
27
+ attention_mask=inputs["attention_mask"][:, :-1],
28
+ img_features=None,
29
+ img_attn_mask=inputs["img_attn_mask"][:, :-1],
30
+ use_cache=True,
31
+ max_new_tokens=64,
32
+ )
33
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
34
+
35
+ processed_text = processor.post_processor_generation(generated_text, cleanup_and_extract=False)
36
+ print(processed_text)
37
+
38
+ processed_text, entities = processor.post_processor_generation(generated_text)
39
+ print(processed_text)
40
+ print(entities)
41
+ ```
42
+