def iter_data(self, slice_element=None) -> Iterator[Result]: """Get frames and metadata corresponding to segment Args: slice_element (optional): If not specified all frames for the segment will be returned Yields: dict: dictionary with the fields * ``meta``: All metadata corresponding to the segment, this is the same as the data in the labels csv * ``frames``: list of :class:`PIL.Image.Image` corresponding to the frames specified in ``slice_element`` * ``id``: UID corresponding to segment """ slice_element = slice_element or slice(0, len(self)) for meta in self.meta_data[slice_element]: clip_id = self._segment_metadata_to_clip_id(meta) folder = os.path.join( self.video_segment_dir, meta[PARTICIPANT_ID_COL], meta[VIDEO_ID_COL], clip_id, ) paths = self._find_frames(folder) frames = list(resize_images(paths, self.frame_size)) meta["frame_size"] = frames[0].shape meta["num_frames"] = len(frames) meta["modality"] = 'rgb' result = {"meta": meta, "frames": frames, "id": meta[UID_COL]} yield result
def iter_data(self, slice_element=None) -> Iterator[Result]: """Get frames and metadata corresponding to segment Args: slice_element (optional): If not specified all frames for the segment will be returned Yields: dict: dictionary with the fields * ``meta``: All metadata corresponding to the segment, this is the same as the data in the labels csv * ``frames``: list of :class:`PIL.Image.Image` corresponding to the frames specified in ``slice_element`` * ``id``: UID corresponding to segment """ slice_element = slice_element or slice(0, len(self)) for meta in self.meta_data[slice_element]: folder = (Path(self.video_segment_dir) / meta["participant_id"] / meta["video_id"]) paths = [ folder / f"frame_{idx:010d}.jpg" for idx in range(meta["start_frame"], meta["stop_frame"] + 1) ] frames = list(resize_images(map(str, paths), self.frame_size)) meta["frame_size"] = frames[0].shape meta["num_frames"] = len(frames) result = { "meta": meta, "frames": frames, "id": (self.get_uid(meta)) } yield result
def iter_data(self, slice_element=None): slice_element = slice_element or slice(0, len(self)) for meta in self.meta_data[slice_element]: video_id = meta["video_id"] folder = Path( self.video_segment_dir) / meta["participant_id"] / video_id start_frame = meta["start_frame"] stop_frame = meta["stop_frame"] paths = { axis: [ folder / axis / f"frame_{idx:010d}.jpg" for idx in range(start_frame, stop_frame) ] for axis in ["u", "v"] } frames = {} for axis in "u", "v": frames[axis] = list( resize_images(map(str, paths[axis]), self.frame_size)) meta["frame_size"] = frames["u"][0].shape meta["num_frames"] = len(frames["u"]) result = { "meta": meta, "frames": list(_intersperse(frames["u"], frames["v"])), "id": self.get_uid(meta), } yield result
def test(self, mock_resize, mock_imread): mock_imread.side_effect = ['READ_IMAGE1', 'READ_IMAGE2', 'READ_IMAGE3'] mock_resize.side_effect = [ 'RESIZED_IMAGE1', 'RESIZED_IMAGE2', 'RESIZED_IMAGE3' ] input_ = ['ANY_IMAGE1', 'ANY_IMAGE2', 'ANY_IMAGE3'] received = list(resize_images(input_, img_size=1)) self.assertEqual( ['RESIZED_IMAGE1', 'RESIZED_IMAGE2', 'RESIZED_IMAGE3'], received)
def iter_data(self, slice_element=None): slice_element = slice_element or slice(0, len(self)) for meta in self.all_meta[slice_element]: video_path = os.path.join(self.videos_dir, str(meta['id'] + '.gif')) with temp_dir_for_bursting(self.shm_dir_path) as temp_burst_dir: frame_paths = burst_video_into_frames( video_path, temp_burst_dir, frame_rate=self.frame_rate) frames = list(resize_images(frame_paths, self.frame_size)) result = {'meta': meta, 'frames': frames, 'id': meta['id']} yield result
def iter_data(self, slice_element=None): slice_element = slice_element or slice(0, len(self)) for meta in self.meta_data[slice_element]: paths = self._find_uv_frames(meta) frames = {} for axis in "u", "v": frames[axis] = list(resize_images(paths[axis], self.frame_size)) meta["frame_size"] = frames["u"][0].shape meta["num_frames"] = len(frames["u"]) result = { "meta": meta, "frames": list(_intersperse(frames["u"], frames["v"])), "id": meta[UID_COL], } yield result