Inference model¶
- class tract.inference_model.InferenceModel(ptr)[source]¶
ONNX models are loaded as
InferenceModelinstances instead ofModelinstances: many ONNX models come with partial shape and element type information, while tract’sModelassumes full shape and element type knowledge. In this case, it is generally sufficient to inform tract about the input shape and type, then let tract infer the rest of the missing shape information before converting theInferenceModelto a regularModel.# load the model as an InferenceModel model = tract.onnx().load("./mobilenetv2-7.onnx") # set the shape and type of its first and only input model.set_input_fact(0, "1,3,224,224,f32") # get ready to run the model model = model.into_model().into_runnable()
- into_model() Model[source]¶
Convert an InferenceModel to a regular typed
Model.This will leave the opportunity to run more transformation on the intermediary form of the model, before optimising it all the way.
- input_fact(input_id: int) InferenceFact[source]¶
Extract the InferenceFact of the
input_id-th input.
- set_input_fact(input_id: int, fact: InferenceFact | str | None) None[source]¶
Change the InferenceFact of the
input_id-th input.
- output_fact(output_id: int) InferenceFact[source]¶
Extract the InferenceFact of the
output_id-th output.
- set_output_fact(output_id: int, fact: InferenceFact | str | None) None[source]¶
Change the InferenceFact of the
output_id-th output.
- fact(spec: str) InferenceFact[source]¶
Parse a fact specification as an
InferenceFact.Typical
InferenceFactspecification is in the form “1,224,224,3,f32”. Comma-separated list of dimension, one for each axis, plus an mnemonic for the element type. f32 is single precision “float”, i16 is a 16-bit signed integer, and u8 a 8-bit unsigned integer.
- into_analysed() InferenceModel[source]¶
Perform shape and element type inference on the model.