Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
[len(index)], index)
container.add_node(
'ArrayFeatureExtractor',
[operator.inputs[0].full_name, column_indices_name],
output_name, op_domain='ai.onnx.ml',
name=scope.get_unique_operator_name('ArrayFeatureExtractor'))
else:
container.add_node('ConstantOfShape', operator.inputs[0].full_name,
output_name, op_version=9)
if needs_cast:
apply_cast(scope, output_name, operator.outputs[0].full_name,
container, to=onnx_proto.TensorProto.FLOAT)
register_converter('SklearnGenericUnivariateSelect',
convert_sklearn_feature_selection)
register_converter('SklearnRFE', convert_sklearn_feature_selection)
register_converter('SklearnRFECV', convert_sklearn_feature_selection)
register_converter('SklearnSelectFdr', convert_sklearn_feature_selection)
register_converter('SklearnSelectFpr', convert_sklearn_feature_selection)
register_converter('SklearnSelectFromModel', convert_sklearn_feature_selection)
register_converter('SklearnSelectFwe', convert_sklearn_feature_selection)
register_converter('SklearnSelectKBest', convert_sklearn_feature_selection)
register_converter('SklearnSelectPercentile',
convert_sklearn_feature_selection)
register_converter('SklearnVarianceThreshold',
convert_sklearn_feature_selection)
"""
Converts *NearestNeighbors* into *ONNX*.
"""
many = _convert_nearest_neighbors(operator, container)
top_indices, top_distances = many[:2]
out = operator.outputs
ind = OnnxIdentity(top_indices, output_names=out[:1])
dist = OnnxIdentity(top_distances, output_names=out[1:])
dist.add_to(scope, container)
ind.add_to(scope, container)
register_converter(
'SklearnKNeighborsClassifier', convert_nearest_neighbors_classifier)
register_converter(
'SklearnKNeighborsRegressor', convert_nearest_neighbors_regressor)
register_converter(
'SklearnNearestNeighbors', convert_nearest_neighbors_transform)
array_feature_extractor_result_name, op_domain='ai.onnx.ml',
name=scope.get_unique_operator_name('ArrayFeatureExtractor'))
if class_type == onnx_proto.TensorProto.INT32:
apply_reshape(scope, array_feature_extractor_result_name,
reshaped_result_name, container,
desired_shape=output_shape)
apply_cast(scope, reshaped_result_name, operator.outputs[0].full_name,
container, to=onnx_proto.TensorProto.INT64)
else:
apply_reshape(scope, array_feature_extractor_result_name,
operator.outputs[0].full_name, container,
desired_shape=output_shape)
register_converter('SklearnCalibratedClassifierCV',
convert_sklearn_calibrated_classifier_cv)
"do not necessarily match input variables "
"defined for the ONNX model.").format(i, ind))
container.add_initializer(column_indices_name,
onnx_proto.TensorProto.INT64,
[len(operator.column_indices)],
operator.column_indices)
container.add_node(
'ArrayFeatureExtractor',
[operator.inputs[0].full_name, column_indices_name],
operator.outputs[0].full_name,
name=scope.get_unique_operator_name('ArrayFeatureExtractor'),
op_domain='ai.onnx.ml')
register_converter('SklearnArrayFeatureExtractor',
convert_sklearn_array_feature_extractor)
# with np.errstate(under='ignore'):
# log_resp = weighted_log_prob - log_prob_norm[:, np.newaxis]
log_prob_norm = OnnxReduceLogSumExp(
weighted_log_prob, axes=[1], op_version=opv)
log_resp = OnnxSub(weighted_log_prob, log_prob_norm, op_version=opv)
# probabilities
probs = OnnxExp(log_resp, output_names=out[1:], op_version=opv)
# final
labels.add_to(scope, container)
probs.add_to(scope, container)
register_converter('SklearnGaussianMixture', convert_sklearn_gaussian_mixture)
register_converter('SklearnBayesianGaussianMixture',
convert_sklearn_gaussian_mixture)
cast_input_name = scope.get_unique_variable_name('cast_input')
apply_cast(scope, operator.input_full_names, cast_input_name,
container, to=onnx_proto.TensorProto.FLOAT)
input_name = [cast_input_name]
container.add_node(op_type, input_name,
operator.output_full_names, op_domain='ai.onnx.ml',
**attrs)
register_converter('SklearnDecisionTreeClassifier',
convert_sklearn_decision_tree_classifier)
register_converter('SklearnDecisionTreeRegressor',
convert_sklearn_decision_tree_regressor)
register_converter('SklearnExtraTreeClassifier',
convert_sklearn_decision_tree_classifier)
register_converter('SklearnExtraTreeRegressor',
convert_sklearn_decision_tree_regressor)
}
if all(isinstance(feature_name, (six.string_types, six.text_type))
for feature_name in op.feature_names_):
attrs['string_vocabulary'] = list(str(i) for i in op.feature_names_)
elif all(isinstance(feature_name, numbers.Integral)
for feature_name in op.feature_names_):
attrs['int64_vocabulary'] = list(int(i) for i in op.feature_names_)
else:
raise ValueError('Keys must be all integers or all strings.')
container.add_node(op_type, operator.input_full_names,
operator.output_full_names, op_domain='ai.onnx.ml',
**attrs)
register_converter('SklearnDictVectorizer', convert_sklearn_dict_vectorizer)
container.add_node(
'ArrayFeatureExtractor',
[operator.inputs[0].full_name, column_indices_name],
output_name, op_domain='ai.onnx.ml',
name=scope.get_unique_operator_name('ArrayFeatureExtractor'))
else:
container.add_node('ConstantOfShape', operator.inputs[0].full_name,
output_name, op_version=9)
if needs_cast:
apply_cast(scope, output_name, operator.outputs[0].full_name,
container, to=onnx_proto.TensorProto.FLOAT)
register_converter('SklearnGenericUnivariateSelect',
convert_sklearn_feature_selection)
register_converter('SklearnRFE', convert_sklearn_feature_selection)
register_converter('SklearnRFECV', convert_sklearn_feature_selection)
register_converter('SklearnSelectFdr', convert_sklearn_feature_selection)
register_converter('SklearnSelectFpr', convert_sklearn_feature_selection)
register_converter('SklearnSelectFromModel', convert_sklearn_feature_selection)
register_converter('SklearnSelectFwe', convert_sklearn_feature_selection)
register_converter('SklearnSelectKBest', convert_sklearn_feature_selection)
register_converter('SklearnSelectPercentile',
convert_sklearn_feature_selection)
register_converter('SklearnVarianceThreshold',
convert_sklearn_feature_selection)
grid_search_operator.raw_operator = best_estimator
grid_search_operator.inputs = operator.inputs
label_name = scope.declare_local_variable('label')
grid_search_operator.outputs.append(label_name)
if is_classifier(best_estimator):
proba_name = scope.declare_local_variable('probability_tensor',
FloatTensorType())
grid_search_operator.outputs.append(proba_name)
apply_identity(scope, label_name.full_name,
operator.outputs[0].full_name, container)
if is_classifier(best_estimator):
apply_identity(scope, proba_name.full_name,
operator.outputs[1].full_name, container)
register_converter('SklearnGridSearchCV',
convert_sklearn_grid_search_cv)
'https://github.com/onnx/sklearn-onnx/issues.'
'' % type(op))
# ONNX does not convert arrays of float32.
for k in attrs:
v = attrs[k]
if isinstance(v, np.ndarray) and v.dtype == np.float32:
attrs[k] = v.astype(np.float64)
container.add_node(op_type, feature_name, operator.outputs[0].full_name,
op_domain='ai.onnx.ml', **attrs)
register_converter('SklearnRobustScaler', convert_sklearn_scaler)
register_converter('SklearnScaler', convert_sklearn_scaler)
register_converter('SklearnMinMaxScaler', convert_sklearn_scaler)
register_converter('SklearnMaxAbsScaler', convert_sklearn_scaler)