def parse_detect(detannos): xmls_path = loop(detannos, ['.xml']) print('########## Reading {0} annotation files of DT.##########'.format(len(xmls_path))) infos = [] for xml_path in xmls_path: info = parse_rec(xml_path) info = [item for cls_key in info for item in info[cls_key]] basename = os.path.basename(xml_path) infos.append([os.path.splitext(basename)[0], [[item['confidence']]+[item['name']]+item['bbox'] for item in info]]) return [[item[0], item[1]] for item in infos]
def load_detect_lines(detannos, conf): txts_path = loop(detannos, ['.txt']) print('########## Reading {0} annotation files of DT.##########'.format(len(txts_path))) infos = [] for txt_path in txts_path: with open(txt_path, 'r') as f: lines = f.readlines() true_class = os.path.basename(txt_path).split('.')[0].split('_')[-1] # 图片名[无后缀] 置信度 x1 y1 x2 y2 # target: image_name, conf, det_class, [xmin, ymin, xmax, ymax] for line in lines: line = line.strip().split(' ') if float(line[1]) < conf: continue infos.append(line[0:2]+[true_class]+line[2:]) return infos
def get_xmls_basename(xml_path): return [ os.path.splitext(os.path.basename(item))[0] for item in loop(xml_path, ['.xml']) ]
def test_pars_annotations(self): xml_poaths = dir_loop.loop(self.test_data_dir, ['.xml']) self.parse_annotations(xml_poaths[0])