Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"export": {
"opset_version": 17,
"batch_size": 1,
"export_params": true,
"do_constant_folding": true,
"verbose": false,
"dynamo": false,
"enable_hierarchy_tags": true,
"clean_onnx": false,
"hierarchy_tag_format": "full",
"input_tensors": [
{
"name": "pixel_values",
"dtype": "float32",
"shape": [
1,
3,
256,
192
],
"value_range": [
-2.1179039478302,
2.640000343322754
]
}
],
"output_tensors": [
{
"name": "heatmaps"
}
],
"compatibility": {
"transformers_attention": "eager"
}
},
"optim": {},
"quant": {
"mode": "fp16",
"samples": 10,
"calibration_method": "minmax",
"weight_type": "uint8",
"activation_type": "uint8",
"per_channel": false,
"symmetric": false,
"weight_symmetric": null,
"activation_symmetric": null,
"save_calibration": false,
"distribution": "uniform",
"seed": null,
"calibration_load_path": null,
"calibration_save_path": null,
"op_types_to_quantize": null,
"nodes_to_exclude": null,
"task": "keypoint-detection",
"model_id": "nielsr/vitpose-base-simple",
"model_type": "vitpose",
"fp16_keep_io_types": true,
"fp16_op_block_list": null
},
"compile": null,
"loader": {
"task": "keypoint-detection",
"model_class": "VitPoseForPoseEstimation",
"model_type": "vitpose"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"export": {
"opset_version": 17,
"batch_size": 1,
"export_params": true,
"do_constant_folding": true,
"verbose": false,
"dynamo": false,
"enable_hierarchy_tags": true,
"clean_onnx": false,
"hierarchy_tag_format": "full",
"input_tensors": [
{
"name": "pixel_values",
"dtype": "float32",
"shape": [
1,
3,
256,
192
],
"value_range": [
-2.1179039478302,
2.640000343322754
]
}
],
"output_tensors": [
{
"name": "heatmaps"
}
],
"compatibility": {
"transformers_attention": "eager"
}
},
"optim": {},
"quant": null,
"compile": null,
"loader": {
"task": "keypoint-detection",
"model_class": "VitPoseForPoseEstimation",
"model_type": "vitpose"
}
}
11 changes: 11 additions & 0 deletions src/winml/modelkit/models/hf/vitpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,19 @@

from __future__ import annotations

from optimum.exporters.onnx.model_configs import VitPoseOnnxConfig
from optimum.utils.input_generators import DummyVisionInputGenerator
from transformers import VitPoseForPoseEstimation

from ...export import register_onnx_overwrite


@register_onnx_overwrite("vitpose", "keypoint-detection", library_name="transformers")
class VitPoseIOConfig(VitPoseOnnxConfig): # type: ignore[misc] # optimum base is untyped
"""Generate image inputs without reloading a processor from the model ID."""

DUMMY_INPUT_GENERATOR_CLASSES = (DummyVisionInputGenerator,)


# (model_type, task) -> HuggingFace model class
#
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/models/test_vitpose_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@

from unittest.mock import MagicMock

from transformers import VitPoseConfig

from winml.modelkit.export import resolve_io_specs
from winml.modelkit.loader import resolve_task
from winml.modelkit.models.hf import MODEL_CLASS_MAPPING
from winml.modelkit.models.hf.vitpose import MODEL_CLASS_MAPPING as VITPOSE_MAPPING
from winml.modelkit.models.hf.vitpose import VitPoseIOConfig


class TestVitPoseMapping:
Expand Down Expand Up @@ -67,3 +71,30 @@ def test_sentinel_registered_in_mapping(self):
is MODEL_CLASS_MAPPING[("vitpose", "keypoint-detection")]
)


class TestVitPoseIOConfig:
def test_resolves_dummy_input_without_loading_processor(self):
config = VitPoseConfig(
backbone_config={
"model_type": "vitpose_backbone",
"image_size": [256, 192],
"num_channels": 3,
},
num_labels=17,
scale_factor=4,
use_simple_decoder=True,
)

specs = resolve_io_specs(
"vitpose",
"keypoint-detection",
config,
height=256,
width=192,
)

assert specs["input_names"] == ["pixel_values"]
assert specs["output_names"] == ["heatmaps"]
assert specs["input_shapes"] == [(1, 3, 256, 192)]
assert specs["input_dtypes"] == ["float32"]
assert VitPoseIOConfig.__name__ == "VitPoseIOConfig"
Loading