Inference model
Classes
InferenceModel
ONNX model are loaded as an
InferenceModel
s instead of Model
s: many ONNX models come with partial shape and
element type information, while tract's Model
assume full shape and element type
knownledge. 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 the InferenceModel
to a regular Model
.
# load the model as an InferenceModel
model = tract.onnx().model_for_path("./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_optimized().into_runnable()
Source code in tract/inference_model.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
Functions
into_optimized() -> Model
Run the InferenceModel through the full tract optimisation pipeline to get an optimised Model.
Source code in tract/inference_model.py
38 39 40 41 42 43 44 45 46 |
|
into_typed() -> Model
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 optimisint it all the way.
Source code in tract/inference_model.py
48 49 50 51 52 53 54 55 56 57 58 |
|
input_count() -> int
Return the number of inputs of the model
Source code in tract/inference_model.py
60 61 62 63 64 65 |
|
output_count() -> int
Return the number of outputs of the model
Source code in tract/inference_model.py
67 68 69 70 71 72 |
|
input_name(input_id: int) -> str
Return the name of the input_id
th input.
Source code in tract/inference_model.py
74 75 76 77 78 79 80 81 |
|
input_fact(input_id: int) -> InferenceFact
Extract the InferenceFact of the input_id
th input.
Source code in tract/inference_model.py
83 84 85 86 87 88 |
|
set_input_fact(input_id: int, fact: Union[InferenceFact, str, None]) -> None
Change the InferenceFact of the input_id
th input.
Source code in tract/inference_model.py
90 91 92 93 94 95 96 97 98 |
|
set_output_names(names: List[str])
Change the output nodes of the model
Source code in tract/inference_model.py
100 101 102 103 104 105 106 107 108 109 |
|
output_name(output_id: int) -> str
Return the name of the output_id
th output.
Source code in tract/inference_model.py
111 112 113 114 115 116 117 118 |
|
output_fact(output_id: int) -> InferenceFact
Extract the InferenceFact of the output_id
th output.
Source code in tract/inference_model.py
120 121 122 123 124 125 |
|
set_output_fact(output_id: int, fact: Union[InferenceFact, str, None]) -> None
Change the InferenceFact of the output_id
th output.
Source code in tract/inference_model.py
127 128 129 130 131 132 133 134 135 |
|
fact(spec: str) -> InferenceFact
Parse an fact specification as an InferenceFact
Typical InferenceFact
specification 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.
Source code in tract/inference_model.py
137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
analyse() -> None
Perform shape and element type inference on the model.
Source code in tract/inference_model.py
151 152 153 154 155 156 |
|
into_analysed() -> InferenceModel
Perform shape and element type inference on the model.
Source code in tract/inference_model.py
158 159 160 161 162 163 |
|