Title: | R Interface to 'ONNX' |
---|---|
Description: | R Interface to 'ONNX' - Open Neural Network Exchange <https://onnx.ai/>. 'ONNX' provides an open source format for machine learning models. It defines an extensible computation graph model, as well as definitions of built-in operators and standard data types. |
Authors: | Yuan Tang [aut, cre] , ONNX Authors [aut, cph], Facebook, Inc. [cph], Microsoft Corporation [cph] |
Maintainer: | Yuan Tang <[email protected]> |
License: | MIT License + file LICENSE |
Version: | 0.0.3 |
Built: | 2024-11-12 04:56:17 UTC |
Source: | https://github.com/onnx/onnx-r |
This method checks whether a protobuf in a particular type is valid.
check(proto, ir_version) ## S3 method for class 'onnx_pb2.ModelProto' check(proto, ir_version = 3L) ## S3 method for class 'onnx_pb2.GraphProto' check(proto, ir_version = 3L) ## S3 method for class 'onnx_pb2.TensorProto' check(proto, ir_version = 3L) ## S3 method for class 'onnx_pb2.AttributeProto' check(proto, ir_version = 3L) ## S3 method for class 'onnx_pb2.NodeProto' check(proto, ir_version = 3L)
check(proto, ir_version) ## S3 method for class 'onnx_pb2.ModelProto' check(proto, ir_version = 3L) ## S3 method for class 'onnx_pb2.GraphProto' check(proto, ir_version = 3L) ## S3 method for class 'onnx_pb2.TensorProto' check(proto, ir_version = 3L) ## S3 method for class 'onnx_pb2.AttributeProto' check(proto, ir_version = 3L) ## S3 method for class 'onnx_pb2.NodeProto' check(proto, ir_version = 3L)
proto |
The proto |
ir_version |
The version of the proto |
## Not run: library(onnx) # Define a node protobuf and check whether it's valid node_def <- make_node("Relu", list("X"), list("Y")) check(node_def) ## End(Not run)
## Not run: library(onnx) # Define a node protobuf and check whether it's valid node_def <- make_node("Relu", list("X"), list("Y")) check(node_def) ## End(Not run)
Loads a binary protobuf that stores onnx model
load_from_file(obj)
load_from_file(obj)
obj |
a file-like object (has "read" function) or a string containing a file name |
ONNX ModelProto object
Loads a binary string that stores onnx model
load_from_string(s)
load_from_string(s)
s |
string object containing protobuf |
ONNX ModelProto object
This includes AttributeProto, GraphProto, NodeProto, TensorProto, TensorValueInfoProto, etc.
make_attribute(key, value, doc_string = NULL) make_graph(nodes, name, inputs, outputs, initializer = NULL, doc_string = NULL) make_node(op_type, inputs, outputs, name = NULL, doc_string = NULL) make_tensor(name, data_type, dims, vals, raw = FALSE) make_tensor_value_info(name, elem_type, shape, doc_string = "")
make_attribute(key, value, doc_string = NULL) make_graph(nodes, name, inputs, outputs, initializer = NULL, doc_string = NULL) make_node(op_type, inputs, outputs, name = NULL, doc_string = NULL) make_tensor(name, data_type, dims, vals, raw = FALSE) make_tensor_value_info(name, elem_type, shape, doc_string = "")
key |
The key |
value |
The value |
doc_string |
The doc_string |
nodes |
The nodes |
name |
The name |
inputs |
The inputs |
outputs |
The outputs |
initializer |
The initializer |
op_type |
The op type |
data_type |
The data type |
dims |
The dimensions |
vals |
The values |
raw |
If this is |
elem_type |
The element type, e.g. |
shape |
The shape |
## Not run: library(onnx) # Define a node protobuf and check whether it's valid node_def <- make_node("Relu", list("X"), list("Y")) check(node_def) # Define an attribute protobuf and check whether it's valid attr_def <- make_attribute("this_is_an_int", 123L) check(attr_def) # Define a graph protobuf and check whether it's valid graph_def <- make_graph( nodes = list( make_node("FC", list("X", "W1", "B1"), list("H1")), make_node("Relu", list("H1"), list("R1")), make_node("FC", list("R1", "W2", "B2"), list("Y")) ), name = "MLP", inputs = list( make_tensor_value_info('X' , onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('W1', onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('B1', onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('W2', onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('B2', onnx$TensorProto$FLOAT, list(1L)) ), outputs = list( make_tensor_value_info('Y', onnx$TensorProto$FLOAT, list(1L)) ) ) check(graph_def) ## End(Not run)
## Not run: library(onnx) # Define a node protobuf and check whether it's valid node_def <- make_node("Relu", list("X"), list("Y")) check(node_def) # Define an attribute protobuf and check whether it's valid attr_def <- make_attribute("this_is_an_int", 123L) check(attr_def) # Define a graph protobuf and check whether it's valid graph_def <- make_graph( nodes = list( make_node("FC", list("X", "W1", "B1"), list("H1")), make_node("Relu", list("H1"), list("R1")), make_node("FC", list("R1", "W2", "B2"), list("Y")) ), name = "MLP", inputs = list( make_tensor_value_info('X' , onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('W1', onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('B1', onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('W2', onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('B2', onnx$TensorProto$FLOAT, list(1L)) ), outputs = list( make_tensor_value_info('Y', onnx$TensorProto$FLOAT, list(1L)) ) ) check(graph_def) ## End(Not run)
Print the Human-readable Representation of the Proto Object
print_readable(x)
print_readable(x)
x |
The proto object |
## Not run: library(onnx) graph_def <- make_graph( nodes = list( make_node("FC", list("X", "W1", "B1"), list("H1")), make_node("Relu", list("H1"), list("R1")), make_node("FC", list("R1", "W2", "B2"), list("Y")) ), name = "MLP", inputs = list( make_tensor_value_info('X' , onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('W1', onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('B1', onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('W2', onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('B2', onnx$TensorProto$FLOAT, list(1L)) ), outputs = list( make_tensor_value_info('Y', onnx$TensorProto$FLOAT, list(1L)) ) ) print_readable(graph_def) ## End(Not run)
## Not run: library(onnx) graph_def <- make_graph( nodes = list( make_node("FC", list("X", "W1", "B1"), list("H1")), make_node("Relu", list("H1"), list("R1")), make_node("FC", list("R1", "W2", "B2"), list("Y")) ), name = "MLP", inputs = list( make_tensor_value_info('X' , onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('W1', onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('B1', onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('W2', onnx$TensorProto$FLOAT, list(1L)), make_tensor_value_info('B2', onnx$TensorProto$FLOAT, list(1L)) ), outputs = list( make_tensor_value_info('Y', onnx$TensorProto$FLOAT, list(1L)) ) ) print_readable(graph_def) ## End(Not run)