10
"output_type": "stream",
12
"Before shape inference, the shape info of Y is:\n",
19
"from onnx import helper, shape_inference\n",
20
"from onnx import TensorProto\n",
23
"# Preprocessing: create a model with two nodes, Y's shape is unknown\n",
24
"node1 = helper.make_node(\"Transpose\", [\"X\"], [\"Y\"], perm=[1, 0, 2])\n",
25
"node2 = helper.make_node(\"Transpose\", [\"Y\"], [\"Z\"], perm=[1, 0, 2])\n",
27
"graph = helper.make_graph(\n",
29
" \"two-transposes\",\n",
30
" [helper.make_tensor_value_info(\"X\", TensorProto.FLOAT, (2, 3, 4))],\n",
31
" [helper.make_tensor_value_info(\"Z\", TensorProto.FLOAT, (2, 3, 4))],\n",
34
"original_model = helper.make_model(graph, producer_name=\"onnx-examples\")\n",
36
"# Check the model and print Y's shape information\n",
37
"onnx.checker.check_model(original_model)\n",
39
" \"Before shape inference, the shape info of Y is:\\n{}\".format(\n",
40
" original_model.graph.value_info\n",
52
"output_type": "stream",
54
"After shape inference, the shape info of Y is:\n",
77
"# Apply shape inference on the model\n",
78
"inferred_model = shape_inference.infer_shapes(original_model)\n",
80
"# Check the model and print Y's shape information\n",
81
"onnx.checker.check_model(inferred_model)\n",
83
" \"After shape inference, the shape info of Y is:\\n{}\".format(\n",
84
" inferred_model.graph.value_info\n",
92
"display_name": "Python 3",
101
"file_extension": ".py",
102
"mimetype": "text/x-python",
104
"nbconvert_exporter": "python",
105
"pygments_lexer": "ipython3",