@@ -120,6 +120,7 @@ def __init__(self, annotation_ir, db_task, scheme='', host='', create_callback=N
120
120
self ._MAX_ANNO_SIZE = 30000
121
121
self ._frame_info = {}
122
122
self ._frame_mapping = {}
123
+ self ._frame_step = db_task .get_frame_step ()
123
124
124
125
db_labels = self ._db_task .label_set .all ().prefetch_related ('attributespec_set' ).order_by ('pk' )
125
126
@@ -270,7 +271,7 @@ def _export_attributes(self, attributes):
270
271
def _export_tracked_shape (self , shape ):
271
272
return Annotation .TrackedShape (
272
273
type = shape ["type" ],
273
- frame = self ._db_task .start_frame + shape ["frame" ] * self ._db_task . get_frame_step () ,
274
+ frame = self ._db_task .start_frame + shape ["frame" ] * self ._frame_step ,
274
275
points = shape ["points" ],
275
276
occluded = shape ["occluded" ],
276
277
outside = shape .get ("outside" , False ),
@@ -283,7 +284,7 @@ def _export_labeled_shape(self, shape):
283
284
return Annotation .LabeledShape (
284
285
type = shape ["type" ],
285
286
label = self ._get_label_name (shape ["label_id" ]),
286
- frame = self ._db_task .start_frame + shape ["frame" ] * self ._db_task . get_frame_step () ,
287
+ frame = self ._db_task .start_frame + shape ["frame" ] * self ._frame_step ,
287
288
points = shape ["points" ],
288
289
occluded = shape ["occluded" ],
289
290
z_order = shape .get ("z_order" , 0 ),
@@ -293,7 +294,7 @@ def _export_labeled_shape(self, shape):
293
294
294
295
def _export_tag (self , tag ):
295
296
return Annotation .Tag (
296
- frame = self ._db_task .start_frame + tag ["frame" ] * self ._db_task . get_frame_step () ,
297
+ frame = self ._db_task .start_frame + tag ["frame" ] * self ._frame_step ,
297
298
label = self ._get_label_name (tag ["label_id" ]),
298
299
group = tag .get ("group" , 0 ),
299
300
attributes = self ._export_attributes (tag ["attributes" ]),
@@ -302,7 +303,7 @@ def _export_tag(self, tag):
302
303
def group_by_frame (self ):
303
304
def _get_frame (annotations , shape ):
304
305
db_image = self ._frame_info [shape ["frame" ]]
305
- frame = self ._db_task .start_frame + shape ["frame" ] * self ._db_task . get_frame_step ()
306
+ frame = self ._db_task .start_frame + shape ["frame" ] * self ._frame_step
306
307
rpath = db_image ['path' ].split (os .path .sep )
307
308
if len (rpath ) != 1 :
308
309
rpath = os .path .sep .join (rpath [rpath .index (".upload" )+ 1 :])
@@ -359,6 +360,7 @@ def meta(self):
359
360
def _import_tag (self , tag ):
360
361
_tag = tag ._asdict ()
361
362
label_id = self ._get_label_id (_tag .pop ('label' ))
363
+ _tag ['frame' ] = (int (_tag ['frame' ]) - self ._db_task .start_frame ) // self ._frame_step
362
364
_tag ['label_id' ] = label_id
363
365
_tag ['attributes' ] = [self ._import_attribute (label_id , attrib ) for attrib in _tag ['attributes' ]
364
366
if self ._get_attribute_id (label_id , attrib .name )]
@@ -373,6 +375,7 @@ def _import_attribute(self, label_id, attribute):
373
375
def _import_shape (self , shape ):
374
376
_shape = shape ._asdict ()
375
377
label_id = self ._get_label_id (_shape .pop ('label' ))
378
+ _shape ['frame' ] = (int (_shape ['frame' ]) - self ._db_task .start_frame ) // self ._frame_step
376
379
_shape ['label_id' ] = label_id
377
380
_shape ['attributes' ] = [self ._import_attribute (label_id , attrib ) for attrib in _shape ['attributes' ]
378
381
if self ._get_attribute_id (label_id , attrib .name )]
@@ -381,11 +384,13 @@ def _import_shape(self, shape):
381
384
def _import_track (self , track ):
382
385
_track = track ._asdict ()
383
386
label_id = self ._get_label_id (_track .pop ('label' ))
384
- _track ['frame' ] = min (shape .frame for shape in _track ['shapes' ])
387
+ _track ['frame' ] = (min (int (shape .frame ) for shape in _track ['shapes' ]) - \
388
+ self ._db_task .start_frame ) // self ._frame_step
385
389
_track ['label_id' ] = label_id
386
390
_track ['attributes' ] = []
387
391
_track ['shapes' ] = [shape ._asdict () for shape in _track ['shapes' ]]
388
392
for shape in _track ['shapes' ]:
393
+ shape ['frame' ] = (int (shape ['frame' ]) - self ._db_task .start_frame ) // self ._frame_step
389
394
_track ['attributes' ] = [self ._import_attribute (label_id , attrib ) for attrib in shape ['attributes' ]
390
395
if self ._get_immutable_attribute_id (label_id , attrib .name )]
391
396
shape ['attributes' ] = [self ._import_attribute (label_id , attrib ) for attrib in shape ['attributes' ]
@@ -431,6 +436,10 @@ def _len(self):
431
436
def frame_info (self ):
432
437
return self ._frame_info
433
438
439
+ @property
440
+ def frame_step (self ):
441
+ return self ._frame_step
442
+
434
443
@staticmethod
435
444
def _get_filename (path ):
436
445
return os .path .splitext (os .path .basename (path ))[0 ]
0 commit comments