Skip to content
Merged
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
5 changes: 4 additions & 1 deletion tests/models/paddleocr_vl/test_modeling_paddleocr_vl.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
ids_tensor,
)
from ...test_pipeline_mixin import PipelineTesterMixin
from ...test_processing_common import url_to_local_path


if is_torch_available():
Expand Down Expand Up @@ -360,7 +361,9 @@ def setUp(self):
"content": [
{
"type": "image",
"url": "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/ocr_demo2.jpg",
"url": url_to_local_path(
"https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/ocr_demo2.jpg"
),
},
{"type": "text", "text": "OCR:"},
],
Expand Down
6 changes: 5 additions & 1 deletion tests/models/pp_chart2table/test_modeling_pp_chart2table.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from transformers import AutoModelForImageTextToText, AutoProcessor
from transformers.testing_utils import cleanup, require_torch, require_vision, slow, torch_device

from ...test_processing_common import url_to_local_path


@slow
@require_vision
Expand All @@ -33,7 +35,9 @@ def setUp(self):
"content": [
{
"type": "image",
"url": "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/chart_parsing_02.png",
"url": url_to_local_path(
"https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/chart_parsing_02.png"
),
},
],
},
Expand Down
13 changes: 6 additions & 7 deletions tests/models/pp_doclayout_v2/test_modeling_pp_doclayout_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
import tempfile
import unittest

import requests
from parameterized import parameterized

from transformers import (
PPDocLayoutV2Config,
PPDocLayoutV2ForObjectDetection,
PPDocLayoutV2ImageProcessor,
is_torch_available,
is_vision_available,
)
from transformers.image_utils import load_image
from transformers.testing_utils import (
cleanup,
require_torch,
Expand All @@ -41,14 +40,12 @@
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 url_to_local_path


if is_torch_available():
import torch

if is_vision_available():
from PIL import Image


class PPDocLayoutV2ModelTester:
def __init__(
Expand Down Expand Up @@ -583,8 +580,10 @@ def setUp(self):
model_path = "PaddlePaddle/PP-DocLayoutV2_safetensors"
self.model = PPDocLayoutV2ForObjectDetection.from_pretrained(model_path).to(torch_device)
self.image_processor = PPDocLayoutV2ImageProcessor.from_pretrained(model_path)
url = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout_demo.jpg"
self.image = Image.open(requests.get(url, stream=True).raw)
img_url = url_to_local_path(
"https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout_demo.jpg"
)
self.image = load_image(img_url)

def tearDown(self):
cleanup(torch_device, gc_collect=True)
Expand Down
12 changes: 6 additions & 6 deletions tests/models/pp_doclayout_v3/test_modeling_pp_doclayout_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import math
import unittest

import requests
from parameterized import parameterized

from transformers import (
Expand All @@ -28,6 +27,7 @@
is_torch_available,
is_vision_available,
)
from transformers.image_utils import load_image
from transformers.testing_utils import (
require_torch,
require_torch_accelerator,
Expand All @@ -39,14 +39,12 @@
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 url_to_local_path


if is_torch_available():
import torch

if is_vision_available():
from PIL import Image


class PPDocLayoutV3ModelTester:
def __init__(
Expand Down Expand Up @@ -457,8 +455,10 @@ def setUp(self):
self.image_processor = (
PPDocLayoutV3ImageProcessor.from_pretrained(model_path) if is_vision_available() else None
)
url = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout_demo.jpg"
self.image = Image.open(requests.get(url, stream=True).raw)
img_url = url_to_local_path(
"https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout_demo.jpg"
)
self.image = load_image(img_url)

def test_inference_object_detection_head(self):
inputs = self.image_processor(images=self.image, return_tensors="pt").to(torch_device)
Expand Down
12 changes: 6 additions & 6 deletions tests/models/pp_lcnet/test_modeling_pp_lcnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import inspect
import unittest

import requests
from parameterized import parameterized

from transformers import (
Expand All @@ -28,6 +27,7 @@
is_torch_available,
is_vision_available,
)
from transformers.image_utils import load_image
from transformers.testing_utils import (
require_torch,
require_torch_accelerator,
Expand All @@ -40,14 +40,12 @@
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 url_to_local_path


if is_torch_available():
import torch

if is_vision_available():
from PIL import Image


class PPLCNetModelTester:
def __init__(
Expand Down Expand Up @@ -282,8 +280,10 @@ def setUp(self):
model_path = "PaddlePaddle/PP-LCNet_x1_0_doc_ori_safetensors"
self.model = PPLCNetForImageClassification.from_pretrained(model_path).to(torch_device)
self.image_processor = PPLCNetImageProcessor.from_pretrained(model_path) if is_vision_available() else None
url = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/img_rot180_demo.jpg"
self.image = Image.open(requests.get(url, stream=True).raw)
img_url = url_to_local_path(
"https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/img_rot180_demo.jpg"
)
self.image = load_image(img_url)

def test_inference_image_classification_head(self):
inputs = self.image_processor(images=self.image, return_tensors="pt").to(torch_device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import inspect
import unittest

import requests
from parameterized import parameterized

from transformers import (
Expand All @@ -27,6 +26,7 @@
is_torch_available,
is_vision_available,
)
from transformers.image_utils import load_image
from transformers.testing_utils import (
require_cv2,
require_torch,
Expand All @@ -38,14 +38,12 @@

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor
from ...test_processing_common import url_to_local_path


if is_torch_available():
import torch

if is_vision_available():
from PIL import Image


class PPOCRV5MobileDetModelTester:
def __init__(
Expand Down Expand Up @@ -242,8 +240,10 @@ def setUp(self):
self.image_processor = (
PPOCRV5ServerDetImageProcessor.from_pretrained(model_path) if is_vision_available() else None
)
url = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_001.png"
self.image = Image.open(requests.get(url, stream=True).raw)
img_url = url_to_local_path(
"https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_001.png"
)
self.image = load_image(img_url)

def test_inference_object_detection_head(self):
inputs = self.image_processor(images=self.image, return_tensors="pt").to(torch_device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import inspect
import unittest

import requests
from parameterized import parameterized

from transformers import (
Expand All @@ -28,6 +27,7 @@
is_torch_available,
is_vision_available,
)
from transformers.image_utils import load_image
from transformers.testing_utils import (
require_torch,
require_torch_accelerator,
Expand All @@ -39,14 +39,12 @@
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 url_to_local_path


if is_torch_available():
import torch

if is_vision_available():
from PIL import Image


class PPOCRV5MobileRecModelTester:
def __init__(
Expand Down Expand Up @@ -245,8 +243,10 @@ def setUp(self):
self.image_processor = (
AutoImageProcessor.from_pretrained(model_path, return_tensors="pt") if is_vision_available() else None
)
url = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.png"
self.image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
img_url = url_to_local_path(
"https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.png"
)
self.image = load_image(img_url)

def test_inference_text_recognition_head(self):
inputs = self.image_processor(images=self.image, return_tensors="pt").to(torch_device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import inspect
import unittest

import requests
from parameterized import parameterized

from transformers import (
Expand All @@ -28,6 +27,7 @@
is_torch_available,
is_vision_available,
)
from transformers.image_utils import load_image
from transformers.testing_utils import (
require_cv2,
require_torch,
Expand All @@ -40,14 +40,12 @@
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 url_to_local_path


if is_torch_available():
import torch

if is_vision_available():
from PIL import Image


class PPOCRV5ServerDetModelTester:
def __init__(
Expand Down Expand Up @@ -263,11 +261,10 @@ def setUp(self):
self.image_processor = (
PPOCRV5ServerDetImageProcessor.from_pretrained(model_path) if is_vision_available() else None
)
self.image = Image.open(
requests.get(
"https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_001.png", stream=True
).raw
).convert("RGB")
img_url = url_to_local_path(
"https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_001.png"
)
self.image = load_image(img_url)

def test_inference_object_detection_head(self):
inputs = self.image_processor(images=self.image, return_tensors="pt").to(torch_device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import inspect
import unittest

import requests
from parameterized import parameterized

from transformers import (
Expand All @@ -28,6 +27,7 @@
is_torch_available,
is_vision_available,
)
from transformers.image_utils import load_image
from transformers.testing_utils import (
require_torch,
require_torch_accelerator,
Expand All @@ -39,14 +39,12 @@
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 url_to_local_path


if is_torch_available():
import torch

if is_vision_available():
from PIL import Image


class PPOCRV5ServerRecModelTester:
def __init__(
Expand Down Expand Up @@ -251,8 +249,10 @@ def setUp(self):
self.image_processor = (
AutoImageProcessor.from_pretrained(model_path, return_tensors="pt") if is_vision_available() else None
)
url = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.png"
self.image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
img_url = url_to_local_path(
"https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.png"
)
self.image = load_image(img_url)

def test_inference_text_recognition_head(self):
inputs = self.image_processor(images=self.image, return_tensors="pt").to(torch_device)
Expand Down
Loading
Loading