[Perf] Hash videos by source bytes (#49607)
Signed-off-by: Guan-Ming (Wesley) Chiu <105915352+guan404ming@users.noreply.github.com> Signed-off-by: Guan-Ming Chiu <105915352+guan404ming@users.noreply.github.com> Co-authored-by: Isotr0py <2037008807@qq.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Isotr0py
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
d2ca3002d9
commit
04502deca2
@@ -366,6 +366,20 @@ class VideoProcessorItems(ProcessorBatchItems[HfVideoItem | None]):
|
||||
|
||||
self.metadata = metadata
|
||||
|
||||
def _unwrap(self, item: Any) -> Any:
|
||||
if isinstance(item, tuple):
|
||||
frames, metadata = item
|
||||
return super()._unwrap(frames), metadata
|
||||
return super()._unwrap(item)
|
||||
|
||||
def get_item_for_hash(self, index: int) -> Any:
|
||||
item = self.data[index]
|
||||
if isinstance(item, MediaWithBytes) and isinstance(self.metadata, list):
|
||||
metadata = self.metadata[index]
|
||||
if metadata is not None:
|
||||
return item, metadata
|
||||
return item
|
||||
|
||||
def get_num_frames(self, item_idx: int) -> int:
|
||||
video = self.get(item_idx)
|
||||
if video is None:
|
||||
@@ -552,7 +566,10 @@ class MultiModalDataParser:
|
||||
def _get_video_with_metadata(
|
||||
self,
|
||||
video: VideoItem,
|
||||
) -> tuple[np.ndarray, dict[str, Any] | None]:
|
||||
) -> tuple[np.ndarray | MediaWithBytes[np.ndarray], dict[str, Any] | None]:
|
||||
if isinstance(video, MediaWithBytes):
|
||||
new_video, metadata = self._get_video_with_metadata(video.media)
|
||||
return MediaWithBytes(new_video, video.original_bytes), metadata
|
||||
if isinstance(video, tuple):
|
||||
return video
|
||||
if isinstance(video, list):
|
||||
@@ -653,7 +670,11 @@ class MultiModalDataParser:
|
||||
else:
|
||||
data_items = data # type: ignore[assignment]
|
||||
|
||||
new_videos = list[tuple[np.ndarray, dict[str, Any] | None]]()
|
||||
new_videos = list[
|
||||
np.ndarray
|
||||
| MediaWithBytes[np.ndarray]
|
||||
| tuple[np.ndarray | MediaWithBytes[np.ndarray], dict[str, Any]]
|
||||
]()
|
||||
metadata_lst: list[dict[str, Any] | None] = []
|
||||
for data_item in data_items:
|
||||
video, metadata = self._get_video_with_metadata(data_item)
|
||||
@@ -664,12 +685,9 @@ class MultiModalDataParser:
|
||||
"Please check your video input in `multi_modal_data`"
|
||||
)
|
||||
new_videos.append((video, metadata))
|
||||
metadata_lst.append(metadata)
|
||||
else:
|
||||
new_videos.append(video)
|
||||
|
||||
if not self.video_needs_metadata:
|
||||
metadata = None
|
||||
metadata_lst.append(metadata)
|
||||
|
||||
return VideoProcessorItems(new_videos, metadata=metadata_lst)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user