GizStack
View .mdOpen in ChatGPTOpen in Claude

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.

gizlang
import * as Onnx from "gizml:onnx";

Types

Port

gizlang
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: string
  • elem: i64
  • dims: Vec<i64>

Network

gizlang
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

gizlang
function encode(m: Model, version: string): bytes throws string

The 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

gizlang
function portsOf(m: Model): Vec<Vec<Port>> throws string

The inputs and outputs of the ONNX graph of a model.

Effects: fail.

decode

gizlang
function decode(data: bytes): Model throws string

The gizml:ml model of an ONNX file: one ai.onnx.ml LinearRegressor, LinearClassifier, TreeEnsembleRegressor or TreeEnsembleClassifier. Its algorithm is "onnx".

Effects: fail.

network

gizlang
function network(data: bytes, gpu: Option<Gpu>): Network throws string

The 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

gizlang
function Network.run(self: Network, inputs: Vec<T.Tensor>): Vec<T.Tensor> throws string

The network's outputs for its inputs, in the file's orders.

Effects: fail, read, write, console, io.

Constants

IR_VERSION

gizlang
const IR_VERSION = 8

The ONNX version that encode writes (IR version 8: ONNX 1.10 and later).

OPSET

gizlang
const OPSET = 17

The ONNX operator set version that encode writes.

ML_OPSET

gizlang
const ML_OPSET = 3

The ONNX-ML (ai.onnx.ml) operator set version that encode writes.

T_FLOAT

gizlang
const T_FLOAT = 1

The TensorProto data type of a 32-bit float.

T_INT64

gizlang
const T_INT64 = 7

The TensorProto data type of a 64-bit integer.