create_model()¶
- audonnx.testing.create_model(shapes, *, value=0.0, dtype=1, opset_version=14, device='cpu', num_workers=1, session_options=None)[source]¶
Create test model.
Creates a model that outputs arrays filled with
value
of the givenshapes
. 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 graphvalue (
float
) – fill valuedtype (
int
) – data type, see supported data typesopset_version (
int
) – opset versiondevice (
Union
[str
,Tuple
[str
,Dict
],Sequence
[Union
[str
,Tuple
[str
,Dict
]]]]) – set device ('cpu'
,'cuda'
, or'cuda:<id>'
) or a (list of) provider(s)num_workers (
Optional
[int
]) – number of threads for running onnxruntime inference on cpu. IfNone
andsession_options
isNone
, onnxruntime chooses the number of threadssession_options (
Optional
[SessionOptions
]) –onnxruntime.SessionOptions
to use for inference. IfNone
the default options are used and the number of threads for running inference on cpu is determined bynum_workers
. Otherwise, the provided options are used and thesession_options
propertiesinter_op_num_threads
andintra_op_num_threads
determine the number of threads for inference on cpu andnum_workers
is ignored
- Return type
- 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)}