Skip to content

fix Image.open failure in case "tests/models/prompt_depth_anything/te…#44645

Merged
ydshieh merged 3 commits intohuggingface:mainfrom
sywangyi:prompt_depth_test
Mar 27, 2026
Merged

fix Image.open failure in case "tests/models/prompt_depth_anything/te…#44645
ydshieh merged 3 commits intohuggingface:mainfrom
sywangyi:prompt_depth_test

Conversation

@sywangyi
Copy link
Copy Markdown
Contributor

======================================================================== FAILURES ========================================================================
_________________________________________________ PromptDepthAnythingModelIntegrationTest.test_inference _________________________________________________

self = <tests.models.prompt_depth_anything.test_modeling_prompt_depth_anything.PromptDepthAnythingModelIntegrationTest testMethod=test_inference>

    def test_inference(self):
        image_processor = AutoImageProcessor.from_pretrained("depth-anything/prompt-depth-anything-vits-hf")
        model = PromptDepthAnythingForDepthEstimation.from_pretrained(
            "depth-anything/prompt-depth-anything-vits-hf"
        ).to(torch_device)

>       image = prepare_img()
                ^^^^^^^^^^^^^

tests/models/prompt_depth_anything/test_modeling_prompt_depth_anything.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/models/prompt_depth_anything/test_modeling_prompt_depth_anything.py:220: in prepare_img
    image = Image.open(requests.get(url, stream=True).raw)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

fp = <_io.BytesIO object at 0x712c38143100>, mode = 'r', formats = ['BMP', 'DIB', 'GIF', 'JPEG', 'PPM', 'PNG', ...]

    def open(fp, mode="r", formats=None):
        """
        Opens and identifies the given image file.

        This is a lazy operation; this function identifies the file, but
        the file remains open and the actual image data is not read from
        the file until you try to process the data (or call the
        :py:meth:`~PIL.Image.Image.load` method).  See
        :py:func:`~PIL.Image.new`. See :ref:`file-handling`.

        :param fp: A filename (string), pathlib.Path object or a file object.
           The file object must implement ``file.read``,
           ``file.seek``, and ``file.tell`` methods,
           and be opened in binary mode. The file object will also seek to zero
           before reading.
        :param mode: The mode.  If given, this argument must be "r".
        :param formats: A list or tuple of formats to attempt to load the file in.
           This can be used to restrict the set of formats checked.
           Pass ``None`` to try all supported formats. You can print the set of
           available formats by running ``python3 -m PIL`` or using
           the :py:func:`PIL.features.pilinfo` function.
        :returns: An :py:class:`~PIL.Image.Image` object.
        :exception FileNotFoundError: If the file cannot be found.
        :exception PIL.UnidentifiedImageError: If the image cannot be opened and
           identified.
        :exception ValueError: If the ``mode`` is not "r", or if a ``StringIO``
           instance is used for ``fp``.
        :exception TypeError: If ``formats`` is not ``None``, a list or a tuple.
        """

        if mode != "r":
            msg = f"bad mode {repr(mode)}"
            raise ValueError(msg)
        elif isinstance(fp, io.StringIO):
            msg = (
                "StringIO cannot be used to open an image. "
                "Binary data must be used instead."
            )
            raise ValueError(msg)

        if formats is None:
            formats = ID
        elif not isinstance(formats, (list, tuple)):
            msg = "formats must be a list or tuple"
            raise TypeError(msg)

        exclusive_fp = False
        filename = ""
        if isinstance(fp, Path):
            filename = str(fp.resolve())
        elif is_path(fp):
            filename = fp

        if filename:
            fp = builtins.open(filename, "rb")
            exclusive_fp = True

        try:
            fp.seek(0)
        except (AttributeError, io.UnsupportedOperation):
            fp = io.BytesIO(fp.read())
            exclusive_fp = True

        prefix = fp.read(16)

        preinit()

        accept_warnings = []

        def _open_core(fp, filename, prefix, formats):
            for i in formats:
                i = i.upper()
                if i not in OPEN:
                    init()
                try:
                    factory, accept = OPEN[i]
                    result = not accept or accept(prefix)
                    if type(result) in [str, bytes]:
                        accept_warnings.append(result)
                    elif result:
                        fp.seek(0)
                        im = factory(fp, filename)
                        _decompression_bomb_check(im.size)
                        return im
                except (SyntaxError, IndexError, TypeError, struct.error):
                    # Leave disabled by default, spams the logs with image
                    # opening failures that are entirely expected.
                    # logger.debug("", exc_info=True)
                    continue
                except BaseException:
                    if exclusive_fp:
                        fp.close()
                    raise
            return None

        im = _open_core(fp, filename, prefix, formats)

        if im is None and formats is ID:
            checked_formats = formats.copy()
            if init():
                im = _open_core(
                    fp,
                    filename,
                    prefix,
                    tuple(format for format in formats if format not in checked_formats),
                )

        if im:
            im._exclusive_fp = exclusive_fp
            return im

        if exclusive_fp:
            fp.close()
        for message in accept_warnings:
            warnings.warn(message)
        msg = "cannot identify image file %r" % (filename if filename else fp)
