def _make_encoded_video_dataset(self, data) -> 'EncodedVideoDataset': ds: EncodedVideoDataset = labeled_encoded_video_dataset( pathlib.Path(data), self.clip_sampler, video_sampler=self.video_sampler, decode_audio=self.decode_audio, decoder=self.decoder, ) return ds
def load_data(self, data: Any, dataset: IterableDataset) -> 'EncodedVideoDataset': ds: EncodedVideoDataset = labeled_encoded_video_dataset( data, self.clip_sampler, video_sampler=self.video_sampler, decode_audio=self.decode_audio, decoder=self.decoder, ) if self.training: label_to_class_mapping = {p[1]: p[0].split("/")[-2] for p in ds._labeled_videos._paths_and_labels} self.set_state(ClassificationState(label_to_class_mapping)) dataset.num_classes = len(np.unique([s[1]['label'] for s in ds._labeled_videos])) return ds
def test_random_video_sampler(self, decoder): with mock_encoded_video_dataset_file() as (mock_csv, expected, total_duration): clip_sampler = make_clip_sampler("uniform", total_duration) dataset = labeled_encoded_video_dataset( data_path=mock_csv, clip_sampler=clip_sampler, video_sampler=RandomSampler, decode_audio=False, decoder=decoder, ) for _ in range(2): actual = [(sample["label"], sample["video"]) for sample in dataset] assert_unordered_list_compare_true(self, expected, actual)
def load_data(self, data: str, dataset: Optional[Any] = None) -> 'EncodedVideoDataset': ds: EncodedVideoDataset = labeled_encoded_video_dataset( pathlib.Path(data), self.clip_sampler, video_sampler=self.video_sampler, decode_audio=self.decode_audio, decoder=self.decoder, ) if self.training: label_to_class_mapping = { p[1]: p[0].split("/")[-2] for p in ds._labeled_videos._paths_and_labels } self.set_state(LabelsState(label_to_class_mapping)) dataset.num_classes = len( np.unique([s[1]['label'] for s in ds._labeled_videos])) return ds
def test_single_clip_per_video_works(self, decoder): with mock_encoded_video_dataset_file() as (mock_csv, expected, total_duration): clip_sampler = make_clip_sampler("uniform", total_duration) dataset = labeled_encoded_video_dataset( data_path=mock_csv, clip_sampler=clip_sampler, video_sampler=SequentialSampler, decode_audio=False, decoder=decoder, ) test_dataloader = DataLoader(dataset, batch_size=None, num_workers=2) for _ in range(2): actual = [(sample["label"], sample["video"]) for sample in test_dataloader] assert_unordered_list_compare_true(self, expected, actual)