{"library":"onnx","code":"import onnx\nfrom onnx import helper, checker, TensorProto\nimport numpy as np\nimport os\n\n# Create a simple ONNX model: Y = X + A\n# Define model inputs and outputs\nX = helper.make_tensor_value_info('X', TensorProto.FLOAT, [None, 2])\nA = helper.make_tensor_value_info('A', TensorProto.FLOAT, [2])\nY = helper.make_tensor_value_info('Y', TensorProto.FLOAT, [None, 2])\n\n# Create a node for the Add operation\nnode_def = helper.make_node(\n    'Add',\n    inputs=['X', 'A'],\n    outputs=['Y'],\n)\n\n# Create the graph\ngraph_def = helper.make_graph(\n    [node_def],\n    'simple-add-model',\n    [X, A],\n    [Y],\n)\n\n# Create the model with specified opset_imports (e.g., opset 13)\n# Opset 13 is commonly used and widely supported.\nmodel_def = helper.make_model(\n    graph_def,\n    producer_name='onnx-example',\n    opset_imports=[helper.make_opsetid('', 13)]\n)\n\n# Check the model for validity\nchecker.check_model(model_def)\nprint('Model is valid!')\n\n# Save the model to a file\nmodel_path = 'simple_add_model.onnx'\nonnx.save(model_def, model_path)\nprint(f'Model saved to {model_path}')\n\n# Optional: Load the model back and print its structure\nloaded_model = onnx.load(model_path)\nprint('\\nLoaded model:\\n', loaded_model.graph.node)\n\n# Clean up the created file\n# os.remove(model_path)\n","lang":"python","description":"This quickstart demonstrates how to programmatically create a simple ONNX model (Y = X + A), validate it using `onnx.checker`, and then save it to a `.onnx` file using the ONNX Python API. It also shows how to load the model back for inspection.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":0}]}