args = parser.parse_args() if not isdir(train_directory) or not isdir(test_directory): print(colored('[!]', 'yellow', attrs=['bold']), colored('The training or test directories do not exist')) exit(1) else: print(colored('[Ok]', 'green'), colored('Directories exists')) everythingWentAsExpected = True for tree in [train_directory, test_directory]: if args.move and not isdir(tree + '/wrong_data'): makedirs(tree + '/wrong_data') for file in xmlFiles(tree + '/*.xml'): xmlFile = ElementTree.parse(file) boxes = xmlFile.findall('object/bndbox') for box in boxes: xmin, ymin, xmax, ymax = box.getchildren() x_value = int(xmax.text) - int(xmin.text) y_value = int(ymax.text) - int(ymin.text) if x_value < 33 or y_value < 33: print( colored('[!]', 'red'), 'File {} contains a bounding box smaller than 32 in height or width' .format(file)) print(colored('xmax - xmin', 'yellow', attrs=['bold']), x_value) print(colored('ymax - ymin', 'yellow', attrs=['bold']),
import os from glob import glob as xmlFiles file_name = "trainval.txt" save_folder = "../annotations" ann_folder = save_folder + '/xmls' out = "" for tree in [ann_folder]: print(xmlFiles(tree + '/*.xml')) for file in xmlFiles(tree + '/*.xml'): base = os.path.basename(file) out += str(os.path.splitext(base)[0]) + "\n" text_file = open(os.path.join(save_folder, file_name), "w") text_file.write(out) text_file.close()