def test_custom_pipeline_scaler(self): digits = datasets.load_digits(n_class=6) Xd = digits.data[:20] yd = digits.target[:20] n_samples, n_features = Xd.shape ptsne_knn = PredictableTSNE() ptsne_knn.fit(Xd, yd) update_registered_converter( PredictableTSNE, "CustomPredictableTSNE", predictable_tsne_shape_calculator, predictable_tsne_converter, ) model_onnx = convert_sklearn( ptsne_knn, "predictable_tsne", [("input", FloatTensorType([None, Xd.shape[1]]))], target_opset=TARGET_OPSET) dump_data_and_model(Xd.astype(numpy.float32)[:7], ptsne_knn, model_onnx, basename="CustomTransformerTSNEkNN-OneOffArray") trace_line = [] def my_parser(scope, model, inputs, custom_parsers=None): trace_line.append(model) return _parse_sklearn_simple_model(scope, model, inputs, custom_parsers) model_onnx = convert_sklearn( ptsne_knn, "predictable_tsne", [("input", FloatTensorType([None, Xd.shape[1]]))], custom_parsers={PredictableTSNE: my_parser}, target_opset=TARGET_OPSET) assert len(trace_line) == 1 dump_data_and_model( Xd.astype(numpy.float32)[:7], ptsne_knn, model_onnx, basename="CustomTransformerTSNEkNNCustomParser-OneOffArray") update_registered_parser(PredictableTSNE, my_parser) model_onnx = convert_sklearn( ptsne_knn, "predictable_tsne", [("input", FloatTensorType([None, Xd.shape[1]]))], target_opset=TARGET_OPSET) assert len(trace_line) == 2
def test_custom_pipeline_scaler(self): digits = datasets.load_digits(n_class=6) Xd = digits.data[:20] yd = digits.target[:20] n_samples, n_features = Xd.shape ptsne_knn = PredictableTSNE() ptsne_knn.fit(Xd, yd) update_registered_converter(PredictableTSNE, 'CustomPredictableTSNE', predictable_tsne_shape_calculator, predictable_tsne_converter) model_onnx = convert_sklearn( ptsne_knn, 'predictable_tsne', [('input', FloatTensorType([1, Xd.shape[1]]))]) dump_data_and_model(Xd.astype(numpy.float32)[:7], ptsne_knn, model_onnx, basename="CustomTransformerTSNEkNN-OneOffArray", allow_failure="StrictVersion(onnx.__version__) " "== StrictVersion('1.4.1')") trace_line = [] def my_parser(scope, model, inputs, custom_parsers=None): trace_line.append(model) return _parse_sklearn_simple_model(scope, model, inputs, custom_parsers) model_onnx = convert_sklearn( ptsne_knn, 'predictable_tsne', [('input', FloatTensorType([1, Xd.shape[1]]))], custom_parsers={PredictableTSNE: my_parser}) assert len(trace_line) == 1 dump_data_and_model( Xd.astype(numpy.float32)[:7], ptsne_knn, model_onnx, basename="CustomTransformerTSNEkNNCustomParser-OneOffArray", allow_failure="StrictVersion(onnx.__version__) " "== StrictVersion('1.4.1')") update_registered_parser(PredictableTSNE, my_parser) model_onnx = convert_sklearn( ptsne_knn, 'predictable_tsne', [('input', FloatTensorType([1, Xd.shape[1]]))]) assert len(trace_line) == 2