create_model()

audonnx.testing.create_model(shapes, *, value=0.0, dtype=1, opset_version=14, ir_version=7, device='cpu', num_workers=1, session_options=None)[source]

Create test model.

Creates a model that outputs arrays filled with value of the given shapes. For each entry an output node will be created. -1, None or strings define a dynamic axis. Per node, one dynamic axis is allowed.

Parameters:
  • shapes (Sequence[Sequence[int]]) – list with shapes defining the identical input and output nodes of the model graph

  • value (float) – fill value

  • dtype (int) – data type, see supported data types

  • opset_version (int) – opset version

  • ir_version (int) – ir version

  • device (str | tuple[str, dict] | Sequence[str | tuple[str, dict]]) – set device ('cpu', 'cuda', or 'cuda:<id>') or a (list of) provider(s)

  • num_workers (int | None) – number of threads for running onnxruntime inference on cpu. If None and session_options is None, onnxruntime chooses the number of threads

  • session_options (Optional[SessionOptions]) – onnxruntime.SessionOptions to use for inference. If None the default options are used and the number of threads for running inference on cpu is determined by num_workers. Otherwise, the provided options are used and the session_options properties inter_op_num_threads and intra_op_num_threads determine the number of threads for inference on cpu and num_workers is ignored

Return type:

Model

Returns:

model object

Examples

>>> shapes = [[3], [1, -1, 2]]
>>> model = create_model(shapes)
>>> model
Input:
  input-0:
    shape: [3]
    dtype: tensor(float)
    transform: audonnx.core.function.Function(reshape)
  input-1:
    shape: [1, -1, 2]
    dtype: tensor(float)
    transform: audonnx.core.function.Function(reshape)
Output:
  output-0:
    shape: [3]
    dtype: tensor(float)
    labels: [output-0-0, output-0-1, output-0-2]
  output-1:
    shape: [1, -1, 2]
    dtype: tensor(float)
    labels: [output-1-0, output-1-1]
>>> signal = np.zeros((1, 5), np.float32)
>>> model(signal, 8000)
{'output-0': array([0., 0., 0.], dtype=float32), 'output-1': array([[[0., 0.],
        [0., 0.],
        [0., 0.],
        [0., 0.],
        [0., 0.]]], dtype=float32)}