@@ -136,6 +136,30 @@ def get_image_data(self, diffgram_file):
136
136
else :
137
137
raise Exception ('Pytorch datasets only support images. Please provide only file_ids from images' )
138
138
139
+ def gen_global_attrs (self , instance_list ):
140
+ res = []
141
+ for inst in instance_list :
142
+ if inst ['type' ] != 'global' :
143
+ continue
144
+ res .append (inst ['attribute_groups' ])
145
+ return res
146
+
147
+ def gen_tag_instances (self , instance_list ):
148
+ result = []
149
+ for inst in instance_list :
150
+ if inst ['type' ] != 'tag' :
151
+ continue
152
+ for k in list (inst .keys ()):
153
+ val = inst [k ]
154
+ if val is None :
155
+ inst .pop (k )
156
+ elm = {
157
+ 'label' : inst ['label_file' ]['label' ]['name' ],
158
+ 'label_file_id' : inst ['label_file' ]['id' ],
159
+ }
160
+ result .append (elm )
161
+ return result
162
+
139
163
def get_file_instances (self , diffgram_file ):
140
164
if diffgram_file .type not in ['image' , 'frame' ]:
141
165
raise NotImplementedError ('File type "{}" is not supported yet' .format (diffgram_file ['type' ]))
@@ -147,6 +171,9 @@ def get_file_instances(self, diffgram_file):
147
171
sample = {'image' : image , 'diffgram_file' : diffgram_file }
148
172
has_boxes = False
149
173
has_poly = False
174
+ has_tags = False
175
+ has_global = False
176
+ sample ['raw_instance_list' ] = instance_list
150
177
if 'box' in instance_types_in_file :
151
178
has_boxes = True
152
179
x_min_list , x_max_list , y_min_list , y_max_list = self .extract_bbox_values (instance_list , diffgram_file )
@@ -164,12 +191,19 @@ def get_file_instances(self, diffgram_file):
164
191
has_poly = True
165
192
mask_list = self .extract_masks_from_polygon (instance_list , diffgram_file )
166
193
sample ['polygon_mask_list' ] = mask_list
194
+ if 'tag' in instance_types_in_file :
195
+ has_tags = True
196
+ sample ['tags' ] = self .gen_tag_instances (instance_list )
197
+ if 'global' in instance_types_in_file :
198
+ has_global = True
199
+ sample ['global_attributes' ] = self .gen_global_attrs (instance_list )
200
+
167
201
else :
168
202
sample ['polygon_mask_list' ] = []
169
203
170
- if len (instance_types_in_file ) > 2 and has_boxes and has_boxes :
204
+ if len (instance_types_in_file ) > 4 and has_poly and has_boxes and has_tags and has_global :
171
205
raise NotImplementedError (
172
- 'SDK only supports boxes and polygon types currently. If you want a new instance type to be supported please contact us!'
206
+ 'SDK Streaming only supports boxes and polygon, tags and global attributes types currently. If you want a new instance type to be supported please contact us!'
173
207
)
174
208
175
209
label_id_list , label_name_list = self .extract_labels (instance_list )
@@ -198,11 +232,13 @@ def extract_masks_from_polygon(self, instance_list, diffgram_file, empty_value =
198
232
def extract_labels (self , instance_list , allowed_instance_types = None ):
199
233
label_file_id_list = []
200
234
label_names_list = []
201
-
202
235
for inst in instance_list :
236
+ if inst ['type' ] == 'global' :
237
+ continue
238
+ if inst is None :
239
+ continue
203
240
if allowed_instance_types and inst ['type' ] in allowed_instance_types :
204
241
continue
205
-
206
242
label_file_id_list .append (inst ['label_file' ]['id' ])
207
243
label_names_list .append (inst ['label_file' ]['label' ]['name' ])
208
244
0 commit comments