Inference Support
DeGirum Tools API Reference Guide. Utilities to connect, run, annotate, and profile inferences.
Inference Support Overview
Key Concepts
Basic Usage Example
from degirum_tools import (
ModelSpec,
remote_assets,
attach_analyzers,
annotate_video,
model_time_profile,
ResultAnalyzerBase,
)
# Define a simple analyzer that draws text on each frame
class MyDummyAnalyzer(ResultAnalyzerBase):
def analyze(self, result):
# Optional: add custom logic here, e.g. track or filter detections
pass
def annotate(self, result, image):
"""
Draws a simple "Dummy Analyzer" label in the top-left corner of each frame.
"""
import cv2
cv2.putText(
image,
"Dummy Analyzer",
(10, 30),
cv2.FONT_HERSHEY_SIMPLEX,
1.0,
(0, 255, 0),
2
)
return image
# Describe the model once so the configuration is reusable.
model_spec = ModelSpec(
model_name="<your_model_name>",
zoo_url="degirum/degirum",
inference_host_address="@cloud",
)
with model_spec.load_model() as model:
# Attach dummy analyzer
attach_analyzers(model, MyDummyAnalyzer())
# Annotate a video with detection results + dummy analyzer and set a path to save the video
annotate_video(
model,
video_source_id=remote_assets.store_short,
output_video_path="annotated_output.mp4",
show_progress=True, # Show a progress bar in console
visual_display=True, # Open an OpenCV window to display frames
show_ai_overlay=True, # Use model's overlay with bounding boxes
fps=None # Use the source's native frame rate
)
# Time-profile the model
profile = model_time_profile(model, iterations=100)
print("Time profiling results:")
print(f" Elapsed time: {profile.elapsed:.3f} s")
print(f" Observed FPS: {profile.observed_fps:.2f}")
print(f" Max possible FPS: {profile.max_possible_fps:.2f}")Functions
connect_model_zoo(inference_option=CloudInference)
Name
Type
Description
Default
Type
Description
Type
Description
attach_analyzers(model, ...)
Name
Type
Description
Default
predict_stream(model, ...)
Name
Type
Description
Default
Name
Type
Description
annotate_video(model, ...)
Name
Type
Description
Default
model_time_profile(model, ...)
Name
Type
Description
Default
Type
Description
Name
Type
Description
warmup_device(model, ...)
warmup_model(model)
Name
Type
Description
Default
Classes
ModelTimeProfile
Name
Type
Description
Last updated
Was this helpful?

