예제 #1
0
    def test_custom_scaler_pipeline_left(self):
        pipe = make_pipeline(
            CustomOpTransformer(op_version=TARGET_OPSET),
            StandardScaler())
        mat = np.array([[0., 1.], [0., 1.], [2., 2.]])
        pipe.fit(mat)
        z = pipe.transform(mat)

        matf = mat.astype(np.float32)

        try:
            model_onnx = to_onnx(pipe, matf, target_opset=TARGET_OPSET)
        except RuntimeError as e:
            assert "cannot be infered" in str(e)

        pipe = make_pipeline(
            CustomOpTransformerShape(op_version=TARGET_OPSET),
            StandardScaler())
        mat = np.array([[0., 1.], [0., 1.], [2., 2.]])
        pipe.fit(mat)
        z = pipe.transform(mat)
        assert z is not None

        matf = mat.astype(np.float32)

        model_onnx = to_onnx(pipe, matf)

        # Next instructions fails...
        # Field 'shape' of type is required but missing.
        # onnx.checker.check_model(model_onnx)

        dump_data_and_model(
            mat.astype(np.float32), pipe, model_onnx,
            basename="CustomTransformerPipelineLeftAlgebra")
    def test_custom_scaler_pipeline_left(self):
        pipe = make_pipeline(
            CustomOpTransformer(op_version=TARGET_OPSET),
            StandardScaler())
        mat = np.array([[0., 1.], [0., 1.], [2., 2.]])
        pipe.fit(mat)
        z = pipe.transform(mat)

        matf = mat.astype(np.float32)

        try:
            model_onnx = to_onnx(pipe, matf, target_opset=TARGET_OPSET)
        except RuntimeError as e:
            assert "inputs should contain one name" in str(e)

        pipe = make_pipeline(
            CustomOpTransformerShape(op_version=TARGET_OPSET),
            StandardScaler())
        mat = np.array([[0., 1.], [0., 1.], [2., 2.]])
        pipe.fit(mat)
        z = pipe.transform(mat)
        assert z is not None

        matf = mat.astype(np.float32)

        model_onnx = to_onnx(pipe, matf, target_opset=TARGET_OPSET)

        if StrictVersion(onnx.__version__) >= StrictVersion("1.8.0"):
            # It fails for older version of onnx.
            onnx.checker.check_model(model_onnx)

        dump_data_and_model(
            mat.astype(np.float32), pipe, model_onnx,
            basename="CustomTransformerPipelineLeftAlgebra")
    def test_custom_scaler_pipeline_right(self):
        pipe = make_pipeline(
            StandardScaler(),
            CustomOpTransformerShape(op_version=TARGET_OPSET))
        mat = np.array([[0., 1.], [0., 1.], [2., 2.]])
        pipe.fit(mat)
        z = pipe.transform(mat)
        assert z is not None

        matf = mat.astype(np.float32)
        model_onnx = to_onnx(pipe, matf, target_opset=TARGET_OPSET)
        onnx.checker.check_model(model_onnx)
        dump_data_and_model(
            mat.astype(np.float32), pipe, model_onnx,
            basename="CustomTransformerPipelineRightAlgebra")
예제 #4
0
    def test_custom_scaler_pipeline_right(self):
        pipe = make_pipeline(StandardScaler(), CustomOpTransformerShape())
        mat = np.array([[0., 1.], [0., 1.], [2., 2.]])
        pipe.fit(mat)
        z = pipe.transform(mat)
        assert z is not None

        matf = mat.astype(np.float32)
        model_onnx = to_onnx(pipe, matf)
        # Next instructions fails...
        # Field 'shape' of type is required but missing.
        # onnx.checker.check_model(model_onnx)

        # use assert_consistent_outputs
        # calls dump_data_and_model
        dump_data_and_model(
            mat.astype(np.float32), pipe, model_onnx,
            basename="CustomTransformerPipelineRightAlgebra")