|
|
|
|
@ -4,6 +4,8 @@ import json
|
|
|
|
|
import argparse
|
|
|
|
|
import random
|
|
|
|
|
import logging
|
|
|
|
|
import fnmatch
|
|
|
|
|
from operator import xor
|
|
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
import cv2
|
|
|
|
|
@ -18,10 +20,14 @@ from cvat.apps.auto_annotation.inference import run_inference_engine_annotation
|
|
|
|
|
|
|
|
|
|
def _get_kwargs():
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
parser.add_argument('--py', required=True, help='Path to the python interpt file')
|
|
|
|
|
parser.add_argument('--xml', required=True, help='Path to the xml file')
|
|
|
|
|
parser.add_argument('--bin', required=True, help='Path to the bin file')
|
|
|
|
|
parser.add_argument('--json', required=True, help='Path to the JSON mapping file')
|
|
|
|
|
parser.add_argument('--py', help='Path to the python interpt file')
|
|
|
|
|
parser.add_argument('--xml', help='Path to the xml file')
|
|
|
|
|
parser.add_argument('--bin', help='Path to the bin file')
|
|
|
|
|
parser.add_argument('--json', help='Path to the JSON mapping file')
|
|
|
|
|
|
|
|
|
|
parser.add_argument('--model-name', help='Name of the model in the Model Manager')
|
|
|
|
|
parser.add_argument('--task-id', type=int, help='ID task used to test the model')
|
|
|
|
|
|
|
|
|
|
parser.add_argument('--restricted', dest='restricted', action='store_true')
|
|
|
|
|
parser.add_argument('--unrestricted', dest='restricted', action='store_false')
|
|
|
|
|
parser.add_argument('--image-files', nargs='*', help='Paths to image files you want to test')
|
|
|
|
|
@ -56,14 +62,75 @@ def find_min_y(array):
|
|
|
|
|
|
|
|
|
|
return array[index]
|
|
|
|
|
|
|
|
|
|
def _get_docker_files(model_name: str, task_id: int):
|
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'cvat.settings.development'
|
|
|
|
|
|
|
|
|
|
import django
|
|
|
|
|
django.setup()
|
|
|
|
|
|
|
|
|
|
from cvat.apps.auto_annotation.models import AnnotationModel
|
|
|
|
|
from cvat.apps.engine.models import Task as TaskModel
|
|
|
|
|
|
|
|
|
|
task = TaskModel(pk=task_id)
|
|
|
|
|
model = AnnotationModel.objects.get(name=model_name)
|
|
|
|
|
|
|
|
|
|
images_dir = task.get_data_dirname()
|
|
|
|
|
|
|
|
|
|
py_file = model.interpretation_file.name
|
|
|
|
|
mapping_file = model.labelmap_file.name
|
|
|
|
|
xml_file = model.model_file.name
|
|
|
|
|
bin_file = model.weights_file.name
|
|
|
|
|
|
|
|
|
|
image_files = []
|
|
|
|
|
for root, _, filenames in os.walk(images_dir):
|
|
|
|
|
for filename in fnmatch.filter(filenames, '*.jpg'):
|
|
|
|
|
image_files.append(os.path.join(root, filename))
|
|
|
|
|
|
|
|
|
|
return py_file, mapping_file, bin_file, xml_file, image_files
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
kwargs = _get_kwargs()
|
|
|
|
|
|
|
|
|
|
py_file = kwargs['py']
|
|
|
|
|
bin_file = kwargs['bin']
|
|
|
|
|
mapping_file = kwargs['json']
|
|
|
|
|
xml_file = kwargs['xml']
|
|
|
|
|
py_file = kwargs.get('py')
|
|
|
|
|
bin_file = kwargs.get('bin')
|
|
|
|
|
mapping_file = kwargs.get('json')
|
|
|
|
|
xml_file = kwargs.get('xml')
|
|
|
|
|
|
|
|
|
|
model_name = kwargs.get('model_name')
|
|
|
|
|
task_id = kwargs.get('task_id')
|
|
|
|
|
|
|
|
|
|
is_docker = model_name and task_id
|
|
|
|
|
|
|
|
|
|
# xor is `exclusive or`. English is: if one or the other but not both
|
|
|
|
|
if xor(bool(model_name), bool(task_id)):
|
|
|
|
|
logging.critical('Must provide both `--model-name` and `--task-id` together!')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if is_docker:
|
|
|
|
|
files = _get_docker_files(model_name, task_id)
|
|
|
|
|
py_file = files[0]
|
|
|
|
|
mapping_file = files[1]
|
|
|
|
|
bin_file = files[2]
|
|
|
|
|
xml_file = files[3]
|
|
|
|
|
image_files = files[4]
|
|
|
|
|
else:
|
|
|
|
|
return_ = False
|
|
|
|
|
if not py_file:
|
|
|
|
|
logging.critical('Must provide --py file!')
|
|
|
|
|
return_ = True
|
|
|
|
|
if not bin_file:
|
|
|
|
|
logging.critical('Must provide --bin file!')
|
|
|
|
|
return_ = True
|
|
|
|
|
if not xml_file:
|
|
|
|
|
logging.critical('Must provide --xml file!')
|
|
|
|
|
return_ = True
|
|
|
|
|
if not mapping_file:
|
|
|
|
|
logging.critical('Must provide --json file!')
|
|
|
|
|
return_ = True
|
|
|
|
|
|
|
|
|
|
if return_:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if not os.path.isfile(py_file):
|
|
|
|
|
logging.critical('Py file not found! Check the path')
|
|
|
|
|
@ -98,6 +165,8 @@ def main():
|
|
|
|
|
mapping = {int(k): v for k, v in mapping.items()}
|
|
|
|
|
|
|
|
|
|
restricted = kwargs['restricted']
|
|
|
|
|
|
|
|
|
|
if not is_docker:
|
|
|
|
|
image_files = kwargs.get('image_files')
|
|
|
|
|
|
|
|
|
|
if image_files:
|
|
|
|
|
|