-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathmodels.py
More file actions
220 lines (178 loc) · 5.17 KB
/
models.py
File metadata and controls
220 lines (178 loc) · 5.17 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
"""
Visual Genome Python API wrapper, models
"""
class Image:
"""
Image.
ID int
url hyperlink string
width int
height int
"""
def __init__(self, id, url, width, height, coco_id, flickr_id):
self.id = id
self.url = url
self.width = width
self.height = height
self.coco_id = coco_id
self.flickr_id = flickr_id
def __str__(self):
return 'id: %d, coco_id: %d, flickr_id: %d, width: %d, url: %s' \
% (self.id, -1
if self.coco_id is None
else self.coco_id, -1
if self.flickr_id is None
else self.flickr_id, self.width, self.url)
def __repr__(self):
return str(self)
class Region:
"""
Region.
image int
phrase string
x int
y int
width int
height int
"""
def __init__(self, id, image, phrase, x, y, width, height):
self.id = id
self.image = image
self.phrase = phrase
self.x = x
self.y = y
self.width = width
self.height = height
def __str__(self):
stat_str = 'id: {0}, x: {1}, y: {2}, width: {3},' \
'height: {4}, phrase: {5}, image: {6}'
return stat_str.format(self.id, self.x, self.y,
self.width, self.height, self.phrase,
self.image.id)
def __repr__(self):
return str(self)
class Graph:
"""
Graphs contain objects, relationships and attributes
image Image
bboxes Object array
relationships Relationship array
attributes Attribute array
"""
def __init__(self, image, objects, relationships, attributes):
self.image = image
self.objects = objects
self.relationships = relationships
self.attributes = attributes
class Object:
"""
Objects.
id int
x int
y int
width int
height int
names string array
synsets Synset array
"""
def __init__(self, id, x, y, width, height, names, synsets):
self.id = id
self.x = x
self.y = y
self.width = width
self.height = height
self.names = names
self.synsets = synsets
def __str__(self):
name = self.names[0] if len(self.names) != 0 else 'None'
return '%s' % (name)
def __repr__(self):
return str(self)
class Relationship:
"""
Relationships. Ex, 'man - jumping over - fire hydrant'.
subject int
predicate string
object int
rel_canon Synset
"""
def __init__(self, id, subject, predicate, object, synset):
self.id = id
self.subject = subject
self.predicate = predicate
self.object = object
self.synset = synset
def __str__(self):
return "{0}: {1} {2} {3}".format(self.id, self.subject,
self.predicate, self.object)
def __repr__(self):
return str(self)
class Attribute:
"""
Attributes. Ex, 'man - old'.
subject Object
attribute string
synset Synset
"""
def __init__(self, id, subject, attribute, synset):
self.id = id
self.subject = subject
self.attribute = attribute
self.synset = synset
def __str__(self):
return "%d: %s is %s" % (self.id, self.subject, self.attribute)
def __repr__(self):
return str(self)
class QA:
"""
Question Answer Pairs.
ID int
image int
question string
answer string
q_objects QAObject array
a_objects QAObject array
"""
def __init__(self, id, image, question, answer,
question_objects, answer_objects):
self.id = id
self.image = image
self.question = question
self.answer = answer
self.q_objects = question_objects
self.a_objects = answer_objects
def __str__(self):
return 'id: %d, image: %d, question: %s, answer: %s' \
% (self.id, self.image.id, self.question, self.answer)
def __repr__(self):
return str(self)
class QAObject:
"""
Question Answer Objects are localized in the image and refer to a part
of the question text or the answer text.
start_idx int
end_idx int
name string
synset_name string
synset_definition string
"""
def __init__(self, start_idx, end_idx, name, synset):
self.start_idx = start_idx
self.end_idx = end_idx
self.name = name
self.synset = synset
def __repr__(self):
return str(self)
class Synset:
"""
Wordnet Synsets.
name string
definition string
"""
def __init__(self, name, definition):
self.name = name
self.definition = definition
def __str__(self):
return '{} - {}'.format(self.name, self.definition)
def __repr__(self):
return str(self)