From e683f6419ebb3ad27f3c866440aac320f4176fac Mon Sep 17 00:00:00 2001 From: ahre5612 Date: Mon, 5 Aug 2024 13:29:24 +0200 Subject: [PATCH 1/3] minor bug fix --- notebooks/0_how_to_work_with_onnx.ipynb | 217 +++++++++++++++++------- 1 file changed, 160 insertions(+), 57 deletions(-) diff --git a/notebooks/0_how_to_work_with_onnx.ipynb b/notebooks/0_how_to_work_with_onnx.ipynb index 60340f14..f78305df 100644 --- a/notebooks/0_how_to_work_with_onnx.ipynb +++ b/notebooks/0_how_to_work_with_onnx.ipynb @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -57,7 +57,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -99,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -120,28 +120,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - " graph = onnx.helper.make_graph(\n", - " nodes=[\n", - " Add1_node,\n", - " Add2_node,\n", - " Abs_node,\n", - " Add3_node,\n", - " Round_node,\n", - " ],\n", - " name=\"simple_graph\",\n", - " inputs=[in1, in2, in3],\n", - " outputs=[out1],\n", - " value_info=[\n", - " onnx.helper.make_tensor_value_info(\"sum1\", onnx.TensorProto.FLOAT, [4, 4]),\n", - " onnx.helper.make_tensor_value_info(\"sum2\", onnx.TensorProto.FLOAT, [4, 4]),\n", - " onnx.helper.make_tensor_value_info(\"abs1\", onnx.TensorProto.FLOAT, [4, 4]),\n", - " onnx.helper.make_tensor_value_info(\"sum3\", onnx.TensorProto.FLOAT, [4, 4]),\n", - " ],\n", - " )\n" + "graph = onnx.helper.make_graph(\n", + " nodes=[\n", + " Add1_node,\n", + " Add2_node,\n", + " Abs_node,\n", + " Add3_node,\n", + " Round_node,\n", + " ],\n", + " name=\"simple_graph\",\n", + " inputs=[in1, in2, in3],\n", + " outputs=[out1],\n", + " value_info=[\n", + " onnx.helper.make_tensor_value_info(\"sum1\", onnx.TensorProto.FLOAT, [4, 4]),\n", + " onnx.helper.make_tensor_value_info(\"sum2\", onnx.TensorProto.FLOAT, [4, 4]),\n", + " onnx.helper.make_tensor_value_info(\"abs1\", onnx.TensorProto.FLOAT, [4, 4]),\n", + " onnx.helper.make_tensor_value_info(\"sum3\", onnx.TensorProto.FLOAT, [4, 4]),\n", + " ],\n", + ")\n" ] }, { @@ -155,7 +155,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -172,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -208,9 +208,39 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Serving '/tmp/simple_model.onnx' at http://0.0.0.0:8081\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "showInNetron('/tmp/simple_model.onnx')" ] @@ -226,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -249,7 +279,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -267,7 +297,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -286,7 +316,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -305,9 +335,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The output of the ONNX model is: \n", + "[[14. 8. 6. 5.]\n", + " [13. 8. 12. 8.]\n", + " [ 1. 11. 2. 18.]\n", + " [19. 11. 18. 15.]]\n", + "\n", + "The output of the reference function is: \n", + "[[14. 8. 6. 5.]\n", + " [13. 8. 12. 8.]\n", + " [ 1. 11. 2. 18.]\n", + " [19. 11. 18. 15.]]\n", + "\n", + "The results are the same!\n" + ] + } + ], "source": [ "ref_output= expected_output(in1_values, in2_values, in3_values)\n", "print(\"The output of the ONNX model is: \\n{}\".format(output[0]))\n", @@ -346,7 +396,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -363,7 +413,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -387,7 +437,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -410,9 +460,19 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found adder node: Add1\n", + "Found adder node: Add2\n", + "Found adder node: Add3\n" + ] + } + ], "source": [ "add_nodes = identify_adder_nodes(finn_model)\n", "for node in add_nodes:\n", @@ -428,7 +488,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -457,7 +517,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -471,6 +531,7 @@ " node_pair.append(node)\n", " node_pair.append(successor)\n", " adder_pairs.append((node_pair))\n", + " print(adder_pairs)\n", " node_pair = []\n", " return adder_pairs\n", " " @@ -487,9 +548,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[input: \"in1\"\n", + "input: \"in2\"\n", + "output: \"sum1\"\n", + "name: \"Add1\"\n", + "op_type: \"Add\"\n", + ", input: \"sum1\"\n", + "input: \"in3\"\n", + "output: \"sum2\"\n", + "name: \"Add2\"\n", + "op_type: \"Add\"\n", + "]]\n", + "Found following pair that could be replaced by a sum node:\n", + "Add1\n", + "Add2\n" + ] + } + ], "source": [ "for node in add_nodes:\n", " add_pairs = adder_pair(finn_model, node)\n", @@ -513,9 +595,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The new node gets the following inputs: \n", + "['in1', 'in2', 'in3']\n" + ] + } + ], "source": [ "input_list = []\n", "for i in range(len(substitute_pair)):\n", @@ -539,7 +630,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -555,7 +646,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -576,7 +667,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -604,11 +695,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "onnx_model1 = qonnx.util.basic.qonnx_make_model(graph, producer_name=\"simple-model1\")\n", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'qonnx' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[28], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m onnx_model1 \u001b[38;5;241m=\u001b[39m \u001b[43mqonnx\u001b[49m\u001b[38;5;241m.\u001b[39mutil\u001b[38;5;241m.\u001b[39mbasic\u001b[38;5;241m.\u001b[39mqonnx_make_model(graph, producer_name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msimple-model1\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 2\u001b[0m onnx\u001b[38;5;241m.\u001b[39msave(onnx_model1, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/tmp/simple_model1.onnx\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", + "\u001b[0;31mNameError\u001b[0m: name 'qonnx' is not defined" + ] + } + ], + "source": [ + "onnx_model1 = qonnx_make_model(graph, producer_name=\"simple-model1\")\n", "onnx.save(onnx_model1, '/tmp/simple_model1.onnx')" ] }, @@ -670,7 +773,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.18" + "version": "3.8.19" }, "vscode": { "interpreter": { From 0247fcab5b9d52273bb2ce73711ed1afa0731f94 Mon Sep 17 00:00:00 2001 From: ahre5612 Date: Mon, 5 Aug 2024 13:31:54 +0200 Subject: [PATCH 2/3] minor bug fix --- notebooks/0_how_to_work_with_onnx.ipynb | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/notebooks/0_how_to_work_with_onnx.ipynb b/notebooks/0_how_to_work_with_onnx.ipynb index f78305df..3319c18a 100644 --- a/notebooks/0_how_to_work_with_onnx.ipynb +++ b/notebooks/0_how_to_work_with_onnx.ipynb @@ -695,21 +695,9 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'qonnx' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[28], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m onnx_model1 \u001b[38;5;241m=\u001b[39m \u001b[43mqonnx\u001b[49m\u001b[38;5;241m.\u001b[39mutil\u001b[38;5;241m.\u001b[39mbasic\u001b[38;5;241m.\u001b[39mqonnx_make_model(graph, producer_name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msimple-model1\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 2\u001b[0m onnx\u001b[38;5;241m.\u001b[39msave(onnx_model1, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/tmp/simple_model1.onnx\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", - "\u001b[0;31mNameError\u001b[0m: name 'qonnx' is not defined" - ] - } - ], + "outputs": [], "source": [ "onnx_model1 = qonnx_make_model(graph, producer_name=\"simple-model1\")\n", "onnx.save(onnx_model1, '/tmp/simple_model1.onnx')" From 56088a7bb84e9173c0cf2cbf4424ed4aca105143 Mon Sep 17 00:00:00 2001 From: ahre5612 Date: Mon, 5 Aug 2024 14:17:37 +0200 Subject: [PATCH 3/3] minor bug fix --- notebooks/0_how_to_work_with_onnx.ipynb | 156 +++++------------------- 1 file changed, 33 insertions(+), 123 deletions(-) diff --git a/notebooks/0_how_to_work_with_onnx.ipynb b/notebooks/0_how_to_work_with_onnx.ipynb index 3319c18a..a1c7a5ce 100644 --- a/notebooks/0_how_to_work_with_onnx.ipynb +++ b/notebooks/0_how_to_work_with_onnx.ipynb @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -57,7 +57,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -99,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -120,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -155,7 +155,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -172,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -208,39 +208,9 @@ }, { "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Serving '/tmp/simple_model.onnx' at http://0.0.0.0:8081\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "showInNetron('/tmp/simple_model.onnx')" ] @@ -256,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -279,7 +249,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -297,7 +267,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -316,7 +286,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -335,29 +305,9 @@ }, { "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The output of the ONNX model is: \n", - "[[14. 8. 6. 5.]\n", - " [13. 8. 12. 8.]\n", - " [ 1. 11. 2. 18.]\n", - " [19. 11. 18. 15.]]\n", - "\n", - "The output of the reference function is: \n", - "[[14. 8. 6. 5.]\n", - " [13. 8. 12. 8.]\n", - " [ 1. 11. 2. 18.]\n", - " [19. 11. 18. 15.]]\n", - "\n", - "The results are the same!\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "ref_output= expected_output(in1_values, in2_values, in3_values)\n", "print(\"The output of the ONNX model is: \\n{}\".format(output[0]))\n", @@ -396,7 +346,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -413,7 +363,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -437,7 +387,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -460,19 +410,9 @@ }, { "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Found adder node: Add1\n", - "Found adder node: Add2\n", - "Found adder node: Add3\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "add_nodes = identify_adder_nodes(finn_model)\n", "for node in add_nodes:\n", @@ -488,7 +428,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -517,7 +457,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -548,30 +488,9 @@ }, { "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[input: \"in1\"\n", - "input: \"in2\"\n", - "output: \"sum1\"\n", - "name: \"Add1\"\n", - "op_type: \"Add\"\n", - ", input: \"sum1\"\n", - "input: \"in3\"\n", - "output: \"sum2\"\n", - "name: \"Add2\"\n", - "op_type: \"Add\"\n", - "]]\n", - "Found following pair that could be replaced by a sum node:\n", - "Add1\n", - "Add2\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "for node in add_nodes:\n", " add_pairs = adder_pair(finn_model, node)\n", @@ -595,18 +514,9 @@ }, { "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The new node gets the following inputs: \n", - "['in1', 'in2', 'in3']\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "input_list = []\n", "for i in range(len(substitute_pair)):\n", @@ -630,7 +540,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -646,7 +556,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -667,7 +577,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "metadata": {}, "outputs": [], "source": [