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): ...@@ -34,7 +34,7 @@ class FailSafe(Annotator):
logger.debug( logger.debug(
"The annotator `%s' failed to annotate!", annotator, "The annotator `%s' failed to annotate!", annotator,
exc_info=True) exc_info=True)
annotations = {} annotations = None
if not annotations: if not annotations:
logger.debug( logger.debug(
"Annotator `%s' returned empty annotations.", annotator) "Annotator `%s' returned empty annotations.", annotator)
...@@ -44,5 +44,5 @@ class FailSafe(Annotator): ...@@ -44,5 +44,5 @@ class FailSafe(Annotator):
break break
else: # this else is for the for loop else: # this else is for the for loop
# we don't want to return half of the annotations # we don't want to return half of the annotations
kwargs['annotations'] = {} kwargs['annotations'] = None
return kwargs['annotations'] return kwargs['annotations']
...@@ -77,9 +77,9 @@ def annotate(database, annotator, output_dir, force, array, **kwargs): ...@@ -77,9 +77,9 @@ def annotate(database, annotator, output_dir, force, array, **kwargs):
outpath = biofile.make_path(output_dir, '.json') outpath = biofile.make_path(output_dir, '.json')
if isfile(outpath): if isfile(outpath):
if force: if force:
logger.debug("Overwriting the annotations file `%s'", outpath) logger.info("Overwriting the annotations file `%s'", outpath)
else: else:
logger.debug("The annotation `%s' already exists", outpath) logger.info("The annotation `%s' already exists", outpath)
continue continue
logger.info( logger.info(
......
from random import random
from bob.bio.base.annotator import FailSafe, Callable from bob.bio.base.annotator import FailSafe, Callable
...@@ -8,6 +9,13 @@ def simple_annotator(image, **kwargs): ...@@ -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): def fail_annotator(image, **kwargs):
return {} return {}
......
...@@ -13,7 +13,13 @@ def test_annotate(): ...@@ -13,7 +13,13 @@ def test_annotate():
runner = CliRunner() runner = CliRunner()
result = runner.invoke(annotate, args=( result = runner.invoke(annotate, args=(
'-d', 'dummy', '-a', 'dummy', '-o', tmp_dir)) '-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 # test if annotations exist
for dirpath, dirnames, filenames in os.walk(tmp_dir): 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.
Finish editing this message first!
Please register or to comment