Coverage for src/bob/bio/base/config/dummy/annotator.py: 74%
19 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-12 22:34 +0200
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-12 22:34 +0200
1from random import random
3from bob.bio.base.annotator import Callable, FailSafe
6def simple_annotator(image_batch, **kwargs):
7 all_annotations = []
8 for image in image_batch:
9 all_annotations.append(
10 {
11 "topleft": (0, 0),
12 "bottomright": image.shape,
13 }
14 )
15 return all_annotations
18def moody_annotator(image_batch, **kwargs):
19 all_annotations = simple_annotator(image_batch, **kwargs)
20 for annot in all_annotations:
21 if random() < 0.5:
22 del annot["bottomright"]
23 return all_annotations
26def fail_annotator(image_batch, **kwargs):
27 all_annotations = []
28 for image in image_batch:
29 all_annotations.append({})
30 return all_annotations
33annotator = FailSafe(
34 [Callable(fail_annotator), Callable(simple_annotator)],
35 required_keys=["topleft", "bottomright"],
36)