@@ -601,6 +601,9 @@ def convert_attrs(label, cvat_attrs):
601
601
602
602
return item_anno
603
603
604
+ class CvatImportError (Exception ):
605
+ pass
606
+
604
607
def match_dm_item (item , task_data , root_hint = None ):
605
608
is_video = task_data .meta ['task' ]['mode' ] == 'interpolation'
606
609
@@ -615,8 +618,8 @@ def match_dm_item(item, task_data, root_hint=None):
615
618
frame_number = cast (osp .basename (item .id )[len ('frame_' ):], int )
616
619
617
620
if not frame_number in task_data .frame_info :
618
- raise Exception ("Could not match item id: '%s' with any task frame" %
619
- item .id )
621
+ raise CvatImportError ("Could not match item id: "
622
+ "'%s' with any task frame" % item .id )
620
623
return frame_number
621
624
622
625
def find_dataset_root (dm_dataset , task_data ):
@@ -631,7 +634,6 @@ def find_dataset_root(dm_dataset, task_data):
631
634
prefix = prefix [:- 1 ]
632
635
return prefix
633
636
634
-
635
637
def import_dm_annotations (dm_dataset , task_data ):
636
638
shapes = {
637
639
datumaro .AnnotationType .bbox : ShapeType .RECTANGLE ,
@@ -667,26 +669,32 @@ def import_dm_annotations(dm_dataset, task_data):
667
669
if 1 < s and group_map [g ]}
668
670
group_map = {g : i for i , g in enumerate ([0 ] + sorted (group_map ))}
669
671
670
- for ann in item .annotations :
671
- if ann .type in shapes :
672
- task_data .add_shape (task_data .LabeledShape (
673
- type = shapes [ann .type ],
674
- frame = frame_number ,
675
- label = label_cat .items [ann .label ].name ,
676
- points = ann .points ,
677
- occluded = ann .attributes .get ('occluded' ) == True ,
678
- z_order = ann .z_order ,
679
- group = group_map .get (ann .group , 0 ),
680
- source = 'manual' ,
681
- attributes = [task_data .Attribute (name = n , value = str (v ))
682
- for n , v in ann .attributes .items ()],
683
- ))
684
- elif ann .type == datumaro .AnnotationType .label :
685
- task_data .add_tag (task_data .Tag (
686
- frame = frame_number ,
687
- label = label_cat .items [ann .label ].name ,
688
- group = group_map .get (ann .group , 0 ),
689
- source = 'manual' ,
690
- attributes = [task_data .Attribute (name = n , value = str (v ))
691
- for n , v in ann .attributes .items ()],
692
- ))
672
+ for idx , ann in enumerate (item .annotations ):
673
+ try :
674
+ if hasattr (ann , 'label' ) and ann .label is None :
675
+ raise CvatImportError ("annotation has no label" )
676
+ if ann .type in shapes :
677
+ task_data .add_shape (task_data .LabeledShape (
678
+ type = shapes [ann .type ],
679
+ frame = frame_number ,
680
+ label = label_cat .items [ann .label ].name ,
681
+ points = ann .points ,
682
+ occluded = ann .attributes .get ('occluded' ) == True ,
683
+ z_order = ann .z_order ,
684
+ group = group_map .get (ann .group , 0 ),
685
+ source = 'manual' ,
686
+ attributes = [task_data .Attribute (name = n , value = str (v ))
687
+ for n , v in ann .attributes .items ()],
688
+ ))
689
+ elif ann .type == datumaro .AnnotationType .label :
690
+ task_data .add_tag (task_data .Tag (
691
+ frame = frame_number ,
692
+ label = label_cat .items [ann .label ].name ,
693
+ group = group_map .get (ann .group , 0 ),
694
+ source = 'manual' ,
695
+ attributes = [task_data .Attribute (name = n , value = str (v ))
696
+ for n , v in ann .attributes .items ()],
697
+ ))
698
+ except Exception as e :
699
+ raise CvatImportError ("Image {}: can't import annotation "
700
+ "#{} ({}): {}" .format (item .id , idx , ann .type .name , e ))
0 commit comments