onnx.hub

ModelInfo

class onnx.hub.ModelInfo(raw_model_info: Dict[str, Any])[source]

A class to represent a model’s property and metadata in the ONNX Hub. It extracts model name, path, sha, tags, etc. from the passed in raw_model_info dict.

model

The name of the model.

model_path

The path to the model, relative to the model zoo (https://github.com/onnx/models/) repo root.

metadata

Additional metadata of the model, such as the size of the model, IO ports, etc.

model_sha

The SHA256 digest of the model file.

tags

A set of tags associated with the model.

opset

The opset version of the model.

list_models

onnx.hub.list_models(repo: str = 'onnx/models:main', model: Optional[str] = None, tags: Optional[List[str]] = None) List[ModelInfo][source]

Gets the list of model info consistent with a given name and tags

Parameters:
  • repo – The location of the model repo in format “user/repo[:branch]”. If no branch is found will default to “main”

  • model – The name of the model to search for. If None, will return all models with matching tags.

  • tags – A list of tags to filter models by. If None, will return all models with matching name.

Returns:

list of ModelInfo

get_model_info

onnx.hub.get_model_info(model: str, repo: str = 'onnx/models:main', opset: Optional[int] = None) ModelInfo[source]

Gets the model info matching the given name and opset.

Parameters:
  • model – The name of the onnx model in the manifest. This field is case-sensitive

  • repo – The location of the model repo in format “user/repo[:branch]”. If no branch is found will default to “main”

  • opset – The opset of the model to get. The default of None will return the model with largest opset.

Returns:

ModelInfo

load

onnx.hub.load(model: str, repo: str = 'onnx/models:main', opset: Optional[int] = None, force_reload: bool = False, silent: bool = False) Optional[ModelProto][source]

Downloads a model by name from the onnx model hub

Parameters:
  • model – The name of the onnx model in the manifest. This field is case-sensitive

  • repo – The location of the model repo in format “user/repo[:branch]”. If no branch is found will default to “main”

  • opset – The opset of the model to download. The default of None automatically chooses the largest opset

  • force_reload – Whether to force the model to re-download even if its already found in the cache

  • silent – Whether to suppress the warning message if the repo is not trusted.

Returns:

ModelProto or None