diff --git a/optimum/exporters/onnx/base.py b/optimum/exporters/onnx/base.py index 198094cbd2..d93c0b29f6 100644 --- a/optimum/exporters/onnx/base.py +++ b/optimum/exporters/onnx/base.py @@ -133,14 +133,7 @@ class OnnxConfig(ExportConfig, ABC): "feature-extraction": OrderedDict({"last_hidden_state": {0: "batch_size", 1: "sequence_length"}}), "fill-mask": OrderedDict({"logits": {0: "batch_size", 1: "sequence_length"}}), "image-classification": OrderedDict({"logits": {0: "batch_size"}}), - # TODO: Is this the same thing as semantic-segmentation? - "image-segmentation": OrderedDict( - { - "logits": {0: "batch_size", 1: "num_queries"}, - "pred_boxes": {0: "batch_size", 1: "num_queries"}, - "pred_masks": {0: "batch_size", 1: "num_queries"}, - } - ), + "image-segmentation": OrderedDict({"logits": {0: "batch_size", 1: "num_labels", 2: "height", 3: "width"}}), "image-to-text": OrderedDict({"logits": {0: "batch_size", 1: "sequence_length"}}), "mask-generation": OrderedDict({"logits": {0: "batch_size"}}), "masked-im": OrderedDict( diff --git a/optimum/exporters/onnx/model_configs.py b/optimum/exporters/onnx/model_configs.py index 1d203daa63..20304e6d6c 100644 --- a/optimum/exporters/onnx/model_configs.py +++ b/optimum/exporters/onnx/model_configs.py @@ -572,7 +572,7 @@ class ConvNextOnnxConfig(ViTOnnxConfig): class MobileViTOnnxConfig(ViTOnnxConfig): - pass + ATOL_FOR_VALIDATION = 1e-4 class RegNetOnnxConfig(ViTOnnxConfig): @@ -588,9 +588,14 @@ class DetrOnnxConfig(ViTOnnxConfig): DEFAULT_ONNX_OPSET = 12 @property - def inputs(self) -> Dict[str, Dict[int, str]]: - # TODO: is pixel mask needed? - return {**super().inputs, "pixel_mask": {0: "batch_size"}} + def outputs(self) -> Dict[str, Dict[int, str]]: + if self.task == "image-segmentation": + return { + "logits": {0: "batch_size", 1: "num_queries"}, + "pred_masks": {0: "batch_size", 1: "num_queries"}, + } + else: + return super().outputs class YolosOnnxConfig(ViTOnnxConfig): diff --git a/optimum/exporters/tasks.py b/optimum/exporters/tasks.py index e841a6e047..0b7246034c 100644 --- a/optimum/exporters/tasks.py +++ b/optimum/exporters/tasks.py @@ -161,7 +161,7 @@ class TasksManager: "object-detection": "AutoModelForObjectDetection", "question-answering": "AutoModelForQuestionAnswering", "image-classification": "AutoModelForImageClassification", - "image-segmentation": "AutoModelForImageSegmentation", + "image-segmentation": ("AutoModelForImageSegmentation", "AutoModelForSemanticSegmentation"), "mask-generation": "AutoModel", "masked-im": "AutoModelForMaskedImageModeling", "semantic-segmentation": "AutoModelForSemanticSegmentation", @@ -632,6 +632,7 @@ class TasksManager: "mobilevit": supported_tasks_mapping( "feature-extraction", "image-classification", + "image-segmentation", onnx="MobileViTOnnxConfig", ), "mobilenet-v1": supported_tasks_mapping( @@ -766,6 +767,7 @@ class TasksManager: "segformer": supported_tasks_mapping( "feature-extraction", "image-classification", + "image-segmentation", "semantic-segmentation", onnx="SegformerOnnxConfig", ),