>       raise UnidentifiedImageError(msg)
E       PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x712c38143100>

/opt/venv/lib/python3.12/site-packages/PIL/Image.py:3280: UnidentifiedImageError

The root cause of this error is that the content retrieved is not actual image bytes. A common case is that a GitHub blob URL with ?raw=true returns an HTML or redirect page instead of raw image data.

…st_modeling_prompt_depth_anything.py::PromptDepthAnythingModelIntegrationTest::test_inference"

Signed-off-by: Wang, Yi <yi.a.wang@intel.com>
Copy link
Copy Markdown
Member

@IlyasMoutawwakil IlyasMoutawwakil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thansk ! are there any more cases of this ?

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@IlyasMoutawwakil
Copy link
Copy Markdown
Member

it seems there some others, should replace all of them ? @ydshieh

Copy link
Copy Markdown
Collaborator

@ydshieh ydshieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! It seems it depends on CI network environment, but the new approach is the most sure one.

@ydshieh
Copy link
Copy Markdown
Collaborator

ydshieh commented Mar 26, 2026

@sywangyi

would you like push the change for

class LlavaNextForConditionalGenerationIntegrationTest(unittest.TestCase):
    def setUp(self):
        self.processor = AutoProcessor.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")
        url = "https://github.com/haotian-liu/LLaVA/blob/1a91fc274d7c35a9b50b3cb29c4247ae5837ce39/images/llava_v1_5_radar.jpg?raw=true"

and

class VideoLlama3IntegrationTest(unittest.TestCase):
    .... 

    url = "https://github.com/DAMO-NLP-SG/VideoLLaMA3/raw/refs/heads/main/assets/sora.png"

??

sywangyi and others added 2 commits March 27, 2026 09:13
Signed-off-by: Wang, Yi <yi.a.wang@intel.com>
@ydshieh ydshieh enabled auto-merge March 27, 2026 10:49
@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: llava_next, prompt_depth_anything, video_llama_3

@ydshieh ydshieh disabled auto-merge March 27, 2026 11:09
@ydshieh ydshieh merged commit 0efcf1b into huggingface:main Mar 27, 2026
18 checks passed
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Mar 27, 2026
* fix Image.open failure in case "tests/models/prompt_depth_anything/test_modeling_prompt_depth_anything.py::PromptDepthAnythingModelIntegrationTest::test_inference"

Signed-off-by: Wang, Yi <yi.a.wang@intel.com>

* updated

Signed-off-by: Wang, Yi <yi.a.wang@intel.com>

---------

Signed-off-by: Wang, Yi <yi.a.wang@intel.com>
Co-authored-by: Yih-Dar <2521628+ydshieh@users.noreply.github.com>
NielsRogge pushed a commit to NielsRogge/transformers that referenced this pull request Mar 30, 2026
* fix Image.open failure in case "tests/models/prompt_depth_anything/test_modeling_prompt_depth_anything.py::PromptDepthAnythingModelIntegrationTest::test_inference"

Signed-off-by: Wang, Yi <yi.a.wang@intel.com>

* updated

Signed-off-by: Wang, Yi <yi.a.wang@intel.com>

---------

Signed-off-by: Wang, Yi <yi.a.wang@intel.com>
Co-authored-by: Yih-Dar <2521628+ydshieh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants