Skip to content

Commit b922b22

Browse files
samrae7Samuel Raeyonigozlan
authored
36978 | Fast image processor for DPT model (#37481)
* chore: ran codegen script * test: test_image_processor_properties * test: test_image_processor_from_dict_with_kwargs * test: wip - test_padding * test: test_padding * test: test_keep_aspect_ratio * wip * test * test: wip * test: wip * test: test_call_segmentation_maps, wip * chore: tidy up * test: test_call_segmentation_maps * fix: test_save_load_fast_slow * test: reduce labels * chore: make fixup * chore: rm comment * chore: tidy * chore remove comment * refactor: no need to infer channel dimesnion * refactor: encapsulate logic for preparing segmentation maps * refactor: improve readability of segmentation_map preparation * improvement: batched version of pad_image * chore: fixup * docs * chore: make quality * chore: remove unecessary comment * fix: add SemanticSegmentationMixin * feat: add post_process_depth_estimation to fast dpt image processor * chore: fix formatting * remove max_height, max_width * fix: better way of processin segmentation maps - copied from Beit Fast processor * chore: formatting + remove TODO * chore: fixup styles * chore: remove unecessary line break * chore: core review suggestion to remove autodocstring * fix: add do_reduce_labels logic + refactor - refactor preprocess logic to make it consistent with other processors - add missing reduce labels logic * refactor: remove deprecated mixin * chore: fixup * use modular for dpt + final nit changes * fix style --------- Co-authored-by: Samuel Rae <[email protected]> Co-authored-by: yonigozlan <[email protected]>
1 parent c27f628 commit b922b22

File tree

7 files changed

+1018
-158
lines changed

7 files changed

+1018
-158
lines changed

docs/source/en/model_doc/dpt.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ If you're interested in submitting a resource to be included here, please feel f
7878

7979
[[autodoc]] DPTImageProcessor
8080
- preprocess
81+
82+
## DPTImageProcessorFast
83+
84+
[[autodoc]] DPTImageProcessorFast
85+
- preprocess
8186
- post_process_semantic_segmentation
87+
- post_process_depth_estimation
8288

8389
## DPTModel
8490

src/transformers/models/auto/image_processing_auto.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@
7474
("data2vec-vision", ("BeitImageProcessor", "BeitImageProcessorFast")),
7575
("deformable_detr", ("DeformableDetrImageProcessor", "DeformableDetrImageProcessorFast")),
7676
("deit", ("DeiTImageProcessor", "DeiTImageProcessorFast")),
77-
("depth_anything", ("DPTImageProcessor",)),
77+
("depth_anything", ("DPTImageProcessor", "DPTImageProcessorFast")),
7878
("depth_pro", ("DepthProImageProcessor", "DepthProImageProcessorFast")),
7979
("deta", ("DetaImageProcessor",)),
8080
("detr", ("DetrImageProcessor", "DetrImageProcessorFast")),
8181
("dinat", ("ViTImageProcessor", "ViTImageProcessorFast")),
8282
("dinov2", ("BitImageProcessor", "BitImageProcessorFast")),
8383
("donut-swin", ("DonutImageProcessor", "DonutImageProcessorFast")),
84-
("dpt", ("DPTImageProcessor",)),
84+
("dpt", ("DPTImageProcessor", "DPTImageProcessorFast")),
8585
("efficientformer", ("EfficientFormerImageProcessor",)),
8686
("efficientnet", ("EfficientNetImageProcessor", "EfficientNetImageProcessorFast")),
8787
("flava", ("FlavaImageProcessor", "FlavaImageProcessorFast")),

src/transformers/models/beit/image_processing_beit_fast.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,6 @@ def _preprocess_segmentation_maps(
174174
processed_segmentation_maps = processed_segmentation_maps.to(torch.int64)
175175
return processed_segmentation_maps
176176

177-
def __call__(self, images, segmentation_maps=None, **kwargs):
178-
# Overrides the `__call__` method of the `Preprocessor` class such that the images and segmentation maps can both
179-
# be passed in as positional arguments.
180-
return super().__call__(images, segmentation_maps=segmentation_maps, **kwargs)
181-
182177
@auto_docstring
183178
def preprocess(
184179
self,

src/transformers/models/dpt/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from .configuration_dpt import *
2222
from .feature_extraction_dpt import *
2323
from .image_processing_dpt import *
24+
from .image_processing_dpt_fast import *
2425
from .modeling_dpt import *
2526
else:
2627
import sys

0 commit comments

Comments
 (0)