Skip to content

Romanove/model metadata - #663

Draft
warrkan wants to merge 7 commits into
masterfrom
romanove/model_metadata
Draft

warrkan wants to merge 7 commits into
masterfrom
romanove/model_metadata

Conversation

@warrkan

@warrkan warrkan commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Proposal on a Model metadata contract

@github-actions github-actions Bot added the docs Related to documentation label Nov 2, 2026

@leoll2 leoll2 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposed interface is better than what we currently have, however it still suffers from a problem that affected the original design, although to a lesser extent now: it prescribes pre-processing steps instead of describing an input interface. Let me try to explain it more in detail.

Pre-processing is, by definition, the process of adapting the user input to the model. It depends on two things:

  1. What the user supplies as input, for example 1280x720 NCHW BGR tensors normalized in [0,255].
  2. What the model expects as input, for example 600x600 BGR NHWC tensors normalized in [0,1].

(2) is a property of the model and it's purely determined by how the model was trained and exported. (1) instead is beyond our control, depending on the client's data loading pipeline. Ideally, an inference library and its contract should not dictate on (1), otherwise the client is forced to implement pre-processing routines on his side, building complexity and latency. To give a practical example, a parameter like reverse_input_channels=True in the contract reads like: "I'm going to swap the R and B channels of your image; since the underlying model expects RGB, you must give me a BGR input.". As you see, this is not very user-friendly: if the upstream code loads images in RGB format, the user must either modify that code, or the model XML, or insert a redundant RBG->BGR conversion in the middle.

How it should work instead:

  • The contract focuses on (2): describe what the model expects as input, no more no less.
  • The client remains in control of (1), declaring what input format he supplies.
  • The inference library bridges the two through a flexible API.

With reference to my initial example:

  • The model.xml metadata declares the model properties: input_width: 600, input_height: 600, tensor_layout: nhwc, channels_order: bgr, ...
  • The user provides a descriptor of his tensors: InputShape(width=1280, height=720, tensor_layout: "nchw", ...).
  • The inference library compares the model metadata with the user-provided input shape, hence it auto-determines the necessary pre-processing steps to apply.

If we want to translate this to a code snippet that demonstrate how the client would implement a pipeline with our inference library (getipredict / MAPI):

from getipredict import Model, InferenceAdapter

# arbitrary code that produces the inference input array: it could be a simple cv2.imread or the output of a complex image acquisition pipeline.
image = ...

model = Model("./model.xml")
adapter = InferenceAdapter(
    model=model,
    # client sets 'input_shape' consistently with his images
    input_shape=InputShape(
        width=1280, 
        height=720, 
        tensor_layout: "nchw",
        ...
    )
)
predictions = adapter.infer(image)

This is just a minimal example, of course the real library API should take into account inputs of different shapes, post-processing, etc... My point is that the metadata keys should express properties of the model and its training pipeline, rather than listing a sequence of preprocessing steps to apply unconditionally; it's responsibility of the library to build a preprocessing pipeline that connects the user input (custom) to the model input (fixed).

Comment thread MODEL_METADATA_SPEC.md Resolved
Comment thread MODEL_METADATA_SPEC.md Outdated
Comment on lines +135 to +136
- **Possible values:** `classification`, `segmentation`, `detection`,
`instance_segmentation`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For classification, is it worth to distinguish between multiclass and multilabel? Or is it already done through other fields?

Comment thread MODEL_METADATA_SPEC.md Resolved
Comment thread MODEL_METADATA_SPEC.md Resolved
Comment thread MODEL_METADATA_SPEC.md Resolved
Comment thread MODEL_METADATA_SPEC.md Resolved
Comment thread MODEL_METADATA_SPEC.md Resolved
@warrkan
warrkan requested a review from kprokofi November 27, 2026 14:03

@kprokofi kprokofi left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the proposal. I left several comments, the main points are the missing decoder definitions and test vectors, the version/enum rules, and the preprocessing wording that can't be tested as written

Additionally, I agree with Leo's direction he mentioned. The contract should describe what the model expects as input, and leave it to the library that loads the model to convert whatever the user supplies. Some of the current wording still reads like a list of steps the caller must follow, for example "the client feeds the raw image" in embedded_pre_postprocessing, and the operations listed in the preprocessing section.

I suggest two changes:

  1. Word each preprocessing field as a property of the model input (size, layout, channel order, value range, how the model was trained to handle aspect ratio). Don't word it as a step to perform.
  2. Say that the contract fixes only the final tensor given to the model. Where and how the client produces it (in the graph, with OpenCV, on a GPU) is the client's choice, and conformance is checked on that tensor within a stated tolerance.

