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

1from random import random 

2 

3from bob.bio.base.annotator import Callable, FailSafe 

4 

5 

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 

16 

17 

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 

24 

25 

26def fail_annotator(image_batch, **kwargs): 

27 all_annotations = [] 

28 for image in image_batch: 

29 all_annotations.append({}) 

30 return all_annotations 

31 

32 

33annotator = FailSafe( 

34 [Callable(fail_annotator), Callable(simple_annotator)], 

35 required_keys=["topleft", "bottomright"], 

36)