def main(): if not args.class_map.exists() or not args.class_map.is_file(): eprint("File %s is invalid!" % args.class_map) with open(args.class_map, 'r') as f: # Note that we're not using the CLoader since it may not exist on all # installations, and isn't really necessary for the small file sizes we # have here. class_map = yaml.load(f.read(), yaml.Loader) print("Loaded class mapping:", class_map) short_classes = set(class_map.keys()) long_classes = set(class_map.values()) if not args.folder.exists() or not args.folder.is_dir(): eprint("Specified folder %s is invalid!" % args.folder) for root, dirs, files in os.walk(args.folder, followlinks=True): for name in files: if not name.endswith(".txt"): continue if name.endswith("rects.txt"): continue txt_name = name txt_full_path = os.path.join(root, txt_name) bboxes, classes = bbox_writer.read_bboxes(txt_full_path) for i, c in enumerate(classes): if c in short_classes: classes[i] = class_map[c] if not classes[i] in long_classes: print("Class name %s in file %s on line %d is invalid!" % (classes[i], txt_full_path, i + 1)) bbox_writer.write_bboxes(bboxes, classes, txt_full_path)
def get_scaled_bboxes(filename, sf): bbox_filename = bbox_writer.get_bbox_filename(filename) bbox_path = os.path.join(os.path.dirname(filename), bbox_filename) bboxes_, classes = bbox_writer.read_bboxes(bbox_path) bboxes = drawing_utils.scale_bboxes(bboxes_, sf) return bboxes, classes
def load_bboxes(frame_number, run_path): # Figure out which file we're trying to load. First, get the path of the # image file that we'd be saving against. bbox_filename = os.path.join(run_path, "%05d.txt" % frame_number) if os.path.isfile(bbox_filename): bboxes, classes = bbox_writer.read_bboxes(bbox_filename) else: # Not saved yet, so just return an empty list bboxes = [] classes = [] return bboxes, classes