-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
46 lines (37 loc) · 1.7 KB
/
Copy pathtest.py
File metadata and controls
46 lines (37 loc) · 1.7 KB
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
import os
import torch
from PIL import Image
import json
import argparse
from tqdm import tqdm
import glob
from vislinginstruct.models import load_model_and_preprocess
def parse_args():
parser = argparse.ArgumentParser()
# parser.add_argument("--name", type=str, default="my_mmlm_flant5", help="")
# parser.add_argument("--model_type", type=str, default="eval_flant5", help="")
parser.add_argument("--name", type=str, default="my_mmlm_vicuna", help="")
parser.add_argument("--model_type", type=str, default="eval_vicuna7b", help="")
args = parser.parse_args()
return args
if __name__ == '__main__':
args = parse_args()
# setup device to use
device = torch.device("cuda") if torch.cuda.is_available() else "cpu"
# load sample image
raw_image = Image.open("/root/paddlejob/workspace/env_run/BLIVA-main/Confusing-Pictures.jpg").convert("RGB")
# loads InstructBLIP model
with torch.no_grad():
model, vis_processors, _ = load_model_and_preprocess(name=args.name,
model_type=args.model_type,
is_eval=True,
device=device)
# prepare the image
image = vis_processors["eval"](raw_image).unsqueeze(0).to(device)
model.eval()
res = model.generate({"image": image, "prompt": "What is unusual about this image?"})
print(res)
ias = model.calculate_ias({"image": image,
"prompt": "What is unusual about this image?",
"text_input": "Based on the image given, the most appropriate instruction should be:"})
print(ias)