tvm.relay.frontend

Frontends for constructing Relay programs.

Contains the model importers currently defined for Relay.

tvm.relay.frontend.from_mxnet(symbol, shape=None, dtype='float32', arg_params=None, aux_params=None)

Convert from MXNet”s model into compatible relay Function.

Parameters:
  • symbol (mxnet.Symbol or mxnet.gluon.HybridBlock) – MXNet symbol.
  • shape (dict of str to tuple, optional) – The input shape to the graph
  • dtype (str or dict of str to str) – The input types to the graph
  • arg_params (dict of str to mx.NDArray) – The argument parameters in mxnet
  • aux_params (dict of str to mx.NDArray) – The auxiliary parameters in mxnet
Returns:

  • sym (tvm.relay.Function) – Compatible relay Function
  • params (dict of str to tvm.NDArray) – The parameter dict to be used by nnvm

tvm.relay.frontend.from_keras(model, shape_dict)

Convert keras model to relay Function.

Parameters:
  • model (keras.engine.training.Model) – The keras model to be converted.
  • shape_dict (dict of str to int list/tuple) – Input shapes of the model.
Returns:

  • func (tvm.relay.Function) – Compatible relay Function.
  • params (dict of str to tvm.NDArray) – The parameter dict to be used by relay.

tvm.relay.frontend.from_onnx(model, shape=None, dtype='float32')

Convert a ONNX model into an equivalent Relay Function.

ONNX graphs are represented as Python Protobuf objects. The companion parameters will be handled automatically. However, the input names from onnx graph is vague, mixing inputs and network weights/bias such as “1”, “2”… For convenience, we rename the real input names to “input_0”, “input_1”… And renaming parameters to “param_0”, “param_1”…

Parameters:
  • model (protobuf object) – ONNX ModelProto after ONNX v1.1.0
  • shape (dict of str to tuple, optional) – The input shape to the graph
  • dtype (str or dict of str to str) – The input types to the graph
Returns:

  • sym (tvm.relay.expr.Function) – Compatible relay function
  • params (dict of str to tvm.NDArray) – The parameter dict to be used by relay