Skip to content
Snippets Groups Projects
Commit 40ae4bb5 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Merge branch 'annotator' into 'master'

Make missing annotations None instead of empty dict

See merge request !135
parents dd5f62bb 97e70380
No related branches found
No related tags found
1 merge request!135Make missing annotations None instead of empty dict
Pipeline #
......@@ -34,7 +34,7 @@ class FailSafe(Annotator):
logger.debug(
"The annotator `%s' failed to annotate!", annotator,
exc_info=True)
annotations = {}
annotations = None
if not annotations:
logger.debug(
"Annotator `%s' returned empty annotations.", annotator)
......@@ -44,5 +44,5 @@ class FailSafe(Annotator):
break
else: # this else is for the for loop
# we don't want to return half of the annotations
kwargs['annotations'] = {}
kwargs['annotations'] = None
return kwargs['annotations']
......@@ -77,9 +77,9 @@ def annotate(database, annotator, output_dir, force, array, **kwargs):
outpath = biofile.make_path(output_dir, '.json')
if isfile(outpath):
if force:
logger.debug("Overwriting the annotations file `%s'", outpath)
logger.info("Overwriting the annotations file `%s'", outpath)
else:
logger.debug("The annotation `%s' already exists", outpath)
logger.info("The annotation `%s' already exists", outpath)
continue
logger.info(
......
from random import random
from bob.bio.base.annotator import FailSafe, Callable
......@@ -8,6 +9,13 @@ def simple_annotator(image, **kwargs):
}
def moody_annotator(image, **kwargs):
annot = simple_annotator(image, **kwargs)
if random() < 0.5:
del annot['bottomright']
return annot
def fail_annotator(image, **kwargs):
return {}
......
......@@ -13,7 +13,13 @@ def test_annotate():
runner = CliRunner()
result = runner.invoke(annotate, args=(
'-d', 'dummy', '-a', 'dummy', '-o', tmp_dir))
assert result.exit_code == 0, result.output
assertion_error_message = (
'Command exited with this output: `{}\' \n'
'If the output is empty, you can run this script locally to see '
'what is wrong:\n'
'bin/bob bio annotate -vvv --force -d dummy -a dummy -o /tmp/temp_annotations'
''.format(result.output))
assert result.exit_code == 0, assertion_error_message
# test if annotations exist
for dirpath, dirnames, filenames in os.walk(tmp_dir):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment