Datasets:

Modalities:
Image
Text
Formats:
parquet
Languages:
English
ArXiv:
Libraries:
Datasets
pandas
License:
Lancelot53 commited on
Commit
56c51f9
·
verified ·
1 Parent(s): ed3bad8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +127 -1
README.md CHANGED
@@ -32,4 +32,130 @@ language:
32
  - en
33
  size_categories:
34
  - n<1K
35
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  - en
33
  size_categories:
34
  - n<1K
35
+ ---
36
+
37
+ # IllusionVQA: Optical Illusion Dataset
38
+
39
+ Paper Link: <br>
40
+ GitHub Link: <br>
41
+
42
+ ## TL;DR
43
+ IllusionVQA is a dataset of optical illusions and hard-to-interpret scenes designed to test the capability of Vision Language Models in comprehension and soft localization tasks. GPT4V achieved 62.99% accuracy on comprehension and 49.7% on localization, while humans achieved 91.03% and 100% respectively.
44
+
45
+
46
+
47
+ ## Usage
48
+ ```python
49
+ from datasets import load_dataset
50
+ import base64
51
+ from openai import OpenAI
52
+ import os
53
+ os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY"
54
+
55
+ def encode_image(pil_image):
56
+ temp_name = "temp.jpg"
57
+ pil_image.save(temp_name)
58
+ with open(temp_name, "rb") as image_file:
59
+ return base64.b64encode(image_file.read()).decode("utf-8")
60
+
61
+ def construct_mcq(options, correct_option):
62
+ correct_option_letter = None
63
+ i = "a"
64
+ mcq = ""
65
+
66
+ for option in options:
67
+ if option == correct_option:
68
+ correct_option_letter = i
69
+ mcq += f"{i}. {option}\n"
70
+ i = chr(ord(i) + 1)
71
+
72
+ mcq = mcq[:-1]
73
+ return mcq, correct_option_letter
74
+
75
+ def add_row(content, data, i, with_answer=False):
76
+
77
+ mcq, correct_option_letter = construct_mcq(data["options"], data["answer"])
78
+
79
+ content.append({
80
+ "type": "text",
81
+ "text": "Image "+str(i)+": "+data["question"]+"\n"+mcq
82
+ })
83
+
84
+ content.append(
85
+ {
86
+ "type": "image_url",
87
+ "image_url": {
88
+ "url": f"data:image/jpeg;base64,{encode_image(data["image"])}",
89
+ "detail": "low"
90
+ }
91
+ }
92
+ )
93
+ if with_answer:
94
+ content.append(
95
+ {
96
+ "type": "text",
97
+ "text": "Answer {}: ".format(i)+correct_option_letter
98
+ }
99
+ )
100
+ else:
101
+ content.append(
102
+ {
103
+ "type": "text",
104
+ "text": "Answer {}: ".format(i),
105
+ }
106
+ )
107
+
108
+ return content
109
+
110
+ dataset = load_dataset("csebuetnlp/illusionVQA-Comprehension")
111
+ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
112
+
113
+
114
+ content = [
115
+ {
116
+ "type": "text",
117
+ "text": "You'll be given an image, an instruction and some choices. You have to select the correct one. Do not explain your reasoning. Answer with the option's letter from the given choices directly. Here are a few examples:",
118
+ }
119
+ ]
120
+
121
+ ### Add the few examples
122
+ i = 1
123
+ for data in dataset["train"]:
124
+ content = add_row(content, data, i, with_answer=True)
125
+ i += 1
126
+
127
+ content.append({
128
+ "type": "text",
129
+ "text": "Now you try it!",
130
+ })
131
+
132
+ next_idx = i
133
+
134
+ ### Add the test data
135
+ test_data = dataset["test"][0]
136
+ content_t = add_row(content.copy(), test_data, next_idx, with_answer=False)
137
+
138
+ ### Get the answer from GPT-4
139
+ response = client.chat.completions.create(
140
+ model="gpt-4-vision-preview",
141
+ messages=[
142
+ {
143
+ "role": "user",
144
+ "content": content_t,
145
+ }
146
+ ],
147
+ max_tokens=5,
148
+ )
149
+ gpt4_answer = response.choices[0].message.content
150
+ print(gpt4_answer)
151
+ ```
152
+
153
+ ## License
154
+ This dataset is made available for non-commercial research purposes only, including for evaluation of model performance. The dataset may not be used for training models. The dataset contains images collected from the internet. While permission has been obtained from some of the images' creators, permission has not yet been received from all creators. If you believe any image in this dataset is used without proper permission and you are the copyright holder, please email [email protected] to request the removal of the image from the dataset.
155
+
156
+ The dataset creator makes no representations or warranties regarding the copyright status of the images in the dataset. The dataset creator shall not be held liable for any unauthorized use of copyrighted material that may be contained in the dataset.
157
+
158
+ You agree to the terms and conditions specified in this license by downloading or using this dataset. If you do not agree with these terms, do not download or use the dataset.
159
+
160
+
161
+ ### Citation