Shell

class dragon.vm.onnx.Shell[source]

Context-manger to export or load onnx models.

Enter a shell to export operators into an onnx model:

x = dragon.constant([1, 2, 3])
with onnx.Shell() as shell, shell.as_default():
    y = x * x
shell.export(inputs=[x], outputs=[y], f='model.onnx')

The onnx models can also be loaded to execute:

f = shell.load_model('model.onnx', explicit_inputs=True)
print(f(np.array([1, 2, 3]))

__init__

Shell.__init__()[source]

Create a Shell.

Methods

as_default

Shell.as_default()[source]

Set as the default shell.

export

Shell.export(
  inputs,
  outputs,
  f,
  input_names=None,
  output_names=None,
  input_shapes=None,
  opset_version=None,
  verbose=False,
  enable_onnx_checker=True
)[source]

Export an onnx model.

Parameters:
  • inputs (Union[Sequence, Dict]) – The model inputs.
  • outputs (Union[Sequence, Dict]) – The model outputs.
  • f (str) – The filename for exporting model.
  • input_names (Sequence[str], optional) – The name to the inputs.
  • output_names (Sequence[str], optional) – The name to the outputs.
  • input_shapes (Union[Sequence, Dict], optional) – The optional rewritten for input shapes.
  • opset_version (int, optional) – The version of operator set.
  • verbose (bool, optional, default=False) – Whether to print the debug string of graph.
  • enable_onnx_checker (bool, optional, default=True) – Whether to check if model is valid.

load_model

static Shell.load_model(
  model_path,
  explicit_inputs=False
)[source]

Import an onnx model to the function.

Parameters:
  • model_path (str) – The path to the onnx model.
  • explicit_inputs (bool, optional, default=False) – True to attach model inputs to the function.
Returns:

callable – The function to run the model once.