diff --git a/tests/models/aimv2/test_modeling_aimv2.py b/tests/models/aimv2/test_modeling_aimv2.py index 085e307512fe..81e7e443eba1 100644 --- a/tests/models/aimv2/test_modeling_aimv2.py +++ b/tests/models/aimv2/test_modeling_aimv2.py @@ -18,7 +18,6 @@ import unittest import numpy as np -import requests from parameterized import parameterized from transformers import Aimv2Config, Aimv2TextConfig, Aimv2VisionConfig @@ -44,6 +43,7 @@ random_attention_mask, ) from ...test_pipeline_mixin import PipelineTesterMixin +from ...test_processing_common import load_test_image if is_torch_available(): @@ -58,8 +58,6 @@ if is_vision_available(): - from PIL import Image - from transformers import AutoImageProcessor, AutoProcessor @@ -479,7 +477,9 @@ def test_inference(self): model = Aimv2Model.from_pretrained(model_name, device_map=torch_device) processor = AutoProcessor.from_pretrained(model_name) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor( text=["a photo of a cat", "a photo of a dog"], images=image, padding=True, return_tensors="pt" ).to(model.device) @@ -513,7 +513,9 @@ def test_inference(self): model = Aimv2VisionModel.from_pretrained(model_name, device_map=torch_device) processor = AutoImageProcessor.from_pretrained(model_name) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(image, return_tensors="pt").to(model.device) with torch.no_grad(): @@ -544,7 +546,9 @@ def test_inference_for_native_resolution(self): model = Aimv2VisionModel.from_pretrained(model_name, device_map="auto") processor = AutoImageProcessor.from_pretrained(model_name) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(image, return_tensors="pt").to(model.device) with torch.no_grad(): diff --git a/tests/models/aria/test_modeling_aria.py b/tests/models/aria/test_modeling_aria.py index 9813f79ba95b..dbd9676d6aec 100644 --- a/tests/models/aria/test_modeling_aria.py +++ b/tests/models/aria/test_modeling_aria.py @@ -44,6 +44,7 @@ from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_processing_common import load_test_image if is_torch_available(): @@ -321,7 +322,9 @@ def test_small_model_integration_test_llama_batched(self): "USER: <|img|>\nWhat is this? ASSISTANT:", ] image1 = Image.open(requests.get(IMAGE_OF_VIEW_URL, stream=True).raw) - image2 = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image2 = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=[image1, image2], text=prompts, return_tensors="pt", padding=True).to( model.device, model.dtype @@ -359,7 +362,9 @@ def test_small_model_integration_test_batch(self): "USER: <|img|>\nWhat is this?\nASSISTANT:", ] image1 = Image.open(requests.get(IMAGE_OF_VIEW_URL, stream=True).raw) - image2 = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image2 = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = self.processor(images=[image1, image2], text=prompts, return_tensors="pt", padding=True).to( model.device, model.dtype @@ -399,7 +404,9 @@ def test_small_model_integration_test_llama_batched_regression(self): "USER: <|img|>\nWhat is this?\nASSISTANT: Two cats lying on a bed!\nUSER: <|img|>\nAnd this?\nASSISTANT:", ] image1 = Image.open(requests.get(IMAGE_OF_VIEW_URL, stream=True).raw) - image2 = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image2 = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=[image1, image2, image1], text=prompts, return_tensors="pt", padding=True) inputs = inputs.to(model.device, model.dtype) diff --git a/tests/models/deepseek_vl_hybrid/test_image_processing_deepseek_vl_hybrid.py b/tests/models/deepseek_vl_hybrid/test_image_processing_deepseek_vl_hybrid.py index f8646f1965cc..b2e4f6452031 100644 --- a/tests/models/deepseek_vl_hybrid/test_image_processing_deepseek_vl_hybrid.py +++ b/tests/models/deepseek_vl_hybrid/test_image_processing_deepseek_vl_hybrid.py @@ -20,6 +20,7 @@ from transformers.utils import is_torch_available, is_vision_available from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs +from ...test_processing_common import load_test_image if is_torch_available(): @@ -203,14 +204,8 @@ def test_backends_equivalence(self): if len(self.image_processing_classes) < 2: self.skipTest(reason="Skipping backends equivalence test as there are less than 2 backends") - import io - - import httpx - - dummy_image = Image.open( - io.BytesIO( - httpx.get("http://images.cocodataset.org/val2017/000000039769.jpg", follow_redirects=True).content - ) + dummy_image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) encodings = {} diff --git a/tests/models/eomt/test_modeling_eomt.py b/tests/models/eomt/test_modeling_eomt.py index 54126d707f76..6dd03fddad10 100644 --- a/tests/models/eomt/test_modeling_eomt.py +++ b/tests/models/eomt/test_modeling_eomt.py @@ -15,25 +15,20 @@ import unittest -import requests - from transformers import AutoImageProcessor, EomtConfig, EomtForUniversalSegmentation, pipeline from transformers.testing_utils import require_torch, require_torch_accelerator, require_torch_fp16, slow, torch_device -from transformers.utils import is_torch_available, is_vision_available +from transformers.utils import is_torch_available from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor from ...test_pipeline_mixin import PipelineTesterMixin +from ...test_processing_common import load_test_image if is_torch_available(): import torch -if is_vision_available(): - from PIL import Image - - class EomtForUniversalSegmentationTester: def __init__( self, @@ -175,7 +170,9 @@ def test_inference(self): model = EomtForUniversalSegmentation.from_pretrained(self.model_id, device_map="auto") processor = AutoImageProcessor.from_pretrained(self.model_id) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=image, return_tensors="pt").to(model.device) @@ -218,7 +215,9 @@ def test_inference_fp16(self): model = EomtForUniversalSegmentation.from_pretrained(self.model_id, dtype=torch.float16, device_map="auto") processor = AutoImageProcessor.from_pretrained(self.model_id) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=image, return_tensors="pt").to(model.device) @@ -234,7 +233,9 @@ def test_semantic_segmentation_inference(self): model = EomtForUniversalSegmentation.from_pretrained(model_id, device_map="auto") processor = AutoImageProcessor.from_pretrained(model_id) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=image, return_tensors="pt").to(model.device) @@ -271,7 +272,9 @@ def test_panoptic_segmentation_inference(self): model = EomtForUniversalSegmentation.from_pretrained(self.model_id, device_map="auto") processor = AutoImageProcessor.from_pretrained(self.model_id) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=image, return_tensors="pt").to(model.device) @@ -320,7 +323,9 @@ def test_instance_segmentation_inference(self): model = EomtForUniversalSegmentation.from_pretrained(model_id, device_map="auto") processor = AutoImageProcessor.from_pretrained(model_id) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=image, return_tensors="pt").to(model.device) @@ -366,7 +371,9 @@ def test_instance_segmentation_inference(self): @slow def test_segmentation_pipeline(self): - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) pipe = pipeline(model=self.model_id, subtask="panoptic", device=torch_device) output = pipe(image) diff --git a/tests/models/eomt_dinov3/test_modeling_eomt_dinov3.py b/tests/models/eomt_dinov3/test_modeling_eomt_dinov3.py index 1e3e2f872dde..7c708015063a 100644 --- a/tests/models/eomt_dinov3/test_modeling_eomt_dinov3.py +++ b/tests/models/eomt_dinov3/test_modeling_eomt_dinov3.py @@ -15,8 +15,6 @@ import unittest -import requests - from transformers import AutoImageProcessor, EomtDinov3Config, EomtDinov3ForUniversalSegmentation, pipeline from transformers.testing_utils import ( Expectations, @@ -26,21 +24,18 @@ slow, torch_device, ) -from transformers.utils import is_torch_available, is_vision_available +from transformers.utils import is_torch_available from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor from ...test_pipeline_mixin import PipelineTesterMixin +from ...test_processing_common import load_test_image if is_torch_available(): import torch -if is_vision_available(): - from PIL import Image - - class EomtDinov3ForUniversalSegmentationTester: def __init__( self, @@ -220,7 +215,9 @@ def test_inference(self): model = EomtDinov3ForUniversalSegmentation.from_pretrained(self.model_id, device_map="auto") processor = AutoImageProcessor.from_pretrained(self.model_id) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=image, return_tensors="pt").to(model.device) @@ -262,7 +259,9 @@ def test_inference_bf16(self): ) processor = AutoImageProcessor.from_pretrained(self.model_id) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=image, return_tensors="pt").to(model.device) @@ -319,7 +318,9 @@ def test_semantic_segmentation_inference(self): model = EomtDinov3ForUniversalSegmentation.from_pretrained(model_id, device_map="auto") processor = AutoImageProcessor.from_pretrained(model_id) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=image, return_tensors="pt").to(model.device) @@ -375,7 +376,9 @@ def test_panoptic_segmentation_inference(self): model = EomtDinov3ForUniversalSegmentation.from_pretrained(self.model_id, device_map="auto") processor = AutoImageProcessor.from_pretrained(self.model_id) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=image, return_tensors="pt").to(model.device) @@ -421,7 +424,9 @@ def test_instance_segmentation_inference(self): model = EomtDinov3ForUniversalSegmentation.from_pretrained(model_id, device_map="auto") processor = AutoImageProcessor.from_pretrained(model_id) - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=image, return_tensors="pt").to(model.device) @@ -463,7 +468,9 @@ def test_instance_segmentation_inference(self): self.assertTrue(0.0 <= info["score"] <= 1.0) def test_segmentation_pipeline(self): - image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) model = EomtDinov3ForUniversalSegmentation.from_pretrained(self.model_id, device_map="auto") processor = AutoImageProcessor.from_pretrained(self.model_id) diff --git a/tests/models/fast_vlm/test_modeling_fast_vlm.py b/tests/models/fast_vlm/test_modeling_fast_vlm.py index 5e26b591f339..d9b327d7eb75 100644 --- a/tests/models/fast_vlm/test_modeling_fast_vlm.py +++ b/tests/models/fast_vlm/test_modeling_fast_vlm.py @@ -39,6 +39,7 @@ from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_processing_common import load_test_image if is_torch_available(): @@ -282,7 +283,9 @@ def test_small_model_integration_test_batch(self): "user\n\nWhat is this?\nassistant", ] image1 = Image.open(requests.get("https://llava-vl.github.io/static/images/view.jpg", stream=True).raw) - image2 = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image2 = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) self.processor.tokenizer.padding_side = "left" inputs = self.processor(images=[image1, image2], text=prompts, return_tensors="pt", padding=True).to( diff --git a/tests/models/flava/test_image_processing_flava.py b/tests/models/flava/test_image_processing_flava.py index cb0dd10b6b50..dafab495a483 100644 --- a/tests/models/flava/test_image_processing_flava.py +++ b/tests/models/flava/test_image_processing_flava.py @@ -12,18 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -import io import random import unittest -import httpx import numpy as np -from PIL import Image from transformers.testing_utils import require_torch, require_vision from transformers.utils import is_torch_available, is_vision_available from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs +from ...test_processing_common import load_test_image if is_torch_available(): @@ -404,10 +402,8 @@ def test_slow_fast_equivalence(self): if len(self.image_processing_classes) < 2: self.skipTest(reason="Skipping backends equivalence test as there are less than 2 backends") - dummy_image = Image.open( - io.BytesIO( - httpx.get("http://images.cocodataset.org/val2017/000000039769.jpg", follow_redirects=True).content - ) + dummy_image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) # Create processors for each backend diff --git a/tests/models/fuyu/test_image_processing_fuyu.py b/tests/models/fuyu/test_image_processing_fuyu.py index f0b1a3110c01..2aa89b54a493 100644 --- a/tests/models/fuyu/test_image_processing_fuyu.py +++ b/tests/models/fuyu/test_image_processing_fuyu.py @@ -1,7 +1,5 @@ -import io import unittest -import httpx import numpy as np import pytest @@ -17,6 +15,7 @@ from transformers.utils import is_torch_available, is_vision_available from ...test_image_processing_common import ImageProcessingTestMixin +from ...test_processing_common import load_test_image if is_torch_available() and is_vision_available(): @@ -180,10 +179,8 @@ def test_backends_equivalence(self): if len(self.image_processing_classes) < 2: self.skipTest(reason="Skipping backends equivalence test as there are less than 2 backends") - dummy_image = Image.open( - io.BytesIO( - httpx.get("http://images.cocodataset.org/val2017/000000039769.jpg", follow_redirects=True).content - ) + dummy_image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) encodings = {} diff --git a/tests/models/idefics/test_image_processing_idefics.py b/tests/models/idefics/test_image_processing_idefics.py index c3b646543a2d..9acba9a18c18 100644 --- a/tests/models/idefics/test_image_processing_idefics.py +++ b/tests/models/idefics/test_image_processing_idefics.py @@ -11,10 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import io import unittest -import httpx import pytest from transformers.testing_utils import ( @@ -28,6 +26,7 @@ from transformers.utils import is_torch_available, is_torchvision_available, is_vision_available from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs +from ...test_processing_common import load_test_image if is_torch_available(): @@ -151,10 +150,8 @@ def test_backends_equivalence(self): if len(self.image_processing_classes) < 2: self.skipTest(reason="Skipping backends equivalence test as there are less than 2 backends") - dummy_image = Image.open( - io.BytesIO( - httpx.get("http://images.cocodataset.org/val2017/000000039769.jpg", follow_redirects=True).content - ) + dummy_image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) # Create processors for each backend diff --git a/tests/models/imagegpt/test_image_processing_imagegpt.py b/tests/models/imagegpt/test_image_processing_imagegpt.py index 8853b12381d7..4ac6b3bc150f 100644 --- a/tests/models/imagegpt/test_image_processing_imagegpt.py +++ b/tests/models/imagegpt/test_image_processing_imagegpt.py @@ -20,7 +20,6 @@ import numpy as np import pytest -import requests from datasets import load_dataset from transformers import AutoImageProcessor @@ -35,6 +34,7 @@ from transformers.utils import is_torch_available, is_vision_available from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs +from ...test_processing_common import load_test_image if is_torch_available(): @@ -285,8 +285,8 @@ def test_backends_equivalence(self): if len(self.image_processing_classes) < 2: self.skipTest(reason="Skipping backends equivalence test as there are less than 2 backends") - dummy_image = Image.open( - requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw + dummy_image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) encodings = {} diff --git a/tests/models/kimi_k25/test_image_processing_kimi_k25.py b/tests/models/kimi_k25/test_image_processing_kimi_k25.py index 8e973825c33a..927fa45d5645 100644 --- a/tests/models/kimi_k25/test_image_processing_kimi_k25.py +++ b/tests/models/kimi_k25/test_image_processing_kimi_k25.py @@ -12,10 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import io import unittest -import httpx import numpy as np from transformers.image_utils import OPENAI_CLIP_MEAN, OPENAI_CLIP_STD @@ -23,6 +21,7 @@ from transformers.utils import is_torch_available, is_vision_available from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs, prepare_video_inputs +from ...test_processing_common import load_test_image if is_torch_available(): @@ -267,10 +266,8 @@ def test_custom_pixels(self): # Override to test additional outputs for equivalence such as `image_grid_thw` def test_backends_equivalence(self): - dummy_image = Image.open( - io.BytesIO( - httpx.get("http://images.cocodataset.org/val2017/000000039769.jpg", follow_redirects=True).content - ) + dummy_image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) # Create processors for each backend diff --git a/tests/models/layoutlmv2/test_image_processing_layoutlmv2.py b/tests/models/layoutlmv2/test_image_processing_layoutlmv2.py index 13f24bfda38b..d91c82769308 100644 --- a/tests/models/layoutlmv2/test_image_processing_layoutlmv2.py +++ b/tests/models/layoutlmv2/test_image_processing_layoutlmv2.py @@ -15,7 +15,6 @@ import unittest import pytest -import requests from transformers.testing_utils import ( require_pytesseract, @@ -26,19 +25,16 @@ torch_device, ) from transformers.utils import ( - is_pytesseract_available, is_torch_available, ) from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs +from ...test_processing_common import load_test_image if is_torch_available(): import torch -if is_pytesseract_available(): - from PIL import Image - class LayoutLMv2ImageProcessingTester: def __init__( @@ -148,8 +144,8 @@ def test_backends_equivalence(self): if len(self.image_processing_classes) < 2: self.skipTest(reason="Skipping backends equivalence test as there are less than 2 backends") - dummy_image = Image.open( - requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw + dummy_image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) encodings = {} diff --git a/tests/models/lfm2_vl/test_modeling_lfm2_vl.py b/tests/models/lfm2_vl/test_modeling_lfm2_vl.py index 74e34cb9ea4d..746433978bc0 100644 --- a/tests/models/lfm2_vl/test_modeling_lfm2_vl.py +++ b/tests/models/lfm2_vl/test_modeling_lfm2_vl.py @@ -37,6 +37,7 @@ from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_processing_common import load_test_image if is_vision_available(): @@ -210,8 +211,8 @@ class Lfm2VlForConditionalGenerationIntegrationTest(unittest.TestCase): def setUp(self): self.processor = AutoProcessor.from_pretrained("LiquidAI/LFM2-VL-1.6B") self.processor.tokenizer.padding_side = "left" - self.image = Image.open( - requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw + self.image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) self.image2 = Image.open( BytesIO( @@ -296,8 +297,8 @@ class Lfm2_5VlForConditionalGenerationIntegrationTest(unittest.TestCase): def setUp(self): self.processor = AutoProcessor.from_pretrained("LiquidAI/LFM2.5-VL-1.6B") self.processor.tokenizer.padding_side = "left" - self.image = Image.open( - requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw + self.image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) self.image2 = Image.open( BytesIO( diff --git a/tests/models/llava/test_modeling_llava.py b/tests/models/llava/test_modeling_llava.py index b0bcf5afbbbd..3fb9446ef68d 100644 --- a/tests/models/llava/test_modeling_llava.py +++ b/tests/models/llava/test_modeling_llava.py @@ -45,6 +45,7 @@ from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor from ...test_pipeline_mixin import PipelineTesterMixin +from ...test_processing_common import load_test_image if is_torch_available(): @@ -367,7 +368,9 @@ def test_small_model_integration_test_llama_batched(self): "USER: \nWhat is this? ASSISTANT:", ] image1 = Image.open(requests.get("https://llava-vl.github.io/static/images/view.jpg", stream=True).raw) - image2 = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image2 = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=[image1, image2], text=prompts, return_tensors="pt", padding=True).to(torch_device) @@ -418,7 +421,9 @@ def test_small_model_integration_test_batch(self): "USER: \nWhat is this?\nASSISTANT:", ] image1 = Image.open(requests.get("https://llava-vl.github.io/static/images/view.jpg", stream=True).raw) - image2 = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image2 = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = self.processor(images=[image1, image2], text=prompts, return_tensors="pt", padding=True).to( torch_device, torch.float16 @@ -471,7 +476,9 @@ def test_small_model_integration_test_llama_batched_regression(self): "USER: \nWhat is this?\nASSISTANT: Two cats lying on a bed!\nUSER: \nAnd this?\nASSISTANT:", ] image1 = Image.open(requests.get("https://llava-vl.github.io/static/images/view.jpg", stream=True).raw) - image2 = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw) + image2 = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" + ) inputs = processor(images=[image1, image2, image1], text=prompts, return_tensors="pt", padding=True).to( torch_device diff --git a/tests/models/minimax_m3_vl/test_modeling_minimax_m3_vl.py b/tests/models/minimax_m3_vl/test_modeling_minimax_m3_vl.py index ce483eeeffad..2047c20001cd 100644 --- a/tests/models/minimax_m3_vl/test_modeling_minimax_m3_vl.py +++ b/tests/models/minimax_m3_vl/test_modeling_minimax_m3_vl.py @@ -45,6 +45,7 @@ ids_tensor, ) from ...test_pipeline_mixin import PipelineTesterMixin +from ...test_processing_common import load_test_image if is_torch_available(): @@ -696,8 +697,8 @@ def test_padding_sides_text_and_image(self): # canonical COCO two-cats photo), paired with deliberately different-length questions so the # batch genuinely needs padding. dog = Image.open(requests.get("https://picsum.photos/id/237/400/300", stream=True).raw).convert("RGB") - cats = Image.open( - requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw + cats = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ).convert("RGB") texts = [ self._prompt(processor, "What animal is this? One word."), diff --git a/tests/models/pix2struct/test_image_processing_pix2struct.py b/tests/models/pix2struct/test_image_processing_pix2struct.py index 386de5e8527e..9a7a8a60e42d 100644 --- a/tests/models/pix2struct/test_image_processing_pix2struct.py +++ b/tests/models/pix2struct/test_image_processing_pix2struct.py @@ -22,7 +22,7 @@ from transformers.utils import is_torch_available, is_vision_available from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs -from ...test_processing_common import url_to_local_path +from ...test_processing_common import load_test_image, url_to_local_path if is_torch_available(): @@ -99,15 +99,8 @@ def test_backends_equivalence(self): if len(self.image_processing_classes) < 2: self.skipTest(reason="Skipping backends equivalence test as there are less than 2 backends") - import io - - import httpx - from PIL import Image - - dummy_image = Image.open( - io.BytesIO( - httpx.get("http://images.cocodataset.org/val2017/000000039769.jpg", follow_redirects=True).content - ) + dummy_image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) # Create processors for each backend diff --git a/tests/models/qwen2_vl/test_image_processing_qwen2_vl.py b/tests/models/qwen2_vl/test_image_processing_qwen2_vl.py index fdad0a9a19fc..907f4bb4366a 100644 --- a/tests/models/qwen2_vl/test_image_processing_qwen2_vl.py +++ b/tests/models/qwen2_vl/test_image_processing_qwen2_vl.py @@ -12,13 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import io import itertools import json import tempfile import unittest -import httpx import numpy as np from transformers.image_utils import OPENAI_CLIP_MEAN, OPENAI_CLIP_STD @@ -27,6 +25,7 @@ from transformers.utils import is_torch_available, is_vision_available from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs, prepare_video_inputs +from ...test_processing_common import load_test_image if is_torch_available(): @@ -294,10 +293,8 @@ def test_backends_equivalence(self): if len(self.image_processing_classes) < 2: self.skipTest(reason="Skipping backends equivalence test as there are less than 2 backends") - dummy_image = Image.open( - io.BytesIO( - httpx.get("http://images.cocodataset.org/val2017/000000039769.jpg", follow_redirects=True).content - ) + dummy_image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) # Create processors for each backend diff --git a/tests/models/video_llama_3/test_image_processing_video_llama_3.py b/tests/models/video_llama_3/test_image_processing_video_llama_3.py index b6d956e258b0..18c5d6d968d5 100644 --- a/tests/models/video_llama_3/test_image_processing_video_llama_3.py +++ b/tests/models/video_llama_3/test_image_processing_video_llama_3.py @@ -18,7 +18,6 @@ import unittest import numpy as np -import requests from transformers.image_utils import IMAGENET_STANDARD_MEAN, IMAGENET_STANDARD_STD from transformers.models.video_llama_3.image_processing_video_llama_3 import smart_resize @@ -26,6 +25,7 @@ from transformers.utils import is_torch_available, is_vision_available from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs, prepare_video_inputs +from ...test_processing_common import load_test_image if is_torch_available(): @@ -296,8 +296,8 @@ def test_backends_equivalence(self): if len(self.image_processing_classes) < 2: self.skipTest(reason="Skipping backends equivalence test as there are less than 2 backends") - dummy_image = Image.open( - requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw + dummy_image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) encodings = {} diff --git a/tests/models/vitpose/test_image_processing_vitpose.py b/tests/models/vitpose/test_image_processing_vitpose.py index a20426d77249..5ce1a51b2eff 100644 --- a/tests/models/vitpose/test_image_processing_vitpose.py +++ b/tests/models/vitpose/test_image_processing_vitpose.py @@ -11,10 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import io import unittest -import httpx import numpy as np import pytest @@ -22,6 +20,7 @@ from transformers.utils import is_torch_available, is_vision_available from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs +from ...test_processing_common import load_test_image if is_torch_available(): @@ -233,10 +232,8 @@ def test_backends_equivalence(self): if len(self.image_processing_classes) < 2: self.skipTest(reason="Skipping backends equivalence test as there are less than 2 backends") - dummy_image = Image.open( - io.BytesIO( - httpx.get("http://images.cocodataset.org/val2017/000000039769.jpg", follow_redirects=True).content - ) + dummy_image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) boxes = [[[0, 0, 1, 1]]] diff --git a/tests/test_image_processing_common.py b/tests/test_image_processing_common.py index 4233df645d1a..75a1ba09eaec 100644 --- a/tests/test_image_processing_common.py +++ b/tests/test_image_processing_common.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. import inspect -import io import json import os import pathlib @@ -21,7 +20,6 @@ import warnings from copy import deepcopy -import httpx import numpy as np import pytest @@ -41,6 +39,8 @@ ) from transformers.utils import is_torch_available, is_vision_available +from .test_processing_common import load_test_image + if is_torch_available(): import torch @@ -175,10 +175,8 @@ def test_backends_equivalence(self): if len(self.image_processing_classes) < 2: self.skipTest(reason="Skipping backends equivalence test as there are less than 2 backends") - dummy_image = Image.open( - io.BytesIO( - httpx.get("http://images.cocodataset.org/val2017/000000039769.jpg", follow_redirects=True).content - ) + dummy_image = load_test_image( + "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg" ) # Create processors for each backend diff --git a/tests/test_processing_common.py b/tests/test_processing_common.py index 8e756923c5e4..4fdb455d253f 100644 --- a/tests/test_processing_common.py +++ b/tests/test_processing_common.py @@ -26,6 +26,7 @@ from huggingface_hub import hf_hub_download from parameterized import parameterized +from transformers.image_utils import load_image from transformers.processing_utils import ( MODALITY_TO_AUTOPROCESSOR_MAPPING, Unpack, @@ -72,6 +73,10 @@ MODALITY_INPUT_DATA[modality] = [url_to_local_path(url) for url in urls] +def load_test_image(url): + return load_image(url_to_local_path(url)) + + def prepare_image_inputs(): """This function prepares a list of PIL images""" image_inputs = [np.random.randint(255, size=(3, 30, 400), dtype=np.uint8)] diff --git a/utils/fetch_hub_objects_for_ci.py b/utils/fetch_hub_objects_for_ci.py index dfab2e2cd786..bf6fd4d8b5d9 100644 --- a/utils/fetch_hub_objects_for_ci.py +++ b/utils/fetch_hub_objects_for_ci.py @@ -51,19 +51,6 @@ "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.png", "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_001.png", "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg", - # Don't use the original COCO URLs anymore. Replace with images from https://huggingface.co/datasets/hf-internal-testing/fixtures-coco below - "http://images.cocodataset.org/val2017/000000000139.jpg", - "http://images.cocodataset.org/val2017/000000000285.jpg", - "http://images.cocodataset.org/val2017/000000000632.jpg", - "http://images.cocodataset.org/val2017/000000000724.jpg", - "http://images.cocodataset.org/val2017/000000000776.jpg", - "http://images.cocodataset.org/val2017/000000000785.jpg", - "http://images.cocodataset.org/val2017/000000000802.jpg", - "http://images.cocodataset.org/val2017/000000000872.jpg", - "http://images.cocodataset.org/val2017/000000001000.jpg", - "http://images.cocodataset.org/val2017/000000039769.jpg", - "http://images.cocodataset.org/val2017/000000077595.jpg", - "http://images.cocodataset.org/val2017/000000136466.jpg", "https://cdn.britannica.com/59/94459-050-DBA42467/Skyline-Chicago.jpg", "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg", "https://llava-vl.github.io/static/images/view.jpg",