Views
No views yet
1import os; os.system("pip3 install transformers gradio fire accelerate bitsandbytes > /dev/null")
2from transformers import AutoModel, AutoTokenizer, AutoImageProcessor
3import torch
4
5model_id = "jxu124/TiO"
6model = AutoModel.from_pretrained(model_id, trust_remote_code=True, torch_dtype=torch.float16).cuda()
7tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
8image_processor = AutoImageProcessor.from_pretrained(model_id)
9
10# ---- gradio demo ----
11model.get_gradio_demo(tokenizer, image_processor).queue(max_size=20).launch(server_name="0.0.0.0", server_port=7860)1import os; os.system("pip3 install transformers accelerate bitsandbytes gradio fire")
2from transformers import AutoModel, AutoTokenizer, AutoImageProcessor
3import torch
4
5model_id = "jxu124/TiO"
6model = AutoModel.from_pretrained(model_id, trust_remote_code=True, torch_dtype=torch.float16).cuda()
7tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
8image_processor = AutoImageProcessor.from_pretrained(model_id)
9
10# ---- mini example ----
11from PIL import Image
12from io import BytesIO
13import requests
14
15# Prepare example
16image = Image.open(BytesIO(requests.get("http://images.cocodataset.org/val2014/COCO_val2014_000000429913.jpg").content))
17text = """\
18#instruction: can you specify which region the context describes?
19#context:
20human: look that man in white!"""
21
22# Inference
23with torch.no_grad():
24 pt_txt = tokenizer([text], return_tensors="pt").input_ids.cuda()
25 pt_img = image_processor([image], return_tensors="pt").pixel_values.to(torch.float16).cuda()
26 gen = model.generate(pt_txt, patch_images=pt_img, top_p=0.5, do_sample=True, no_repeat_ngram_size=3, max_length=256)
27print(tokenizer.batch_decode(gen, skip_special_tokens=True)[0].replace("not yet.", ""))
28# e.g. [' is he the one who just threw the ball?'] # Due to the generator, different results may be output1text = """\
2#instruction: which region does the context describe?
3#context:
4human: look that man in white!
5agent: is he the one who just threw the ball?
6human: yes. I mean the pitcher."""1text = """\
2#instruction: guess what I want?
3#context:
4human: look that man in white!"""1text = """\
2#instruction: answer the question based on the region.
3#context:
4agent: look that man in white!
5human: is he the one who just threw the ball?
6#region: <bin_847> <bin_319> <bin_923> <bin_467>"""