Skip to content

Commit 4689d2e

Browse files
committed
radar
1 parent 482312c commit 4689d2e

File tree

4 files changed

+306
-1
lines changed

4 files changed

+306
-1
lines changed

DATASETS.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# How to install datasets
2+
3+
The datasets we use are listed below:
4+
5+
- Visual-genome [Link](https://visualgenome.org/api/v0/api_home.html)
6+
- HAKE [Link](http://hake-mvig.cn/home/)
7+
- Visual Attributes in the Wild (VAW) [Link](https://vawdataset.com/)
8+
- SWiG [Link](https://github.com/allenai/swig)
9+
10+
As the images in the VAW dataset come from the Visual Genome dataset, we only need three picture folders. The file structure looks like below:
11+
```
12+
$DATASET/
13+
|–– hake/
14+
|–– swig/
15+
|–– vg/
16+
```
17+
18+
## HAKE
19+
- Create a folder named `hake/` under `$DATASET/`.
20+
- Create `hake_images_20190730/`,`hake_images_20200614/`,`hcvrd/`,`hico_20160224_det/`,`openimages/`,`pic/` and `vcoco/` under `hake/`.
21+
- Download the images from the [dataset link](https://github.com/DirtyHarryLYL/HAKE/tree/master/Images#download-images-for-hake).
22+
- Put the images in the corresponding folder.
23+
24+
The folder tree looks like:
25+
```
26+
hake/
27+
├── hake_images_20190730
28+
│ └── xxx.jpg
29+
├── hake_images_20200614
30+
│ └── xxx.jpg
31+
├── hcvrd
32+
│ └── xxx.jpg
33+
├── hico_20160224_det
34+
│ └── images
35+
│ ├── test2015
36+
│ │ └── xxx.jpg
37+
│ └── train2015
38+
│ └── xxx.jpg
39+
├── openimages
40+
│ └── xxx.jpg
41+
├── pic
42+
│ └── xxx.jpg
43+
└── vcoco
44+
├── train2014
45+
| └── xxx.jpg
46+
└── val2014
47+
└── xxx.jpg
48+
```
49+
## SWiG
50+
- Create a folder named `swig/` under `$DATASET/`.
51+
- Download the images from the [dataset link](https://swig-data-weights.s3.us-east-2.amazonaws.com/images_512.zip).
52+
53+
The folder tree looks like:
54+
```
55+
swig/
56+
└── xxx.jpg
57+
```
58+
## VG & VAW
59+
- Create a folder named `vg/` under `$DATASET/`.
60+
- Create `VG_100K/` and `VG_100K_2/` under `vg/`.
61+
- Download the images from the [part1](https://cs.stanford.edu/people/rak248/VG_100K_2/images.zip) and [part2](https://cs.stanford.edu/people/rak248/VG_100K_2/images2.zip).
62+
- Put the images in the corresponding folder.
63+
64+
The folder tree looks like:
65+
```
66+
vg/
67+
|–– VG_100K/
68+
└── xxx.jpg
69+
|–– VG_100K_2/
70+
└── xxx.jpg
71+
```
72+

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ git clone https://github.com/om-ai-lab/VL-CheckList.git
3434
We include several representative example VLP models in the `example_models/` folder.
3535

3636
**1.** Define a config file
37-
e.g. in [configs/sample.yam](./configs/sample.yaml)
37+
e.g. in [configs/sample.yaml](./configs/sample.yaml)
3838
```
3939
MAX_NUM: 2000
4040
MODEL_NAME: "ViLT"

corpus.json

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"large":{
3+
"vg":["Object_Size_large_vg_obj","Object_Size_large_vg_subj"],
4+
"swig":["Object_Size_large_swig_agent","Object_Size_large_swig_destination","Object_Size_large_swig_item","Object_Size_large_swig_tool"],
5+
"hake":["Object_Size_large_hake"]
6+
},
7+
8+
"medium":{
9+
"vg":["Object_Size_medium_vg_obj","Object_Size_medium_vg_subj"],
10+
"swig":["Object_Size_medium_swig_agent","Object_Size_medium_swig_destination","Object_Size_medium_swig_item","Object_Size_medium_swig_tool"],
11+
"hake":["Object_Size_medium_hake"]
12+
},
13+
14+
"small":{
15+
"vg":["Object_Size_small_vg_obj","Object_Size_small_vg_subj"],
16+
"swig":["Object_Size_small_swig_agent","Object_Size_small_swig_destination","Object_Size_small_swig_item","Object_Size_small_swig_tool"],
17+
"hake":["Object_Size_small_hake"]
18+
},
19+
20+
"center":{
21+
"vg":["Object_Location_center_vg_obj","Object_Location_center_vg_subj"],
22+
"swig":["Object_Location_center_swig_agent","Object_Location_center_swig_destination","Object_Location_center_swig_item","Object_Location_center_swig_tool"],
23+
"hake":["Object_Location_center_hake"]
24+
},
25+
"mid":{
26+
"vg":["Object_Location_mid_vg_obj","Object_Location_mid_vg_subj"],
27+
"swig":["Object_Location_mid_swig_agent","Object_Location_mid_swig_destination","Object_Location_mid_swig_item","Object_Location_mid_swig_tool"],
28+
"hake":["Object_Location_mid_hake"]
29+
},
30+
"margin":{
31+
"vg":["Object_Location_margin_vg_obj","Object_Location_margin_vg_subj"],
32+
"swig":["Object_Location_margin_swig_agent","Object_Location_margin_swig_destination","Object_Location_margin_swig_item","Object_Location_margin_swig_tool"],
33+
"hake":["Object_Location_margin_hake"]
34+
},
35+
36+
"color":{
37+
"vg":["Attribute_color_vg"],
38+
"vaw":["Attribute_color_vaw"]
39+
},
40+
"material":{
41+
"vg":["Attribute_material_vg"],
42+
"vaw":["Attribute_material_vaw"]
43+
},
44+
"action_a":{
45+
"vg":["Attribute_action_vg"],
46+
"vaw":["Attribute_action_vaw"]
47+
},
48+
"size":{
49+
"vg":["Attribute_size_vg"],
50+
"vaw":["Attribute_size_vaw"]
51+
},
52+
"state":{
53+
"vg":["Attribute_state_vg"],
54+
"vaw":["Attribute_state_vaw"]
55+
},
56+
57+
"action_r":{
58+
"vg":["Relation_action_vg"],
59+
"swig":["Relation_action_swig"],
60+
"hake":["Relation_action_hake"]
61+
},
62+
"spatial":{
63+
"vg":["Relation_spatial_vg"]
64+
}
65+
}

radar.py

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
import numpy as np
2+
3+
import matplotlib.pyplot as plt
4+
from matplotlib.patches import Circle, RegularPolygon
5+
from matplotlib.path import Path
6+
from matplotlib.projections.polar import PolarAxes
7+
from matplotlib.projections import register_projection
8+
from matplotlib.spines import Spine
9+
from matplotlib.transforms import Affine2D
10+
import matplotlib
11+
import random
12+
import os
13+
import json
14+
15+
def radar_factory(num_vars, frame='circle'):
16+
"""Create a radar chart with `num_vars` axes.
17+
18+
This function creates a RadarAxes projection and registers it.
19+
20+
Parameters
21+
----------
22+
num_vars : int
23+
Number of variables for radar chart.
24+
frame : {'circle' | 'polygon'}
25+
Shape of frame surrounding axes.
26+
27+
"""
28+
# calculate evenly-spaced axis angles
29+
theta = np.linspace(0, 2 * np.pi, num_vars, endpoint=False)
30+
31+
class RadarAxes(PolarAxes):
32+
33+
name = 'radar'
34+
35+
def __init__(self, *args, **kwargs):
36+
super().__init__(*args, **kwargs)
37+
# rotate plot such that the first axis is at the top
38+
self.set_theta_zero_location('N')
39+
40+
def fill(self, *args, closed=True, **kwargs):
41+
"""Override fill so that line is closed by default"""
42+
return super().fill(closed=closed, *args, **kwargs)
43+
44+
def plot(self, *args, **kwargs):
45+
"""Override plot so that line is closed by default"""
46+
lines = super().plot(*args, **kwargs)
47+
for line in lines:
48+
self._close_line(line)
49+
50+
def _close_line(self, line):
51+
x, y = line.get_data()
52+
# FIXME: markers at x[0], y[0] get doubled-up
53+
if x[0] != x[-1]:
54+
x = np.concatenate((x, [x[0]]))
55+
y = np.concatenate((y, [y[0]]))
56+
line.set_data(x, y)
57+
58+
def set_varlabels(self, labels):
59+
self.set_thetagrids(np.degrees(theta), labels)
60+
61+
def _gen_axes_patch(self):
62+
# The Axes patch must be centered at (0.5, 0.5) and of radius 0.5
63+
# in axes coordinates.
64+
if frame == 'circle':
65+
return Circle((0.5, 0.5), 0.5)
66+
elif frame == 'polygon':
67+
return RegularPolygon((0.5, 0.5), num_vars,
68+
radius=.5, edgecolor="k")
69+
else:
70+
raise ValueError("unknown value for 'frame': %s" % frame)
71+
72+
def draw(self, renderer):
73+
""" Draw. If frame is polygon, make gridlines polygon-shaped """
74+
if frame == 'polygon':
75+
gridlines = self.yaxis.get_gridlines()
76+
for gl in gridlines:
77+
gl.get_path()._interpolation_steps = num_vars
78+
super().draw(renderer)
79+
80+
def _gen_axes_spines(self):
81+
if frame == 'circle':
82+
return super()._gen_axes_spines()
83+
elif frame == 'polygon':
84+
# spine_type must be 'left'/'right'/'top'/'bottom'/'circle'.
85+
spine = Spine(axes=self,
86+
spine_type='circle',
87+
path=Path.unit_regular_polygon(num_vars))
88+
# unit_regular_polygon gives a polygon of radius 1 centered at
89+
# (0, 0) but we want a polygon of radius 0.5 centered at (0.5,
90+
# 0.5) in axes coordinates.
91+
spine.set_transform(Affine2D().scale(.5).translate(.5, .5)
92+
+ self.transAxes)
93+
94+
return {'polar': spine}
95+
else:
96+
raise ValueError("unknown value for 'frame': %s" % frame)
97+
98+
register_projection(RadarAxes)
99+
return theta
100+
101+
def generate_chart(output_folder,corpus_path,task,chart_type,models):
102+
"""
103+
output_folder : str
104+
The path of folder that saves all evaluation results.
105+
corpus_path : str
106+
The path of json file that records corresponding file names of all metrics
107+
task : {'itm' | 'itc'}
108+
Task type of output result.
109+
chart_type : str
110+
Type of chart.
111+
models : list
112+
List of model name.
113+
114+
"""
115+
m = json.load(open(corpus_path))
116+
arrs = []
117+
colors = ["cyan", "magenta", "crimson", "orange","blue"]
118+
for model in models:
119+
filepath = os.path.join(output_folder,model,task)
120+
score_list = []
121+
122+
for item in m.keys():
123+
data_num = len(m[item].keys())
124+
data_score = []
125+
for data in m[item].keys():
126+
score = 0
127+
file_num = len(m[item][data])
128+
for file in m[item][data]:
129+
json_name = os.path.join(filepath,f"{file}.json")
130+
if not os.path.exists(json_name):
131+
print(f"{file} has not been evaluated.")
132+
return
133+
else:
134+
m1 = json.load(open(json_name))
135+
score += m1["total_acc"]
136+
data_score.append(score/file_num)
137+
score_list.append(sum(data_score)/data_num)
138+
arrs.append(score_list)
139+
140+
fig_ = plt.figure(figsize=(25, 8))
141+
models_name = [models]
142+
for i in range(len(models_name)):
143+
data = [['O-Large', 'O-Medium', 'O-Small', 'O-Center', 'O-Mid', 'O-Margin', 'A-Color', 'A-Material', 'A-Size',
144+
"A-State", "A-Action", "R-action", "R-spatial"],
145+
('', arrs)]
146+
N = len(data[0])
147+
theta = radar_factory(N, frame='polygon')
148+
149+
spoke_labels = data.pop(0)
150+
title, case_data = data[0]
151+
ax = fig_.add_subplot(f'13{i+1}', projection='radar')
152+
153+
ax.set_rgrids([30, 40, 50, 55, 60, 65, 70, 75, 80, 85, 90])
154+
lines = []
155+
labels = models_name[i]
156+
for i, d in enumerate(case_data):
157+
c = colors.pop()
158+
line = ax.plot(theta, d, label=labels[i], color=c)
159+
lines.append(line)
160+
ax.fill(theta, d, alpha=0.25, color=c)
161+
ax.set_varlabels(spoke_labels)
162+
plt.legend(loc="best", bbox_to_anchor=(1, 1))
163+
164+
plt.show()
165+
166+
if __name__ == "__main__":
167+
168+
generate_chart('./output','corpus.json','itc',chart_type='radar',models=['vilt','albef'])

0 commit comments

Comments
 (0)