Coverage for src/bob/pad/face/database/replay_mobile.py: 89%

28 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2024-07-13 01:19 +0200

1import logging 

2 

3from clapper.rc import UserDefaults 

4from sklearn.pipeline import make_pipeline 

5 

6from bob.bio.base.database.utils import download_file 

7from bob.pad.base.database import FileListPadDatabase 

8from bob.pad.face.database import VideoPadSample 

9from bob.pipelines.transformers import Str_To_Types, str_to_bool 

10 

11logger = logging.getLogger(__name__) 

12rc = UserDefaults("bobrc.toml") 

13 

14 

15def get_rm_video_transform(sample): 

16 should_flip = sample.should_flip 

17 

18 def transform(video): 

19 if not should_flip: 

20 # after changing to imageio-ffmpeg, we need to flip other way around 

21 video = video[..., ::-1] 

22 return video 

23 

24 return transform 

25 

26 

27def ReplayMobilePadDatabase( 

28 protocol="grandtest", 

29 selection_style=None, 

30 max_number_of_frames=None, 

31 step_size=None, 

32 annotation_directory=None, 

33 annotation_type=None, 

34 fixed_positions=None, 

35 **kwargs, 

36): 

37 name = "pad-face-replay-mobile-620dded2.tar.gz" 

38 dataset_protocols_path = download_file( 

39 urls=[f"http://www.idiap.ch/software/bob/data/bob/bob.pad.face/{name}"], 

40 destination_filename=name, 

41 destination_sub_directory="protocols/pad", 

42 checksum="620dded2", 

43 ) 

44 

45 if annotation_directory is None: 

46 name = "annotations-replay-mobile-mtcnn-20055a07.tar.gz" 

47 annotation_directory = download_file( 

48 urls=[ 

49 f"http://www.idiap.ch/software/bob/data/bob/bob.pad.face/{name}" 

50 ], 

51 destination_filename=name, 

52 destination_sub_directory="annotations", 

53 checksum="20055a07", 

54 ) 

55 annotation_type = "eyes-center" 

56 

57 transformer = make_pipeline( 

58 Str_To_Types(fieldtypes=dict(should_flip=str_to_bool)), 

59 VideoPadSample( 

60 original_directory=rc.get("bob.db.replay_mobile.directory"), 

61 annotation_directory=annotation_directory, 

62 selection_style=selection_style, 

63 max_number_of_frames=max_number_of_frames, 

64 step_size=step_size, 

65 get_transform=get_rm_video_transform, 

66 ), 

67 ) 

68 

69 database = FileListPadDatabase( 

70 name="replay-mobile", 

71 dataset_protocols_path=dataset_protocols_path, 

72 protocol=protocol, 

73 transformer=transformer, 

74 **kwargs, 

75 ) 

76 database.annotation_type = annotation_type 

77 database.fixed_positions = fixed_positions 

78 return database