Package 'onnx'

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

Help Index


Check Whether The Proto is Valid

Description

This method checks whether a protobuf in a particular type is valid.

Usage

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)

Arguments

proto

The proto

ir_version

The version of the proto

Examples

## 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

Description

Loads a binary protobuf that stores onnx model

Usage

load_from_file(obj)

Arguments

obj

a file-like object (has "read" function) or a string containing a file name

Value

ONNX ModelProto object


Loads a binary string that stores onnx model

Description

Loads a binary string that stores onnx model

Usage

load_from_string(s)

Arguments

s

string object containing protobuf

Value

ONNX ModelProto object


Make Different Types of Protos

Description

This includes AttributeProto, GraphProto, NodeProto, TensorProto, TensorValueInfoProto, etc.

Usage

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 = "")

Arguments

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 ⁠FALSE``, this function will choose the corresponding proto field to store the values based on ⁠data_type⁠. If raw is ⁠TRUE', use "raw_data" proto field to store the values, and values should be of type bytes in this case.

elem_type

The element type, e.g. onnx$TensorProto$FLOAT

shape

The shape

Examples

## 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)