Implementation:Onnx Onnx ML Operator Sets
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning Operators, Schema Registration |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Concrete tool for declaring and registering ONNX ML domain (ai.onnx.ml) operator schemas across versions 1 through 5, provided by the ONNX library.
Description
This header defines the operator schema forward declarations and versioned operator set classes for the ONNX ML domain. It covers traditional machine learning operators that extend beyond standard tensor operations, targeting classical ML model types such as classifiers, regressors, and feature transformers.
The file is organized by operator set version:
Version 1 declares 18 operators: ArrayFeatureExtractor, Binarizer, CastMap, CategoryMapper, DictVectorizer, FeatureVectorizer, Imputer, LabelEncoder, LinearClassifier, LinearRegressor, Normalizer, OneHotEncoder, SVMClassifier, SVMRegressor, Scaler, TreeEnsembleClassifier, TreeEnsembleRegressor, and ZipMap.
Version 2 introduces an updated LabelEncoder.
Version 3 updates TreeEnsembleClassifier and TreeEnsembleRegressor.
Version 4 introduces another updated LabelEncoder.
Version 5 introduces the new TreeEnsemble operator alongside updated TreeEnsembleRegressor and TreeEnsembleClassifier.
Each version is encapsulated in an OpSet_OnnxML_verN class with a static ForEachSchema method that iterates over the schemas for that version. The RegisterOnnxMLOperatorSetSchema function registers all versions into the global schema registry. The entire file is guarded by the ONNX_ML preprocessor macro, so these operators are only compiled when ML support is enabled.
Usage
Use this header when building ONNX with ML operator support enabled (ONNX_ML defined). The RegisterOnnxMLOperatorSetSchema function should be called during library initialization to make all ML operators available for model validation, shape inference, and other schema-dependent operations. This is essential for processing ONNX models exported from scikit-learn, XGBoost, LightGBM, and similar ML frameworks via converters like sklearn-onnx.
Code Reference
Source Location
- Repository: Onnx_Onnx
- File: onnx/defs/operator_sets_ml.h
Signature
class OpSet_OnnxML_ver1 {
public:
static void ForEachSchema(const std::function<void(OpSchema&&)>& fn);
};
class OpSet_OnnxML_ver2 {
public:
static void ForEachSchema(const std::function<void(OpSchema&&)>& fn);
};
class OpSet_OnnxML_ver3 {
public:
static void ForEachSchema(const std::function<void(OpSchema&&)>& fn);
};
class OpSet_OnnxML_ver4 {
public:
static void ForEachSchema(const std::function<void(OpSchema&&)>& fn);
};
class OpSet_OnnxML_ver5 {
public:
static void ForEachSchema(const std::function<void(OpSchema&&)>& fn);
};
inline void RegisterOnnxMLOperatorSetSchema();
Import
#include "onnx/defs/operator_sets_ml.h"
I/O Contract
Inputs (RegisterOnnxMLOperatorSetSchema)
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | - | - | This function takes no parameters; it registers all ML operator schemas into the global OpSchemaRegistry |
Outputs
| Name | Type | Description |
|---|---|---|
| (side effect) | void | All ML operator schemas from versions 1 through 5 are registered in the global schema registry |
ML Operators by Version
Version 1
- ArrayFeatureExtractor, Binarizer, CastMap, CategoryMapper
- DictVectorizer, FeatureVectorizer, Imputer, LabelEncoder
- LinearClassifier, LinearRegressor, Normalizer, OneHotEncoder
- SVMClassifier, SVMRegressor, Scaler
- TreeEnsembleClassifier, TreeEnsembleRegressor, ZipMap
Version 2
- LabelEncoder (updated)
Version 3
- TreeEnsembleClassifier (updated), TreeEnsembleRegressor (updated)
Version 4
- LabelEncoder (updated)
Version 5
- TreeEnsemble (new), TreeEnsembleRegressor (updated), TreeEnsembleClassifier (updated)
Usage Examples
// Register all ML operator schemas at library initialization
#ifdef ONNX_ML
RegisterOnnxMLOperatorSetSchema();
#endif
// Iterate over version 1 ML operators
OpSet_OnnxML_ver1::ForEachSchema([](OpSchema&& schema) {
// Process each ML operator schema
std::cout << "ML Operator: " << schema.Name() << std::endl;
});