예제 #1
0
 def test_bug_graph(self):
     this = os.path.abspath(os.path.dirname(__file__))
     data = os.path.join(this, "data", "bug_graph.onnx")
     oinf = OnnxInference(
         data,
         inside_loop=True,
         static_inputs=['StatefulPartitionedCall/Reshape:0'])
     text = oinf.to_text(distance=8)
     self.assertIn(
         "cond___pcen/simple_rnn/while/Identity_graph_outputs_Identity__4:0",
         text)
예제 #2
0
 def test_onnxt_text_seq(self):
     idi = numpy.identity(2).astype(numpy.float32)
     idi2 = (numpy.identity(2) * 2).astype(numpy.float32)
     onx = OnnxAdd(OnnxAdd('X', idi, op_version=TARGET_OPSET),
                   idi2,
                   output_names=['Y'],
                   op_version=TARGET_OPSET)
     model_def = onx.to_onnx({'X': idi.astype(numpy.float32)},
                             target_opset=TARGET_OPSET)
     oinf = OnnxInference(model_def)
     text = oinf.to_text(kind='seq')
     self.assertIn('input:', text)
예제 #3
0
    def test_onnx_simple_text_plot_if(self):

        opv = TARGET_OPSET
        x1 = numpy.array([[0, 3], [7, 0]], dtype=numpy.float32)
        x2 = numpy.array([[1, 0], [2, 0]], dtype=numpy.float32)

        node = OnnxAdd('x1', 'x2', output_names=['absxythen'], op_version=opv)
        then_body = node.to_onnx({
            'x1': x1,
            'x2': x2
        },
                                 target_opset=opv,
                                 outputs=[('absxythen', FloatTensorType())])
        node = OnnxSub('x1', 'x2', output_names=['absxyelse'], op_version=opv)
        else_body = node.to_onnx({
            'x1': x1,
            'x2': x2
        },
                                 target_opset=opv,
                                 outputs=[('absxyelse', FloatTensorType())])
        del else_body.graph.input[:]
        del then_body.graph.input[:]

        cond = OnnxGreater(OnnxReduceSum('x1', op_version=opv),
                           OnnxReduceSum('x2', op_version=opv),
                           op_version=opv)
        ifnode = OnnxIf(cond,
                        then_branch=then_body.graph,
                        else_branch=else_body.graph,
                        op_version=opv,
                        output_names=['y'])
        model_def = ifnode.to_onnx({
            'x1': x1,
            'x2': x2
        },
                                   target_opset=opv,
                                   outputs=[('y', FloatTensorType())])
        text = onnx_simple_text_plot(model_def)
        expected = textwrap.dedent("""
        input:
        """).strip(" \n")
        self.assertIn(expected, text)
        self.assertIn("If(Gr_C0) -> y", text)
        oinf = OnnxInference(model_def)
        text2 = oinf.to_text(kind="seq")
        self.assertEqual(text, text2)
예제 #4
0
 def test_bug_graph_infinite(self):
     this = os.path.abspath(os.path.dirname(__file__))
     data = os.path.join(this, "data", "bug_graph_infinite.onnx")
     oinf = OnnxInference(data, inside_loop=True)
     text = oinf.to_text(distance=8)
     self.assertIn("slice_end", text)