Skip to content

Commit

Permalink
Fix decord import (#3094)
Browse files Browse the repository at this point in the history
fix decord import
  • Loading branch information
lhoestq authored Oct 29, 2024
1 parent d126cde commit b0906ba
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions libs/libcommon/src/libcommon/viewer_utils/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any, Optional, Union
from zlib import adler32

import datasets.config
import numpy as np
import soundfile # type: ignore
from datasets import (
Expand Down Expand Up @@ -213,11 +214,20 @@ def video(
storage_client: StorageClient,
json_path: Optional[list[Union[str, int]]] = None,
) -> Any:
from decord import VideoReader # type: ignore
if datasets.config.DECORD_AVAILABLE:
from decord import VideoReader # type: ignore

else:
VideoReader = None

if value is None:
return None
if isinstance(value, VideoReader) and hasattr(value, "_hf_encoded") and isinstance(value._hf_encoded, dict):
if (
VideoReader
and isinstance(value, VideoReader)
and hasattr(value, "_hf_encoded")
and isinstance(value._hf_encoded, dict)
):
value = value._hf_encoded # `datasets` patches `decord` to store the encoded data here
elif isinstance(value, dict):
value = {"path": value.get("path"), "bytes": value["bytes"]}
Expand Down

0 comments on commit b0906ba

Please sign in to comment.