Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark, in light modeAuto light/dark, in dark modeSkip to content
onnx-array-api 0.3.1 documentation
Logo
onnx-array-api 0.3.1 documentation

Contents

More

Back to top

onnx_array_api.translate_api

Main API

translate

onnx_array_api.translate_api.translate(proto:ModelProto,single_line:bool=False,api:str='light')str[source]

Translates an ONNX proto into a code usingLight API for ONNX: everything in one lineto describe the ONNX graph.

Parameters:
Returns:

code

<<<

fromonnx_array_api.light_apiimportstartfromonnx_array_api.translate_apiimporttranslateonx=(start().vin("X").reshape((-1,1)).Transpose(perm=[1,0]).rename("Y").vout().to_onnx())code=translate(onx)print(code)

>>>

(start(opset=22).cst(np.array([-1,1],dtype=np.int64)).rename('r').vin('X',elem_type=TensorProto.FLOAT).bring('X','r').Reshape().rename('r0_0').bring('r0_0').Transpose(perm=[1,0]).rename('Y').bring('Y').vout(elem_type=TensorProto.FLOAT).to_onnx())

The inner API from onnx package is also available.

<<<

fromonnx_array_api.light_apiimportstartfromonnx_array_api.translate_apiimporttranslateonx=(start().vin("X").reshape((-1,1)).Transpose(perm=[1,0]).rename("Y").vout().to_onnx())code=translate(onx,api="onnx")print(code)

>>>

opset_imports=[make_opsetid('',22),]inputs=[]outputs=[]nodes=[]initializers=[]sparse_initializers=[]functions=[]initializers.append(from_array(np.array([-1,1],dtype=np.int64),name='r'))inputs.append(make_tensor_value_info('X',TensorProto.FLOAT,shape=[]))nodes.append(make_node_extended('Reshape',['X','r'],['r0_0']))nodes.append(make_node_extended('Transpose',['r0_0'],['Y'],perm=[1,0]))outputs.append(make_tensor_value_info('Y',TensorProto.FLOAT,shape=[]))graph=make_graph(nodes,'light_api',inputs,outputs,initializers,sparse_initializer=sparse_initializers,)model=make_model(graph,functions=functions,opset_imports=opset_imports)

TheGraphBuilder API returns this:

<<<

fromonnx_array_api.light_apiimportstartfromonnx_array_api.translate_apiimporttranslateonx=(start().vin("X").reshape((-1,1)).Transpose(perm=[1,0]).rename("Y").vout().to_onnx())code=translate(onx,api="builder")print(code)

>>>

deflight_api(op:"GraphBuilder",X:"FLOAT[]",):r=np.array([-1,1],dtype=np.int64)r0_0=op.Reshape(X,r)Y=op.Transpose(r0_0,perm=[1,0])op.Identity(Y,outputs=["Y"])returnYg=GraphBuilder({'':22},ir_version=11)g.make_tensor_input("X",TensorProto.FLOAT,())light_api(g.op,"X")g.make_tensor_output("Y",TensorProto.FLOAT,(),is_dimension=False,indexed=False)model=g.to_onnx()

make_helper

onnx_array_api.translate_api.make_helper.make_node_extended(op_type:str,inputs:Sequence[str],outputs:Sequence[str],name:str|None=None,doc_string:str|None=None,domain:str|None=None,**kwargs:Any)NodeProto[source]

Constructs a NodeProto.

Parameters:
  • op_type – The name of the operator to construct

  • inputs – list of input names

  • outputs – list of output names

  • name – optional unique identifier for NodeProto

  • doc_string – optional documentation string for NodeProto

  • domain – optional domain for NodeProto.If it’s None, we will just use default domain (which is empty)

  • kwargs – the attributes of the node.

Returns:

node proto

onnx_array_api.translate_api.make_helper.make_ref_attribute(key:str,attr_type:int,ref_attr_name:str|None=None)AttributeProto[source]

Creates an attribute.

Parameters:
  • key – atttribute name

  • attr_type – attribute type

  • ref_attr_name – if not None, link this attributeto a function attribute

Returns:

attribute

Classes for the Translater

BaseEmitter

classonnx_array_api.translate_api.base_emitter.BaseEmitter[source]
render_attribute_value(value:Any)Tuple[List[str],str][source]

Renders an attribute value into a string.

Parameters:

value – value to converter

Returns:

rows to append before, actual value

EventType

classonnx_array_api.translate_api.base_emitter.EventType(*values)[source]

InnerEmitter

classonnx_array_api.translate_api.inner_emitter.InnerEmitter[source]

Converts event into proper code.

join(rows:List[str],single_line:bool=False)str[source]

Returns the separators.single_line is unused.

render_attribute_value(value:Any)Tuple[List[str],str][source]

Renders an attribute value into a string.

Parameters:

value – value to converter

Returns:

rows to append before, actual value

LightEmitter

classonnx_array_api.translate_api.light_emitter.LightEmitter[source]

Converts event into proper code.

join(rows:List[str],single_line:bool=False)str[source]

Join the rows

Translater

classonnx_array_api.translate_api.translate.Translater(proto:ModelProto|FunctionProto|GraphProto,emitter:LightEmitter|None=None)[source]

Translates an ONNX graph into a code following the light API.

export(as_str,single_line:bool=False)str|List[str][source]

Exports into a code.

Parameters:
  • as_str – as a single string or by rows

  • single_line – tries to compress the output into a single line

Returns:

list of instructions

extract_attributes(node:NodeProto)Dict[str,Tuple[AttributeProto,Any]][source]

Extracts all atributes of a node.

Parameters:

node – node proto

Returns:

dictionary

On this page

[8]ページ先頭

©2009-2025 Movatter.jp