Repository navigation
Conversation
There was a problem hiding this comment.
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:
- What the user supplies as input, for example 1280x720 NCHW BGR tensors normalized in [0,255].
- 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.xmlmetadata 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).
| - **Possible values:** `classification`, `segmentation`, `detection`, | ||
| `instance_segmentation`. |
There was a problem hiding this comment.
For classification, is it worth to distinguish between multiclass and multilabel? Or is it already done through other fields?
There was a problem hiding this comment.
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:
- 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.
- 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.
|
|
||
| ```xml | ||
| <model_metadata> | ||
| <metadata_schema_version value="1.0" /> |
There was a problem hiding this comment.
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.
| - **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 |
There was a problem hiding this comment.
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.
| > task-specific fine-tuning in Geti (custom label sets, datasets, and | ||
| > thresholds). | ||
| > | ||
| > |
There was a problem hiding this comment.
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.
| > 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 |
There was a problem hiding this comment.
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.
| - **Stage:** Pre | ||
| - **Type:** boolean | ||
| - **Possible values:** `true`, `false`. | ||
| - **Description:** Whether the specified preprocessing, including resize, |
There was a problem hiding this comment.
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.
| - **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]` |
There was a problem hiding this comment.
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.
|
|
||
| - **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 |
There was a problem hiding this comment.
This says model_info, but the new block is called model_metadata (same on lines 843 and 881). model_info is the old format.
| `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 |
There was a problem hiding this comment.
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.
| 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, |
There was a problem hiding this comment.
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.
|
|
||
| --- | ||
|
|
||
| ## Migration plan for existing Python modules |
There was a problem hiding this comment.
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.
Proposal on a Model metadata contract