Add Fast PVT Processor (#37204)
* Add Fast PVT Processor * Update image_processing_pvt_fast.py * Update image_processing_pvt_fast.py * remove kwargs --------- Co-authored-by: Yoni Gozlan <74535834+yonigozlan@users.noreply.github.com>
This commit is contained in:
@@ -64,6 +64,11 @@ This model was contributed by [Xrenya](https://huggingface.co/Xrenya). The origi
|
|||||||
[[autodoc]] PvtImageProcessor
|
[[autodoc]] PvtImageProcessor
|
||||||
- preprocess
|
- preprocess
|
||||||
|
|
||||||
|
## PvtImageProcessorFast
|
||||||
|
|
||||||
|
[[autodoc]] PvtImageProcessorFast
|
||||||
|
- preprocess
|
||||||
|
|
||||||
## PvtForImageClassification
|
## PvtForImageClassification
|
||||||
|
|
||||||
[[autodoc]] PvtForImageClassification
|
[[autodoc]] PvtForImageClassification
|
||||||
|
|||||||
@@ -133,8 +133,8 @@ else:
|
|||||||
("pixtral", ("PixtralImageProcessor", "PixtralImageProcessorFast")),
|
("pixtral", ("PixtralImageProcessor", "PixtralImageProcessorFast")),
|
||||||
("poolformer", ("PoolFormerImageProcessor",)),
|
("poolformer", ("PoolFormerImageProcessor",)),
|
||||||
("prompt_depth_anything", ("PromptDepthAnythingImageProcessor",)),
|
("prompt_depth_anything", ("PromptDepthAnythingImageProcessor",)),
|
||||||
("pvt", ("PvtImageProcessor",)),
|
("pvt", ("PvtImageProcessor", "PvtImageProcessorFast")),
|
||||||
("pvt_v2", ("PvtImageProcessor",)),
|
("pvt_v2", ("PvtImageProcessor", "PvtImageProcessorFast")),
|
||||||
("qwen2_5_vl", ("Qwen2VLImageProcessor", "Qwen2VLImageProcessorFast")),
|
("qwen2_5_vl", ("Qwen2VLImageProcessor", "Qwen2VLImageProcessorFast")),
|
||||||
("qwen2_vl", ("Qwen2VLImageProcessor", "Qwen2VLImageProcessorFast")),
|
("qwen2_vl", ("Qwen2VLImageProcessor", "Qwen2VLImageProcessorFast")),
|
||||||
("regnet", ("ConvNextImageProcessor", "ConvNextImageProcessorFast")),
|
("regnet", ("ConvNextImageProcessor", "ConvNextImageProcessorFast")),
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ from ...utils.import_utils import define_import_structure
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .configuration_pvt import *
|
from .configuration_pvt import *
|
||||||
from .image_processing_pvt import *
|
from .image_processing_pvt import *
|
||||||
|
from .image_processing_pvt_fast import *
|
||||||
from .modeling_pvt import *
|
from .modeling_pvt import *
|
||||||
else:
|
else:
|
||||||
import sys
|
import sys
|
||||||
|
|||||||
44
src/transformers/models/pvt/image_processing_pvt_fast.py
Normal file
44
src/transformers/models/pvt/image_processing_pvt_fast.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
# Copyright 2025 The HuggingFace Inc. team. All rights reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# 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.
|
||||||
|
"""Fast Image processor class for Pvt."""
|
||||||
|
|
||||||
|
from ...image_processing_utils_fast import (
|
||||||
|
BASE_IMAGE_PROCESSOR_FAST_DOCSTRING,
|
||||||
|
BaseImageProcessorFast,
|
||||||
|
)
|
||||||
|
from ...image_utils import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, PILImageResampling
|
||||||
|
from ...utils import add_start_docstrings
|
||||||
|
|
||||||
|
|
||||||
|
@add_start_docstrings(
|
||||||
|
"Constructs a fast Pvt image processor.",
|
||||||
|
BASE_IMAGE_PROCESSOR_FAST_DOCSTRING,
|
||||||
|
)
|
||||||
|
class PvtImageProcessorFast(BaseImageProcessorFast):
|
||||||
|
resample = PILImageResampling.BILINEAR
|
||||||
|
image_mean = IMAGENET_DEFAULT_MEAN
|
||||||
|
image_std = IMAGENET_DEFAULT_STD
|
||||||
|
size = {"height": 224, "width": 224}
|
||||||
|
default_to_square = True
|
||||||
|
crop_size = None
|
||||||
|
do_resize = True
|
||||||
|
do_center_crop = None
|
||||||
|
do_rescale = True
|
||||||
|
do_normalize = True
|
||||||
|
do_convert_rgb = None
|
||||||
|
model_input_names = ["pixel_values"]
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ["PvtImageProcessorFast"]
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from transformers.testing_utils import require_torch, require_vision
|
from transformers.testing_utils import require_torch, require_vision
|
||||||
from transformers.utils import is_vision_available
|
from transformers.utils import is_torchvision_available, is_vision_available
|
||||||
|
|
||||||
from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs
|
from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs
|
||||||
|
|
||||||
@@ -24,6 +24,9 @@ from ...test_image_processing_common import ImageProcessingTestMixin, prepare_im
|
|||||||
if is_vision_available():
|
if is_vision_available():
|
||||||
from transformers import PvtImageProcessor
|
from transformers import PvtImageProcessor
|
||||||
|
|
||||||
|
if is_torchvision_available():
|
||||||
|
from transformers import PvtImageProcessorFast
|
||||||
|
|
||||||
|
|
||||||
class PvtImageProcessingTester:
|
class PvtImageProcessingTester:
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -81,6 +84,7 @@ class PvtImageProcessingTester:
|
|||||||
@require_vision
|
@require_vision
|
||||||
class PvtImageProcessingTest(ImageProcessingTestMixin, unittest.TestCase):
|
class PvtImageProcessingTest(ImageProcessingTestMixin, unittest.TestCase):
|
||||||
image_processing_class = PvtImageProcessor if is_vision_available() else None
|
image_processing_class = PvtImageProcessor if is_vision_available() else None
|
||||||
|
fast_image_processing_class = PvtImageProcessorFast if is_torchvision_available() else None
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
@@ -91,7 +95,8 @@ class PvtImageProcessingTest(ImageProcessingTestMixin, unittest.TestCase):
|
|||||||
return self.image_processor_tester.prepare_image_processor_dict()
|
return self.image_processor_tester.prepare_image_processor_dict()
|
||||||
|
|
||||||
def test_image_processor_properties(self):
|
def test_image_processor_properties(self):
|
||||||
image_processing = self.image_processing_class(**self.image_processor_dict)
|
for image_processing_class in self.image_processor_list:
|
||||||
|
image_processing = image_processing_class(**self.image_processor_dict)
|
||||||
self.assertTrue(hasattr(image_processing, "image_mean"))
|
self.assertTrue(hasattr(image_processing, "image_mean"))
|
||||||
self.assertTrue(hasattr(image_processing, "image_std"))
|
self.assertTrue(hasattr(image_processing, "image_std"))
|
||||||
self.assertTrue(hasattr(image_processing, "do_normalize"))
|
self.assertTrue(hasattr(image_processing, "do_normalize"))
|
||||||
@@ -99,8 +104,9 @@ class PvtImageProcessingTest(ImageProcessingTestMixin, unittest.TestCase):
|
|||||||
self.assertTrue(hasattr(image_processing, "size"))
|
self.assertTrue(hasattr(image_processing, "size"))
|
||||||
|
|
||||||
def test_image_processor_from_dict_with_kwargs(self):
|
def test_image_processor_from_dict_with_kwargs(self):
|
||||||
image_processor = self.image_processing_class.from_dict(self.image_processor_dict)
|
for image_processing_class in self.image_processor_list:
|
||||||
|
image_processor = image_processing_class.from_dict(self.image_processor_dict)
|
||||||
self.assertEqual(image_processor.size, {"height": 18, "width": 18})
|
self.assertEqual(image_processor.size, {"height": 18, "width": 18})
|
||||||
|
|
||||||
image_processor = self.image_processing_class.from_dict(self.image_processor_dict, size=42)
|
image_processor = image_processing_class.from_dict(self.image_processor_dict, size=42)
|
||||||
self.assertEqual(image_processor.size, {"height": 42, "width": 42})
|
self.assertEqual(image_processor.size, {"height": 42, "width": 42})
|
||||||
|
|||||||
Reference in New Issue
Block a user