def predictable_tsne_converter(scope, operator, container): output = operator.outputs[0] op = operator.raw_operator model = op.estimator_ alias = _get_sklearn_operator_name(type(model)) knn_op = scope.declare_local_operator(alias, model) knn_op.inputs = operator.inputs knn_output = scope.declare_local_variable('knn_output', FloatTensorType()) knn_op.outputs.append(knn_output) shape_calc = get_shape_calculator(alias) shape_calc(knn_op) name = scope.get_unique_operator_name('Scaler') attrs = dict(name=name, scale=op.inv_std_.ravel().astype(float), offset=op.mean_.ravel().astype(float)) container.add_node('Scaler', [knn_output.onnx_name], [output.full_name], op_domain='ai.onnx.ml', **attrs)
def predictable_tsne_converter(scope, operator, container): """ :param scope: name space, where to keep node names, get unused new names :param operator: operator to converter, same object as sent to *predictable_tsne_shape_calculator* :param container: contains the ONNX graph """ # input = operator.inputs[0] # input in ONNX graph output = operator.outputs[0] # output in ONNX graph op = operator.raw_operator # scikit-learn model (mmust be fitted) # First step is the k nearest-neighbours, # we reuse existing converter and declare it as local # operator model = op.estimator_ alias = _get_sklearn_operator_name(type(model)) knn_op = scope.declare_local_operator(alias, model) knn_op.inputs = operator.inputs # We add an intermediate outputs. knn_output = scope.declare_local_variable('knn_output', FloatTensorType()) knn_op.outputs.append(knn_output) # We adjust the output of the submodel. shape_calc = get_shape_calculator(alias) shape_calc(knn_op) # We add the normalizer which needs a unique node name. name = scope.get_unique_operator_name('Scaler') # The parameter follows the specifications of ONNX # https://github.com/onnx/onnx/blob/master/docs/Operators-ml.md#ai.onnx.ml.Scaler attrs = dict(name=name, scale=op.inv_std_.ravel().astype(float), offset=op.mean_.ravel().astype(float)) # Let's finally add the scaler which connects the output # of the k-nearest neighbours model to output of the whole model # declared in ONNX graph container.add_node('Scaler', [knn_output.onnx_name], [output.full_name], op_domain='ai.onnx.ml', **attrs)