Skip to content

Commit 6142ca8

Browse files
authored
Add loading image processor (#2254)
* add loading image processor * fix style * fix pix2struct
1 parent fa87c66 commit 6142ca8

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

optimum/exporters/onnx/model_configs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,7 +2579,7 @@ def _create_dummy_input_generator_classes(self, **kwargs) -> List["DummyInputGen
25792579
dummy_inputs_generators = []
25802580
dummy_inputs_generators.append(self.DUMMY_INPUT_GENERATOR_CLASSES[0](self.task, self._normalized_config))
25812581

2582-
if self._preprocessors is None or len(self._preprocessors) != 2:
2582+
if self._preprocessors is None or len(self._preprocessors) < 2:
25832583
raise ValueError(
25842584
f"Preprocessors for pix2struct need to be available for the ONNX export to infer input static shapes. Got: {self._preprocessors}"
25852585
)
@@ -2598,7 +2598,7 @@ def _create_dummy_input_generator_classes(self, **kwargs) -> List["DummyInputGen
25982598
def overwrite_shape_and_generate_input(
25992599
self, dummy_input_gen: "DummyInputGenerator", input_name: str, framework: str, input_shapes: Dict
26002600
):
2601-
if self._preprocessors is None or len(self._preprocessors) != 2:
2601+
if self._preprocessors is None or len(self._preprocessors) < 2:
26022602
raise ValueError(
26032603
f"Preprocessors for pix2struct need to be available for the ONNX export to infer input static shapes. Got: {self._preprocessors}"
26042604
)

optimum/utils/save_utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from pathlib import Path
1919
from typing import List, Union
2020

21-
from transformers import AutoFeatureExtractor, AutoProcessor, AutoTokenizer
21+
from transformers import AutoFeatureExtractor, AutoImageProcessor, AutoProcessor, AutoTokenizer
2222

2323

2424
logger = logging.getLogger(__name__)
@@ -50,6 +50,15 @@ def maybe_load_preprocessors(
5050
)
5151
except Exception:
5252
pass
53+
54+
try:
55+
preprocessors.append(
56+
AutoImageProcessor.from_pretrained(
57+
src_name_or_path, subfolder=subfolder, trust_remote_code=trust_remote_code
58+
)
59+
)
60+
except Exception:
61+
pass
5362
return preprocessors
5463

5564

0 commit comments

Comments
 (0)