Exemple #1
0
class TestCVATAPI(TestCase):
    def setUp(self) -> None:
        self.api = CVATAPI(os.environ["CVAT_HOST"])

    def test_login(self):
        result = self.api.login(os.environ["CVAT_USER"],
                                os.environ["CVAT_PASSWORD"]).json()
        print(f"Log in result: {result}")

    def test_create_task(self):
        self.test_login()
        result = self.api.create_task("test", 5000, [
            Label("glass beads",
                  [Attribute("cropped", "checkbox", ["yes", "no"], "no")])
        ])

        print(f"create task result: {result.json()}")

    def test_get_shared_files(self):
        self.test_login()
        result = self.api.get_server_files()
        print(result.json())

    def test_export(self):
        self.test_login()
        result = self.api.export_data(11)
        print(result.json)
Exemple #2
0

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    cvat_args(parser)
    parser.add_argument("--config")
    parser.add_argument("--job_id", type=int, action="append")
    parser.add_argument("--val_job_id", type=int, action="append")
    parser.add_argument("--output")
    parser.add_argument("--resume", action="store_true")
    parser.add_argument("--restart", action="store_true")
    parser.add_argument("--force_test", action="store_true")
    parser.add_argument("--epoch")
    args = parser.parse_args()

    api = CVATAPI(args.cvat_host)
    api.login(args.cvat_username, args.cvat_password)

    train_tasks = []

    # training tasks
    for job_id in args.job_id:
        data, task_id = get_data_set(job_id)

        coco_json = f"datasets/train_cvat_{task_id}.coco.json"
        with open(coco_json, "w") as f:
            json.dump(data, f)
        train_task = f"cvat/train_{task_id}"
        register_coco_instances(train_task, {}, coco_json, args.cvat_base)
        train_tasks.append(train_task)
    override_cfg = ["DATASETS.TRAIN", tuple(train_tasks)]
Exemple #3
0

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--job_id", action="append")
    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:
from xml.etree import ElementTree
from xml.etree.ElementTree import Element

from cvat.api import CVATAPI
from cvat.argument import cvat_args

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--all", action="store_true")
    parser.add_argument("--task_id", action="append", type=int)
    parser.add_argument("--job_id", action="append", type=int)
    parser.add_argument("--output_dir", required=True)
    cvat_args(parser)
    args = parser.parse_args()

    api = CVATAPI(args.cvat_host)
    api.login(args.cvat_username, args.cvat_password)
    if args.all:
        tasks = api.list_task()
        task_ids = [x["id"] for x in tasks]

    else:
        task_ids = []
        if args.task_id:
            task_ids.extend(args.task_id)
        if args.job_id:
            for job_id in args.job_id:
                job = api.get_job(job_id).json()
                task_id = job["task_id"]
                task_ids.append(task_id)
Exemple #5
0
 def setUp(self) -> None:
     self.api = CVATAPI(os.environ["CVAT_HOST"])
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)))