Loading an AI Model
This is an end-to-end guide for loading a model. You'll start with connecting to an inference engine and model zoo, learn about filtering model lists, then loading a model.
Connect to an Inference Engine and Model Zoo
The degirum.connect()
function is the starting point for interacting with PySDK. It establishes a connection with the appropriate AI inference engine and model zoo based on the configuration you provide.
When you call degirum.connect()
, you will:
Specify an inference host to run AI models
Specify a model zoo from which AI models can be loaded
Authenticate with the AI Hub using a token
degirum.connect()
creates and returns a ZooManager
object. This object enables:
Searching for models available in the connected model zoo.
Loading AI models and creating appropriate AI model handling objects for inference.
Accessing model parameters to customize inference behavior.
degirum.connect()
degirum.connect()
takes three parameters: inference_host_address
, zoo_url
, and token
. These parameters define where the inference will be run, what zoo will be used, and the token used for AI Hub authentication if an AI Hub model zoo will be used.
The following table lists all possible combinations of inference and zoo types with degirum.connect():
AI Hub
Default: AI Hub Public Model Zoo (degirum/public
)
AI Hub
Specified AI Hub Model Zoo
AI Server
Default: Local Folder
AI Server
Specified AI Hub Model Zoo
Local
Default: AI Hub Public Model Zoo (degirum/public
)
Local
Specified AI Hub Model Zoo
Local
Local Folder
Local
Local File
Your AI Hub token is needed only with AI Hub Inference or private model zoos.
Retrieve Supported Devices, Filter Models, then Load Models
ZooManager.supported_device_types()
The ZooManager.supported_device_types()
method returns a list of runtime and device combinations (in "RUNTIME/DEVICE"
format) that the connected inference engine supports.
Example:
Output:
In this example, the inference engine returns a list of supported device types on the application server. In thise case, it's the application server hosted on dg.CLOUD
.
ZooManager.list_models()
After obtaining a ZooManager
object, you can use the ZooManager.list_models()
method to retrieve and filter the list of available AI models.
This method:
Filters models based on various criteria such as model family, runtime, device type, precision, and more.
Returns a list of model names that can be used later when loading models for inference.
Use Cases
Exploring available model families (e.g., mobilenet, YOLO).
Filtering models based on target hardware.
Selecting models for specific precision or density.
Example Usage
In this example, the inference engine returns a list of models that run using the OpenVINO runtime on a CPU.
Available Filtering Parameters and Their Sources
The ZooManager.list_models()
method filters models based on information retrieved from the model name string and also the model JSON fields.
For models named based on our recommended model naming conventions, the model name string store the model_family
, precision
, and pruned
parameters.
The model JSON file specifies the RuntimeAgent
, DeviceType
, and SupportedDeviceTypes
fields.
model_family
Any valid substring like "yolo"
, "mobilenet"
Extracted from the model name
precision
"quant"
(quantized model), "float"
(floating-point model)
Inferred from the presence of precision-related fields in the model name
pruned
"dense"
(dense model), "pruned"
(sparse/pruned model)
Determined from suffixes indicating density in the model name (e.g., "pruned"
or "dense"
)
runtime
Combines information from "RuntimeAgent"
and "SupportedDeviceTypes"
device
Combines information from "DeviceType"
and "SupportedDeviceTypes"
device_type
Extracted from the "SupportedDeviceTypes"
Combine list_models() with supported_device_types() to Find Supported Models
To find only the models that are compatible with the current inference engine, you can use the supported_device_types()
method as a filter for list_models()
.
Example:
ZooManager.load_model()
Once you have obtained supported models from filtering list_models() with supported_device_types()
methods, you can load all of the resulting models for inference using the degirum.zoo_manager.ZooManager.load_model()
method.
Basic Usage
To load a model, pass the model name string as the model_name
argument to load_model()
.
Example:
If a model with the specified name is found, the method returns a
degirum.model.Model
object that you can use to run inference.If the model is not found, an exception will be raised.
Passing Model Properties as Arguments
You can pass additional model properties as keyword arguments to customize the behavior of the loaded model. These properties are directly assigned to the model object.
Example:
In this example:
output_confidence_threshold=0.5
sets a confidence threshold for inference results.input_pad_method="letterbox"
specifies the padding method to maintain the input aspect ratio.
Convenience Functions
degirum.get_supported_devices()
You can retrieve supported device types using the degirum.get_supported_devices()
function. This function combines the arguments of both degirum.connect()
and degirum.zoo_manager.ZooManager.get_supported_devices()
, allowing you to list supported devices with a single call.
Function Signature:
Example:
degirum.list_models()
You can retrieve the list of models using the degirum.list_models()
function. This function combines the arguments of both degirum.connect()
and degirum.zoo_manager.ZooManager.list_models()
, allowing you list models with a single call.
Function Signature:
Example:
In this example, the method connects to the specified model zoo and returns a list of models that run with the OpenVINO runtime on a CPU.
degirum.load_model()
For convenience, you can directly load a model without explicitly obtaining a ZooManager
object with degirum.connect()
. The degirum.load_model()
function combines the arguments of degirum.connect()
and ZooManager.load_model()
, allowing you to load models with a single call.
Function Signature:
Example:
In this example, the code gets supported devices, lists models, then loads a model based on the filtered list with a specified parameter.
Minimum Code Example
After you master all above steps, you can distill your code into just a few lines.
Last updated
Was this helpful?