MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / onnx_export

Function onnx_export

monai/bundle/scripts.py:1323–1434  ·  view source on GitHub ↗

Export the model checkpoint to an onnx model. Typical usage examples: .. code-block:: bash python -m monai.bundle onnx_export network --filepath --ckpt_file ... Args: net_id: ID name of the network component in the config, it must

(
    net_id: str | None = None,
    filepath: PathLike | None = None,
    ckpt_file: str | None = None,
    meta_file: str | Sequence[str] | None = None,
    config_file: str | Sequence[str] | None = None,
    key_in_ckpt: str | None = None,
    use_trace: bool | None = None,
    input_shape: Sequence[int] | None = None,
    args_file: str | None = None,
    converter_kwargs: Mapping | None = None,
    **override: Any,
)

Source from the content-addressed store, hash-verified

1321
1322
1323def onnx_export(
1324 net_id: str | None = None,
1325 filepath: PathLike | None = None,
1326 ckpt_file: str | None = None,
1327 meta_file: str | Sequence[str] | None = None,
1328 config_file: str | Sequence[str] | None = None,
1329 key_in_ckpt: str | None = None,
1330 use_trace: bool | None = None,
1331 input_shape: Sequence[int] | None = None,
1332 args_file: str | None = None,
1333 converter_kwargs: Mapping | None = None,
1334 **override: Any,
1335) -> None:
1336 """
1337 Export the model checkpoint to an onnx model.
1338
1339 Typical usage examples:
1340
1341 .. code-block:: bash
1342
1343 python -m monai.bundle onnx_export network --filepath <export path> --ckpt_file <checkpoint path> ...
1344
1345 Args:
1346 net_id: ID name of the network component in the config, it must be `torch.nn.Module`.
1347 filepath: filepath where the onnx model is saved to.
1348 ckpt_file: filepath of the model checkpoint to load.
1349 meta_file: filepath of the metadata file, if it is a list of file paths, the content of them will be merged.
1350 config_file: filepath of the config file that contains extract network information,
1351 key_in_ckpt: for nested checkpoint like `{"model": XXX, "optimizer": XXX, ...}`, specify the key of model
1352 weights. if not nested checkpoint, no need to set.
1353 use_trace: whether using `torch.jit.trace` to convert the pytorch model to torchscript model.
1354 input_shape: a shape used to generate the random input of the network, when converting the model to an
1355 onnx model. Should be a list like [N, C, H, W] or [N, C, H, W, D]. If not given, will try to parse from
1356 the `metadata` config.
1357 args_file: a JSON or YAML file to provide default values for all the parameters of this function, so that
1358 the command line inputs can be simplified.
1359 converter_kwargs: extra arguments that are needed by `convert_to_onnx`, except ones that already exist in the
1360 input parameters.
1361 override: id-value pairs to override or add the corresponding config content.
1362 e.g. ``--_meta#network_data_format#inputs#image#num_channels 3``.
1363
1364 """
1365 _args = update_kwargs(
1366 args=args_file,
1367 net_id=net_id,
1368 filepath=filepath,
1369 meta_file=meta_file,
1370 config_file=config_file,
1371 ckpt_file=ckpt_file,
1372 key_in_ckpt=key_in_ckpt,
1373 use_trace=use_trace,
1374 input_shape=input_shape,
1375 converter_kwargs=converter_kwargs,
1376 **override,
1377 )
1378 _log_input_summary(tag="onnx_export", args=_args)
1379 (
1380 filepath_,

Callers

nothing calls this directly

Calls 9

read_configMethod · 0.95
read_metaMethod · 0.95
ConfigParserClass · 0.90
update_kwargsFunction · 0.85
_log_input_summaryFunction · 0.85
_pop_argsFunction · 0.85
_get_fake_input_shapeFunction · 0.85
_exportFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…