diff --git a/src/transformers/onnx/config.py b/src/transformers/onnx/config.py index fdcc12bdcd1f0e..0dbbaba4a5047c 100644 --- a/src/transformers/onnx/config.py +++ b/src/transformers/onnx/config.py @@ -99,6 +99,7 @@ class OnnxConfig(ABC): "end_logits": {0: "batch", 1: "sequence"}, } ), + "semantic-segmentation": OrderedDict({"logits": {0: "batch", 1: "sequence"}}), "seq2seq-lm": OrderedDict({"logits": {0: "batch", 1: "decoder_sequence"}}), "sequence-classification": OrderedDict({"logits": {0: "batch"}}), "token-classification": OrderedDict({"logits": {0: "batch", 1: "sequence"}}), diff --git a/src/transformers/onnx/features.py b/src/transformers/onnx/features.py index fbfeb47250e73f..841938d01a0200 100644 --- a/src/transformers/onnx/features.py +++ b/src/transformers/onnx/features.py @@ -25,6 +25,7 @@ AutoModelForMultipleChoice, AutoModelForObjectDetection, AutoModelForQuestionAnswering, + AutoModelForSemanticSegmentation, AutoModelForSeq2SeqLM, AutoModelForSequenceClassification, AutoModelForTokenClassification, @@ -36,6 +37,7 @@ TFAutoModelForMaskedLM, TFAutoModelForMultipleChoice, TFAutoModelForQuestionAnswering, + TFAutoModelForSemanticSegmentation, TFAutoModelForSeq2SeqLM, TFAutoModelForSequenceClassification, TFAutoModelForTokenClassification, @@ -94,6 +96,7 @@ class FeaturesManager: "image-classification": AutoModelForImageClassification, "image-segmentation": AutoModelForImageSegmentation, "masked-im": AutoModelForMaskedImageModeling, + "semantic-segmentation": AutoModelForSemanticSegmentation, } if is_tf_available(): _TASKS_TO_TF_AUTOMODELS = { @@ -105,6 +108,7 @@ class FeaturesManager: "token-classification": TFAutoModelForTokenClassification, "multiple-choice": TFAutoModelForMultipleChoice, "question-answering": TFAutoModelForQuestionAnswering, + "semantic-segmentation": TFAutoModelForSemanticSegmentation, } # Set of model topologies we support associated to the features supported by each topology and the factory @@ -236,7 +240,7 @@ class FeaturesManager: "data2vec-vision": supported_features_mapping( "default", "image-classification", - "image-segmentation", + "semantic-segmentation", onnx_config_cls="models.data2vec.Data2VecVisionOnnxConfig", ), "deberta": supported_features_mapping( diff --git a/tests/onnx/test_onnx_v2.py b/tests/onnx/test_onnx_v2.py index 5634abc7706856..ac18a9463b1673 100644 --- a/tests/onnx/test_onnx_v2.py +++ b/tests/onnx/test_onnx_v2.py @@ -284,6 +284,13 @@ def _onnx_export(self, test_name, name, model_name, feature, onnx_config_class_c model_class = FeaturesManager.get_model_class_for_feature(feature) config = AutoConfig.from_pretrained(model_name) model = model_class.from_config(config) + + # It seems `nn.AdaptiveAvgPool2d` with `output_size` > 1 is not working with ONNX. We get `Segmentation fault` + # without any useful information. + if model.__class__.__name__ == "Data2VecVisionForSemanticSegmentation": + config.pool_scales = [1] * len(config.pool_scales) + model = model_class.from_config(config) + onnx_config = onnx_config_class_constructor(model.config) if is_torch_available():