def test_constructor_with_wrong_base_path_and_name(self): base_path = TestUtils.get_resources_path() name = '' extension = '.avi' self.assertRaises(IOError, lambda: VideoAccess(base_path, name, extension))
def test_constructor_with_valid_parameters_pointing_a_image_instead_a_video( self): base_path = TestUtils.get_resources_path() name = 'todo_nexus' extension = '.mov' video_access = VideoAccess(base_path, name, extension) self.assertRaises(IOError, lambda: video_access.load())
def test_constructor_with_wrong_base_path(self): base_path = '' name = 'access01' extension = '.mov' self.assertRaises(IOError, lambda: VideoAccess(base_path, name, extension))
def get_all_accesses(self, access_modifier=AccessModifier()): if not self.dict_all_accesses: self.dict_all_accesses = {'Train': [], 'Dev': [], 'Test': []} for root, dirs, files in os.walk(self.base_path): if not dirs: for f in files: if f.lower().endswith(('.mov', '.mp4')): basename, extension = os.path.splitext(f) split_path = os.path.normpath(root).split( os.path.sep) relative_path = os.path.join(*split_path[-3:]) subject = int(basename.split('-')[0]) original_subset = split_path[-3] if original_subset == 'Train' and subject in SIW_USERS_PER_SUBSET[ 'Dev']: subset = 'Dev' else: subset = original_subset self.dict_all_accesses[subset].append( VideoAccess(self.base_path, os.path.join( relative_path, basename), extension, access_modifier=access_modifier, annotation_base_path=self. annotation_base_path, database_name=SiwDatabase.name())) for subset, list_accesses in self.dict_all_accesses.items(): list_accesses.sort(key=lambda x: x.name) return self.dict_all_accesses
def test_constructor_with_valid_parameters(self): base_path = TestUtils.get_resources_path() name = 'video' extension = '.mov' video_access = VideoAccess(base_path, name, extension) dict_images = video_access.load() self.assertEqual(len(dict_images), 6) self.assertTrue(isinstance(video_access, VideoAccess))
def test_constructor_with_valid_parameters_but_pointing_no_video_folder( self): base_path = TestUtils.get_resources_path() + '/..' name = 'bob' extension = '.mov' video_access = VideoAccess(base_path, name, extension) self.assertRaises(IOError, lambda: video_access.load())
def test_constructor_with_valid_parameters_but_pointing_no_video_folder( self): base_path = TestUtils.get_resources_path() name = 'video' extension = '.mov' access_modifier = None self.assertRaises( TypeError, lambda: VideoAccess(base_path, name, extension, access_modifier))
def test_constructor_with_valid_parameters_with_setter_access_modifier( self, dummy_dict_images=dummy_dict_images): base_path = TestUtils.get_resources_path() name = 'video' extension = '.mov' video_access = VideoAccess(base_path, name, extension) video_access.set_access_modifier(AccessModifier()) dict_images = video_access.load() AccessModifier.run.assert_called_once() self.assertEqual(dict_images, dummy_dict_images)
def get_enrolment_access(self, access_modifier=AccessModifier()): list_accesses = [] objects = self.db.objects(cls='enroll') for access in objects: path, extension = os.path.splitext(access.videofile()) list_accesses.append( VideoAccess(self.base_path, path, extension, access_modifier=access_modifier, annotation_base_path=self.annotation_base_path)) list_accesses.sort(key=lambda x: x.name) return list_accesses
def get_enrolment_access(self, access_modifier=AccessModifier()): list_accesses = [] objects = self.db.objects(cls='enroll') for access in objects: rotation_rule = self.get_rotation_rule(access) path, extension = os.path.splitext(access.videofile()) list_accesses.append( VideoAccess(self.base_path, path, extension, access_modifier=access_modifier, rotation_rule=rotation_rule, annotation_base_path=self.annotation_base_path, database_name=ReplayMobileDatabase.name())) list_accesses.sort(key=lambda x: x.name) return list_accesses
def __get_accesses_from_subset(self, subset, access_modifier): list_accesses = [] objects = self.db.objects(groups=subset) objects = self.filter_objects(objects) for access in objects: rotation_rule = self.get_rotation_rule(access) path, extension = os.path.splitext(access.videofile()) list_accesses.append( VideoAccess(self.base_path, path, extension, access_modifier=access_modifier, rotation_rule=rotation_rule, annotation_base_path=self.annotation_base_path, database_name=ReplayMobileDatabaseLite.name())) list_accesses.sort(key=lambda x: x.name) return list_accesses
def get_all_accesses(self, access_modifier=AccessModifier()): dict_all_accesses = {'Train': [], 'Dev': [], 'Test': []} for subset, subset_accesses in dict_all_accesses.items(): for access in self.db.objects( sets=THREEDMAD_SUBSETS_CORRESPONDENCE[subset]): path, extension = os.path.splitext(access.videofile()) subset_accesses.append( VideoAccess(self.base_path, path, extension, access_modifier=access_modifier, annotation_base_path=self.annotation_base_path, database_name=ThreedmadDatabase.name())) subset_accesses.sort(key=lambda x: x.name) return dict_all_accesses
def get_all_accesses(self, access_modifier=AccessModifier()): dict_all_accesses = {'Train': [], 'Dev': [], 'Test': []} for subset, subset_accesses in dict_all_accesses.items(): objects = self.db.objects( groups=REPLAY_MOBILE_SUBSETS_CORRESPONDENCE[subset]) for access in objects: rotation_rule = self.get_rotation_rule(access) path, extension = os.path.splitext(access.videofile()) subset_accesses.append( VideoAccess(self.base_path, path, extension, access_modifier=access_modifier, rotation_rule=rotation_rule, annotation_base_path=self.annotation_base_path, database_name=ReplayMobileDatabase.name())) subset_accesses.sort(key=lambda x: x.name) return dict_all_accesses
def get_all_accesses(self, access_modifier=AccessModifier()): dict_all_accesses = {} list_accesses = [] folders_correspondence = {'Train_files': 'Train', 'Dev_files': 'Dev', 'Test_files': 'Test'} for folder in OULU_FOLDERS_VIDEO: folder_set = os.path.join(self.base_path, folder) list_basename_access = self.__get_list_basename_access_from_folder(folder_set) for basename in list_basename_access: list_accesses.append(VideoAccess(self.base_path, os.path.join(folder, basename), OULU_VIDEO_EXTENSION, access_modifier=access_modifier, annotation_base_path=self.annotation_base_path, database_name=OuluNpuDatabase.name())) list_accesses.sort(key=lambda x: x.name) dict_all_accesses[folders_correspondence[folder]] = list_accesses list_accesses = [] return dict_all_accesses
def get_all_accesses(self, access_modifier=AccessModifier()): if not self.dict_all_accesses: self.dict_all_accesses = {'Train':[], 'Dev': [], 'Test': []} dict_videos = {} for root, dirs, files in os.walk(self.base_path): if not dirs: for f in files: if f.lower().endswith(('.mp4', '.mov')): basename, ext = os.path.splitext(f) if basename not in dict_videos: dict_videos[basename] = [] dict_videos[basename].append(os.path.join(root, f)) for subset, subset_accesses in self.dict_all_accesses.items(): txt_file = os.path.join(self.base_path, 'release_1', 'protocols', 'grandtest', subset + '.txt') with open(txt_file) as my_file: for line in my_file.readlines(): user, video1, video2 = line.rstrip().split(' ') basename1, _ = os.path.splitext(video1) basename2, _ = os.path.splitext(video2) for basename in [basename1, basename2]: for full_access_path in dict_videos[basename]: extension = os.path.basename(full_access_path).split('.')[1] relative_path = os.path.relpath(full_access_path, self.base_path).replace('.' + extension, '') subset_accesses.append(VideoAccess(os.path.join(self.base_path), relative_path, ('.' + extension).rstrip(), access_modifier=access_modifier, annotation_base_path=self.annotation_base_path, database_name=UvadDatabase.name())) subset_accesses.sort(key=lambda x: x.name) return self.dict_all_accesses
def get_all_accesses(self, access_modifier=AccessModifier()): if not self.dict_all_accesses: self.dict_all_accesses = {'Train': [], 'Dev': [], 'Test': []} for root, dirs, files in os.walk(self.base_path): if not dirs: for f in files: if f.lower().endswith('.avi'): basename, extension = os.path.splitext(f) split_path = os.path.normpath(root).split( os.path.sep) subject = int(split_path[-1]) if split_path[-2].startswith('train_'): if subject in CASIA_FASD_DEV_USERS: subset = 'Dev' else: subset = 'Train' else: subset = 'Test' self.dict_all_accesses[subset].append( VideoAccess( self.base_path, os.path.join(split_path[-2], split_path[-1], basename), extension, access_modifier=access_modifier, annotation_base_path=self. annotation_base_path, database_name=CasiaFasdDatabase.name())) for subset, list_accesses in self.dict_all_accesses.items(): list_accesses.sort(key=lambda x: x.name) return self.dict_all_accesses