Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions tests/models/aimv2/test_modeling_aimv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import unittest

import numpy as np
import requests
from parameterized import parameterized

from transformers import Aimv2Config, Aimv2TextConfig, Aimv2VisionConfig
Expand All @@ -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():
Expand All @@ -58,8 +58,6 @@


if is_vision_available():
from PIL import Image

from transformers import AutoImageProcessor, AutoProcessor


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand Down
13 changes: 10 additions & 3 deletions tests/models/aria/test_modeling_aria.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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 = {}
Expand Down
33 changes: 20 additions & 13 deletions tests/models/eomt/test_modeling_eomt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
33 changes: 20 additions & 13 deletions tests/models/eomt_dinov3/test_modeling_eomt_dinov3.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

import unittest

import requests

from transformers import AutoImageProcessor, EomtDinov3Config, EomtDinov3ForUniversalSegmentation, pipeline
from transformers.testing_utils import (
Expectations,
Expand All @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion tests/models/fast_vlm/test_modeling_fast_vlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -282,7 +283,9 @@ def test_small_model_integration_test_batch(self):
"user\n<image>\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(
Expand Down
10 changes: 3 additions & 7 deletions tests/models/flava/test_image_processing_flava.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions tests/models/fuyu/test_image_processing_fuyu.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import io
import unittest

import httpx
import numpy as np
import pytest

Expand All @@ -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():
Expand Down Expand Up @@ -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 = {}
Expand Down
Loading
Loading