How to use the onnxmltools.convert.common._registration.register_shape_calculator function in onnxmltools

To help you get started, we’ve selected a few onnxmltools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github onnx / onnxmltools / onnxmltools / convert / xgboost / shape_calculators / Classifier.py View on Github external
if objective == "binary:logistic":
        ncl = 2
    else:
        ncl = ntrees // params['n_estimators']
        if objective == "reg:logistic" and ncl == 1:
            ncl = 2
    classes = xgb_node.classes_
    if (np.issubdtype(classes.dtype, np.floating) or
            np.issubdtype(classes.dtype, np.signedinteger)):
        operator.outputs[0].type = Int64TensorType(shape=[N])
    else:
        operator.outputs[0].type = StringTensorType(shape=[N])
    operator.outputs[1].type = operator.outputs[1].type = FloatTensorType([N, ncl])


register_shape_calculator('XGBClassifier', calculate_xgboost_classifier_output_shapes)
github onnx / onnxmltools / onnxmltools / convert / keras / shape_calculators / Lazy.py View on Github external
register_shape_calculator(keras.layers.Average, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.Maximum, calculate_lazy_output_shapes)

# Permute
register_shape_calculator(keras.layers.Permute, calculate_lazy_output_shapes)

# Reshape
register_shape_calculator(keras.layers.core.Reshape, calculate_lazy_output_shapes)

# Upsample
register_shape_calculator(keras.layers.UpSampling1D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.UpSampling2D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.UpSampling3D, calculate_lazy_output_shapes)

# ZeroPad
register_shape_calculator(keras.layers.ZeroPadding1D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.ZeroPadding2D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.ZeroPadding3D, calculate_lazy_output_shapes)

# RepeatVector
register_shape_calculator(keras.layers.RepeatVector, calculate_lazy_output_shapes)

# Dropout
register_shape_calculator(keras.layers.Dropout, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.SpatialDropout1D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.SpatialDropout2D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.SpatialDropout3D, calculate_lazy_output_shapes)
github onnx / onnxmltools / onnxmltools / convert / sparkml / operator_converters / chi_sq_selector.py View on Github external
op_domain='ai.onnx.ml',
                       name=scope.get_unique_operator_name('ArrayFeatureExtractor'))


register_converter('pyspark.ml.feature.ChiSqSelectorModel', convert_chi_sq_selector)


def calculate_chi_sq_selector_shapes(operator):
    check_input_and_output_numbers(operator, input_count_range=1, output_count_range=1)
    check_input_and_output_types(operator,
                                 good_input_types=[FloatTensorType, Int64TensorType, StringTensorType])
    operator.outputs[0].type = copy.deepcopy(operator.inputs[0].type)
    operator.outputs[0].type.shape[1] = len(operator.raw_operator.selectedFeatures)


register_shape_calculator('pyspark.ml.feature.ChiSqSelectorModel', calculate_chi_sq_selector_shapes)
github onnx / onnxmltools / onnxmltools / convert / sparkml / operator_converters / pca.py View on Github external
container.add_initializer(pc_tensor, onnx_proto.TensorProto.FLOAT,
                              [op.pc.numRows, op.pc.numCols], list(op.pc.toArray().flatten()))
    apply_matmul(scope, [operator.inputs[0].full_name, pc_tensor], operator.output_full_names, container)


register_converter('pyspark.ml.feature.PCAModel', convert_sparkml_pca)


def calculate_sparkml_pca_output_shapes(operator):
    check_input_and_output_numbers(operator, output_count_range=1)
    check_input_and_output_types(operator, good_input_types=[FloatTensorType])
    N = operator.inputs[0].type.shape[0]
    operator.outputs[0].type = FloatTensorType([N, operator.raw_operator.getOrDefault('k')])


register_shape_calculator('pyspark.ml.feature.PCAModel', calculate_sparkml_pca_output_shapes)
github onnx / onnxmltools / onnxmltools / convert / sklearn / shape_calculators / LinearClassifier.py View on Github external
import numpy as np
import numbers
import six
from ...common._registration import register_shape_calculator
from ...common.shape_calculator import calculate_linear_classifier_output_shapes





register_shape_calculator('SklearnLinearClassifier', calculate_linear_classifier_output_shapes)
register_shape_calculator('SklearnDecisionTreeClassifier', calculate_linear_classifier_output_shapes)
register_shape_calculator('SklearnRandomForestClassifier', calculate_linear_classifier_output_shapes)
register_shape_calculator('SklearnExtraTreesClassifier', calculate_linear_classifier_output_shapes)
register_shape_calculator('SklearnGradientBoostingClassifier', calculate_linear_classifier_output_shapes)
register_shape_calculator('SklearnBernoulliNB', calculate_linear_classifier_output_shapes)
register_shape_calculator('SklearnMultinomialNB', calculate_linear_classifier_output_shapes)
register_shape_calculator('SklearnKNeighborsClassifier', calculate_linear_classifier_output_shapes)
github onnx / onnxmltools / onnxmltools / convert / keras / shape_calculators / Lazy.py View on Github external
register_shape_calculator(keras.layers.advanced_activations.Softmax, calculate_lazy_output_shapes)
if StrictVersion(keras.__version__) >= StrictVersion('2.2.0'):
    register_shape_calculator(keras.layers.advanced_activations.ReLU, calculate_lazy_output_shapes)

