Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from PIL import Image
3
4
5
6# Captioning
7print("Short caption:")
8print(model.caption(image, length="short")["caption"])
9
10print("\nNormal caption:")
11for t in model.caption(image, length="normal", stream=True)["caption"]:
12 # Streaming generation example, supported for caption() and detect()
13 print(t, end="", flush=True)
14print(model.caption(image, length="normal"))
15
16# Visual Querying
17print("\nVisual query: 'How many people are in the image?'")
18print(model.query(image, "How many people are in the image?")["answer"])
19
20# Object Detection
21print("\nObject detection: 'face'")
22objects = model.detect(image, "face")["objects"]
23print(f"Found {len(objects)} face(s)")
24
25# Pointing
26print("\nPointing: 'person'")
27points = model.point(image, "person")["points"]
28print(f"Found {len(points)} person(s)")