gizml:onnx
ONNX model files (ModelProto, IR version 8) of gizml:ml models, and gizml:ml models of ONNX files. encode writes opset 17 and ai.onnx.ml 3: LinearRegressor, LinearClassifier (and Normalizer), TreeEnsembleRegressor, TreeEnsembleClassifier, PCA as Sub and MatMul, and k-means as the nearest center (MatMul, ReduceSumSquare, ArgMin). decode reads the ai.onnx.ml linear and tree ensemble operators as skl2onnx and onnxmltools write them for scikit-learn, XGBoost and LightGBM models, with Cast, Identity, ZipMap, Softmax and Normalizer (L1) nodes around them, and a Scaler before a linear operator (a pipeline of StandardScaler), which goes into its coefficients. ONNX Runtime (and scikit-learn's trees) round an input to f32 before a tree compares it with an f32 threshold. encode writes the nearest f32 of each threshold; decode turns each f32 test (BRANCH_LEQ, LT, GT, GTE) into the test on f64 that gives the same branch for each input: x <= T as f32 is x <= the largest f64 that rounds to at most T. network reads a convolutional network's graph (Conv, pooling, Resize, MatMul and the shape operators that YOLOX and RTMPose use) and runs it with gizml:tensor, on a GPU when one is given, with f32 values.
import * as Onnx from "gizml:onnx";Types
Port
type Port = { name: string; elem: i64; dims: Vec<i64>; }A graph input or output: its element type and dimensions (-1: the row count N).
name:stringelem:i64dims:Vec<i64>
Network
type Network = { nodes: Vec<Node>; weights: Map<string, T.Tensor>; inputs: Vec<string>; outputs: Vec<string>; }The neural network of an ONNX file (opset 11 to 17, F32): its nodes run in file order on gizml:tensor, on the GPU of its weights. The operators are those of convolutional detectors and pose models (YOLOX, RTMPose): Conv (any group of one channel or all, square pads), MaxPool, GlobalAveragePool, Resize (nearest, whole scales), MatMul, elementwise arithmetic and activations, and shape operators. Shapes and integer constants are host tensors.
nodes:Vec<M29.Node>weights:_gizlang_sdk_collections.Map<string, M32.Tensor>inputs:Vec<string>outputs:Vec<string>
Functions
encode
function encode(m: Model, version: string): bytes throws stringThe ONNX file of a model. A model whose estimator ONNX has no operator for (svm, AdaBoost's vote and median) is an error; so are class labels that are not integers.
Effects: fail.
portsOf
function portsOf(m: Model): Vec<Vec<Port>> throws stringThe inputs and outputs of the ONNX graph of a model.
Effects: fail.
decode
function decode(data: bytes): Model throws stringThe gizml:ml model of an ONNX file: one ai.onnx.ml LinearRegressor, LinearClassifier, TreeEnsembleRegressor or TreeEnsembleClassifier. Its algorithm is "onnx".
Effects: fail.
network
function network(data: bytes, gpu: Option<Gpu>): Network throws stringThe network of an ONNX file, its weights on gpu where one is given (Option.none(): on the host).
Effects: fail, read, write, console, io.
Methods
Network.run
function Network.run(self: Network, inputs: Vec<T.Tensor>): Vec<T.Tensor> throws stringThe network's outputs for its inputs, in the file's orders.
Effects: fail, read, write, console, io.
Constants
IR_VERSION
const IR_VERSION = 8The ONNX version that encode writes (IR version 8: ONNX 1.10 and later).
OPSET
const OPSET = 17The ONNX operator set version that encode writes.
ML_OPSET
const ML_OPSET = 3The ONNX-ML (ai.onnx.ml) operator set version that encode writes.
T_FLOAT
const T_FLOAT = 1The TensorProto data type of a 32-bit float.
T_INT64
const T_INT64 = 7The TensorProto data type of a 64-bit integer.