parser.add_argument("--config", required=True) cvat_args(parser) parser.add_argument("--output_dir", default="./eval_output") parser.add_argument("--weights") parser.add_argument("--mapping", help="[old_id, new_id]") args = parser.parse_args() cfg = get_cfg() cfg.merge_from_file(args.config) api = CVATAPI(args.cvat_host) api.login(args.cvat_username, args.cvat_password) eval_tasks = [] for job_id in args.job_id: job = api.get_job(job_id).json() task_id = job["task_id"] data = api.export_data(task_id).json() if args.mapping is not None: mapping = json.loads(args.mapping) mapping = {mapping[0]: mapping[1]} remap_annotation(data, mapping) coco_json = f"datasets/eval_cvat_{job_id}.coco.json" with open(coco_json, "w") as f: json.dump(data, f) eval_task = f"cvat_eval_{job_id}" register_coco_instances(eval_task, {}, coco_json, args.cvat_base) eval_tasks.append(eval_task)
if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("--ignore_attributes", action="store_true") parser.add_argument("--ignore_crowded", action="store_true") parser.add_argument("--occluded_as_crowded", action="store_true") parser.add_argument("--file") parser.add_argument("--job_id") cvat_args(parser) args = parser.parse_args() if args.file is not None: root = ElementTree.parse(args.file) elif args.job_id is not None: api = CVATAPI(args.cvat_host) api.login(args.cvat_username, args.cvat_password) job = api.get_job(args.job_id).json() task_id = job["task_id"] xml_content = api.export_data(task_id, format="CVAT XML 1.1 for images").content root = ElementTree.fromstring(xml_content) else: raise ValueError("Task id or xml file should be specified") print( json.dumps( cvat_xml_to_coco(root, ignore_crowded=args.ignore_crowded, occluded_as_crowded=args.occluded_as_crowded, ignore_attributes=args.ignore_attributes, cvat_base_dir=args.cvat_base)))