How a library lets the user describe their own input (for example an InputShape object) is an API question. It should be handled in getipredict, not in this spec.

Comment thread MODEL_METADATA_SPEC.md

```xml
<model_metadata>
<metadata_schema_version value="1.0" />

@kprokofi kprokofi Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.0 is not valid semver (semver needs three numbers: major.minor.patch, e.g. 1.0.0). A client that parses this field with a semver library will reject it. Either write 1.0.0 here and on line 160, or say that the format is major.minor.

Comment thread MODEL_METADATA_SPEC.md
- **Description:** Version of this specification that the metadata conforms to.
- **What it does:** A client compares the **major** version against the versions
it implements. If the major is unknown, the client MUST refuse to run the model
rather than guess. Minor/patch increments are backward compatible (new optional

@kprokofi kprokofi Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor version may only add optional fields, but line 856 says a client must reject values it does not know in a known field (for example a new decoder name). So if a minor release adds a new decoder value, older clients will refuse the model. Please pick one rule: either new allowed values require a major version change, or older clients may skip what they don't know.

Comment thread MODEL_METADATA_SPEC.md
> task-specific fine-tuning in Geti (custom label sets, datasets, and
> thresholds).
>
>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The disclaimer block is cut off here: the sentence saying the spec covers Phase 1 only is gone, and the ## Execution plan heading is glued to the quote. Looks like a merge leftover.

Comment thread MODEL_METADATA_SPEC.md
> pre-trained checkpoints (torchvision, timm, Ultralytics, and the getitune
> recipes exported with their original pre-trained weights) are re-exported to
> carry the metadata defined here.
> 2. **Phase 2 — Models fine-tuned in Geti.** The same models after

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phase 2 (fine-tuned Geti models) will probably need fields this version doesn't have, for example thresholds tuned per model and maybe more task types. It would be good to check now that the current fields can hold them. Otherwise Phase 2 may force an incompatible change soon after 1.0.

Comment thread MODEL_METADATA_SPEC.md
- **Stage:** Pre
- **Type:** boolean
- **Possible values:** `true`, `false`.
- **Description:** Whether the specified preprocessing, including resize,

@kprokofi kprokofi Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name says pre- and postprocessing, but the definition covers preprocessing only. Postprocessing that is built into the model seems to be signaled by other fields (activation = none, nms_execute). Please either limit this flag to preprocessing, or say that it covers both and list which postprocessing steps it implies.

Comment thread MODEL_METADATA_SPEC.md
- **Index base.** `labels[i]` is the name of final index `i`. For decoders with
`label_shift = 1`, `labels[0]` is the background / ignored class.
- **"other" class.** For single-output classifiers whose logit count is
`len(labels) + 1`, the pipeline MUST prepend `"other"` as `labels[0]`

@kprokofi kprokofi Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding other because the output count is one more than the label count is a guess made from the output shape. The spec forbids such guesses elsewhere (line 438: the class count C must not be inferred from shapes). Line 730 already says exporters SHOULD write the complete list. Please make that a MUST, and make the client return an error when the counts do not match, instead of guessing.

Comment thread MODEL_METADATA_SPEC.md

- **Publish the schema as a standalone artifact** (XML Schema (XSD) + prose spec),
versioned independently of the Python package, so a C++/Rust/JS team can validate
`model_info` without any Python dependency. The artifact also includes the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This says model_info, but the new block is called model_metadata (same on lines 843 and 881). model_info is the old format.

Comment thread MODEL_METADATA_SPEC.md
`model_info` without any Python dependency. The artifact also includes the
[Result schema definitions](#result-schema-definitions), which clients use to
implement their own result types (result types are not part of `model_info`).
- **Ship conformance test vectors** — `(input, metadata, expected result)` tuples

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema and the conformance test vectors are promised here, but neither is part of this PR. Without them nobody can check that their implementation is correct. Please add a few reference models with their expected outputs, or link to where they will live.

Comment thread MODEL_METADATA_SPEC.md
values it implements. If a model requires an unsupported combination,
the client fails cleanly. `task` + explicit fields are authoritative; there is no
`pipeline_profile`.
- **Keep `model_type` as a backward-compat alias.** When the new fields are absent,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The back-compat expansion table from model_type is promised here, but it is not in the document. Please add it, including the other old fields (labels, resize_type, reverse_input_channels, mean_values, scale_values, thresholds), so it is clear how each one maps to the new fields.

Comment thread MODEL_METADATA_SPEC.md

---

## Migration plan for existing Python modules

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is a plan for changing the Python model_api classes, not part of the contract between teams. I suggest moving it to a separate document, so the spec only says what a model file contains and what a client must do with it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Related to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants