avoid switching current directory in get_txt_annotation()
@@ -40,6 +40,7 @@ from itertools import repeat
import math
from contextlib import contextmanager
import inspect
+from glob import glob
def random_name(name='ImageData', length=6):
@@ -1235,19 +1236,13 @@ def get_txt_annotation(local_path, coord_type, image_size = (416, 416), label_fi
Default: None
'''
- cwd = os.getcwd()
- os.chdir(local_path)
image_size = _pair(image_size) # ensure image_size is a pair
- # if label_files = None, that means we call it directly and parse annotation files.
- if label_files is None:
- label_files = os.listdir(local_path)
- # find all of label files
- label_files = [x for x in label_files if x.endswith('.xml')]
+ # get all xml file under the local_path
+ label_files = glob(os.path.join(local_path, '*.xml'))
if len(label_files) == 0:
raise DLPyError('Can not find any xml file under data_path')
for idx, filename in enumerate(label_files):
_convert_xml_annotation(filename, coord_type, image_size)
- os.chdir(cwd)
def create_object_detection_table(conn, data_path, coord_type, output,
