@@ -42,22 +42,30 @@ 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+ all_not_folders = [i for i in all_items if not i .is_dir ()]
54+ annotation_paths .update (
55+ [
56+ str (i )
57+ for i in all_not_folders
58+ if i .name .endswith ((VECTOR_ANNOTATION_POSTFIX , PIXEL_ANNOTATION_POSTFIX ))
59+ ]
60+ )
61+ if recursive :
62+ for folder in all_folders :
63+ get_local_annotation_paths (
64+ folder_path = folder ,
65+ annotation_paths = annotation_paths ,
66+ recursive = recursive ,
67+ )
68+ return list (annotation_paths )
6169
6270
6371def get_s3_annotation_paths (folder_path , s3_bucket , annotation_paths , recursive ):
0 commit comments