added in command line auto annotation runner (#563)

main
Ben Hoff 7 years ago committed by Nikita Manovich
parent 018cd143c3
commit 6e1e063c04

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Auto annotation using Pixel Link mobilenet v2 - text detection (utils/open_model_zoo)
- Ability to create a custom extractors for unsupported media types
- Added in PDF extractor
- Added in a command line model manager tester
### Changed
- Outside and keyframe buttons in the side panel for all interpolation shapes (they were only for boxes before)

@ -44,7 +44,7 @@ def _update_dl_model_thread(dl_model_id, name, is_shared, model_file, weights_fi
def _run_test(model_file, weights_file, labelmap_file, interpretation_file):
test_image = np.ones((1024, 1980, 3), np.uint8) * 255
try:
_run_inference_engine_annotation(
run_inference_engine_annotation(
data=[test_image,],
model_file=model_file,
weights_file=weights_file,
@ -266,6 +266,9 @@ class Results():
"attributes": attributes or {},
}
class InterpreterError(Exception):
pass
def _process_detections(detections, path_to_conv_script, restricted=True):
results = Results()
local_vars = {
@ -290,11 +293,23 @@ def _process_detections(detections, path_to_conv_script, restricted=True):
imports = import_modules(source_code)
global_vars.update(imports)
exec(source_code, global_vars, local_vars)
try:
exec(source_code, global_vars, local_vars)
except SyntaxError as err:
error_class = err.__class__.__name__
detail = err.args[0]
line_number = err.lineno
except Exception as err:
error_class = err.__class__.__name__
detail = err.args[0]
cl, exc, tb = sys.exc_info()
line_number = traceback.extract_tb(tb)[-1][1]
else:
return results
return results
raise InterpreterError("%s at line %d: %s" % (error_class, line_number, detail))
def _run_inference_engine_annotation(data, model_file, weights_file,
def run_inference_engine_annotation(data, model_file, weights_file,
labels_mapping, attribute_spec, convertation_file, job=None, update_progress=None, restricted=True):
def process_attributes(shape_attributes, label_attr_spec):
attributes = []
@ -377,7 +392,7 @@ def run_inference_thread(tid, model_file, weights_file, labels_mapping, attribut
result = None
slogger.glob.info("auto annotation with openvino toolkit for task {}".format(tid))
result = _run_inference_engine_annotation(
result = run_inference_engine_annotation(
data=get_image_data(db_task.get_data_dirname()),
model_file=model_file,
weights_file=weights_file,

@ -0,0 +1,76 @@
import os
import sys
import json
import argparse
import traceback
os.environ['DJANGO_SETTINGS_MODULE'] = 'cvat.settings.production'
import django
django.setup()
import numpy as np
import cv2
from cvat.apps.auto_annotation.model_manager 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('--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')
return vars(parser.parse_args())
class InterpreterError(Exception):
pass
def main():
kwargs = _get_kwargs()
py_file = kwargs['py']
bin_file = kwargs['bin']
mapping_file = kwargs['json']
xml_file = kwargs['xml']
if not os.path.isfile(py_file):
print('Py file not found! Check the path')
return
if not os.path.isfile(bin_file):
print('Bin file is not found! Check path!')
return
if not os.path.isfile(xml_file):
print('XML File not found! Check path!')
return
if not os.path.isfile(mapping_file):
print('JSON file is not found! Check path!')
return
with open(mapping_file) as json_file:
mapping = json.load(json_file)
restricted = kwargs['restricted']
image_files = kwargs.get('image_files')
print(image_files, kwargs.keys())
if image_files:
image_data = [cv2.imread(f) for f in image_files]
else:
test_image = np.ones((1024, 1980, 3), np.uint8) * 255
image_data = [test_image,]
attribute_spec = {}
results = run_inference_engine_annotation(image_data, xml_file, bin_file,mapping, attribute_spec, py_file, restricted=restricted)
print('Program Worked!')
if __name__ == '__main__':
main()
Loading…
Cancel
Save