# Concate
register_shape_calculator(keras.layers.Concatenate, calculate_lazy_output_shapes)

# Cropping
register_shape_calculator(keras.layers.Cropping1D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.Cropping2D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.Cropping3D, calculate_lazy_output_shapes)

# Local Pooling
register_shape_calculator(keras.layers.MaxPooling1D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.MaxPooling2D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.MaxPooling3D, calculate_lazy_output_shapes)

register_shape_calculator(keras.layers.AveragePooling1D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.AveragePooling2D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.AveragePooling3D, calculate_lazy_output_shapes)

# Global Pooling
register_shape_calculator(keras.layers.GlobalMaxPooling1D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.GlobalMaxPooling2D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.GlobalMaxPooling3D, calculate_lazy_output_shapes)

register_shape_calculator(keras.layers.GlobalAveragePooling1D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.GlobalAveragePooling2D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.GlobalAveragePooling3D, calculate_lazy_output_shapes)

# Flatten
register_shape_calculator(keras.layers.Flatten, calculate_lazy_output_shapes)
github onnx / onnxmltools / onnxmltools / convert / sklearn / shape_calculators / LinearRegressor.py View on Github external
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

from ...common._registration import register_shape_calculator
from ...common.shape_calculator import calculate_linear_regressor_output_shapes


register_shape_calculator('SklearnElasticNetRegressor', calculate_linear_regressor_output_shapes)
register_shape_calculator('SklearnLinearRegressor', calculate_linear_regressor_output_shapes)
register_shape_calculator('SklearnLinearSVR', calculate_linear_regressor_output_shapes)
register_shape_calculator('SklearnDecisionTreeRegressor', calculate_linear_regressor_output_shapes)
register_shape_calculator('SklearnRandomForestRegressor', calculate_linear_regressor_output_shapes)
register_shape_calculator('SklearnExtraTreesRegressor', calculate_linear_regressor_output_shapes)
register_shape_calculator('SklearnGradientBoostingRegressor', calculate_linear_regressor_output_shapes)
register_shape_calculator('SklearnKNeighborsRegressor', calculate_linear_regressor_output_shapes)
register_shape_calculator('SklearnLassoLars', calculate_linear_regressor_output_shapes)
register_shape_calculator('SklearnRidge', calculate_linear_regressor_output_shapes)
github onnx / onnxmltools / onnxmltools / convert / keras / shape_calculators / Lazy.py View on Github external
import keras
from distutils.version import StrictVersion
from ...common._registration import register_shape_calculator


def calculate_lazy_output_shapes(operator):
    pass


# Activation
register_shape_calculator(keras.layers.Activation, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.advanced_activations.LeakyReLU, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.advanced_activations.ThresholdedReLU, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.advanced_activations.ELU, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.advanced_activations.PReLU, calculate_lazy_output_shapes)
if StrictVersion(keras.__version__) >= StrictVersion('2.1.3'):
    register_shape_calculator(keras.layers.advanced_activations.Softmax, calculate_lazy_output_shapes)
if StrictVersion(keras.__version__) >= StrictVersion('2.2.0'):
    register_shape_calculator(keras.layers.advanced_activations.ReLU, calculate_lazy_output_shapes)

# Concate
register_shape_calculator(keras.layers.Concatenate, calculate_lazy_output_shapes)

# Cropping
register_shape_calculator(keras.layers.Cropping1D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.Cropping2D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.Cropping3D, calculate_lazy_output_shapes)

# Local Pooling
register_shape_calculator(keras.layers.MaxPooling1D, calculate_lazy_output_shapes)
register_shape_calculator(keras.layers.MaxPooling2D, calculate_lazy_output_shapes)
github onnx / onnxmltools / onnxmltools / convert / keras / shape_calculators / LSTM.py View on Github external
import numbers
from keras.layers import LSTM, SimpleRNN, GRU
from ...common._registration import register_shape_calculator


def calculate_keras_lstm_output_shapes(operator):
    op = operator.raw_operator
    if isinstance(op.output_shape[0], collections.Iterable):
        operator.outputs[0].type.shape = list(i if isinstance(i, numbers.Integral) else 'None'
                                              for i in op.output_shape[0])
    else:
        operator.outputs[0].type.shape = list(i if isinstance(i, numbers.Integral) else 'None' for i in op.output_shape)


register_shape_calculator(LSTM, calculate_keras_lstm_output_shapes)
register_shape_calculator(SimpleRNN, calculate_keras_lstm_output_shapes)
register_shape_calculator(GRU, calculate_keras_lstm_output_shapes)
github onnx / onnxmltools / onnxmltools / convert / sparkml / operator_converters / stop_words_remover.py View on Github external
is_case_sensitive=1 if op.getCaseSensitive() else 0,
                       stopwords=op.getStopWords())


register_converter('pyspark.ml.feature.StopWordsRemover', convert_sparkml_stop_words_remover)


def calculate_sparkml_stop_words_remover_output_shapes(operator):
    check_input_and_output_numbers(operator, output_count_range=1)
    check_input_and_output_types(operator,
                                 good_input_types=[StringTensorType])
    input_shape = copy.deepcopy(operator.inputs[0].type.shape)
    operator.outputs[0].type = StringTensorType(input_shape)


register_shape_calculator('pyspark.ml.feature.StopWordsRemover', calculate_sparkml_stop_words_remover_output_shapes)