@@ -42,22 +42,29 @@ def get_annotation_paths(folder_path, s3_bucket=None, recursive=False):
4242 return get_s3_annotation_paths (
4343 folder_path , s3_bucket , annotation_paths , recursive
4444 )
45- return get_local_annotation_paths (folder_path , annotation_paths , recursive )
45+ return get_local_annotation_paths (folder_path , set ( annotation_paths ) , recursive )
4646
4747
4848def get_local_annotation_paths (
49- folder_path : Union [str , Path ], annotation_paths : List , recursive : bool
49+ folder_path : Union [str , Path ], annotation_paths : set , recursive : bool
5050) -> List [str ]:
51- for path in Path (folder_path ).glob ("*" ):
52- if recursive and path .is_dir ():
53- get_local_annotation_paths (path , annotation_paths , recursive )
54- for annotation_path in Path (folder_path ).glob ("*.json" ):
55- if (
56- annotation_path .name .endswith (VECTOR_ANNOTATION_POSTFIX )
57- or annotation_path .name .endswith (PIXEL_ANNOTATION_POSTFIX )
58- ) and str (annotation_path ) not in annotation_paths :
59- annotation_paths .append (str (annotation_path ))
60- return annotation_paths
51+ all_items = [* Path (folder_path ).glob ("*" )]
52+ all_folders = [i for i in all_items if i .is_dir ()]
53+ annotation_paths .update (
54+ [
55+ str (i )
56+ for i in all_items
57+ if i .name .endswith ((VECTOR_ANNOTATION_POSTFIX , PIXEL_ANNOTATION_POSTFIX ))
58+ ]
59+ )
60+ if recursive :
61+ for folder in all_folders :
62+ get_local_annotation_paths (
63+ folder_path = folder ,
64+ annotation_paths = annotation_paths ,
65+ recursive = recursive ,
66+ )
67+ return list (annotation_paths )
6168
6269
6370def get_s3_annotation_paths (folder_path , s3_bucket , annotation_paths , recursive ):
0 commit comments