pythia.models.base#

Model.

A deep learning model used to extract metadata from a video source. Contains:

A labels.txt file, containing the list of model labels. A pgie.conf file. A model.etlt,model.engine or any Deepstream-nvinfer compatible engine file.

class pythia.models.base.Analytics(config_file: ~pathlib.Path, _string: ~typing.Optional[str] = None, _default_props: ~typing.Dict[str, str] = <factory>, CONNECTIONS: ~typing.Dict[str, ~typing.Dict[str, ~typing.Callable]] = <factory>)[source]#

Bases: HasConnections

Pythia wrapper around nvdsanalytics gst element.

CONNECTIONS: Dict[str, Dict[str, Callable]]#
_abc_impl = <_abc_data object>#
_default_props: Dict[str, str]#
_is_protocol = False#
_string: Optional[str] = None#
config_file: Path#
classmethod from_element(element: Element) A[source]#

Factory from nvdsanalytics.

Parameters:

element – The nvdsanalytics to use as source.

Returns:

The instantiated nvdsanalytics wrapper.

classmethod from_file(config_file: Path) A[source]#

Factory from configuration file.

Parameters:

config_file – location of the nvdsanalytics config-file property.

Returns:

The instantiated nvdsanalytics wrapper class.

Raises:

FileNotFoundError – The nvdsanalytics config-file property is not found.

gst(**kwargs: str) str[source]#

Render string as gst-launch-like parseable string.

Parameters:

kwargs – Additional gst element properties.

Returns:

Rendered nvdsanalytics.

requires_tracker() bool[source]#

Return True if its nvdsanalytics requires nvtracker.

Returns:

True if its nvdsanalytics contains line crossing or

direction andata.

class pythia.models.base.InferenceEngine(labels_file: ~pathlib.Path, config_file: ~pathlib.Path, _string: ~typing.Optional[str] = None, source_model: ~typing.Optional[~pathlib.Path] = None, compiled_model: ~typing.Optional[~pathlib.Path] = None, _default_props: ~typing.Dict[str, str] = <factory>, CONNECTIONS: ~typing.Dict[str, ~typing.Dict[str, ~typing.Callable]] = <factory>)[source]#

Bases: HasConnections

Pythia wrapper around nvinfer gst element.

CONNECTIONS: Dict[str, Dict[str, Callable]]#
MODEL_CONFIG_SUFFIXES = ('.conf', '.ini', '.yml', '.yaml')#

Ordered collection of supported model config file extensions.

Used when an inference engine is to be instantiated by a directory, to locate config-file-path from their extension.

See Also: locate_config_file().

MODEL_SUFFIXES = {'.caffe': 'model-file', '.caffemodel': 'model-file', '.etlt': 'tlt-encoded-model', '.onnx': 'onnx-file', '.prototxt': 'proto-file', '.uff': 'uff-file'}#

Supported model extensions (prioritized order).

Used when an inference engine is to be instantiated by a directory, to locate supported models from their extension.

See Also: locate_source_model().

_abc_impl = <_abc_data object>#
_default_props: Dict[str, str]#
_is_protocol = False#
_string: Optional[str] = None#
compiled_model: Optional[Path] = None#
config_file: Path#
classmethod from_element(element: Element) IE[source]#

Factory from nvinfer.

Parameters:

element – The nvinfer to use as source.

Returns:

The instantiated nvinfer wrapper.

classmethod from_folder(folder: str | Path) IE[source]#

Factory to instantiate from directories.

Parameters:

folder – Directory where the model files are located.

Returns:

Instantiated model.

Raises:

FileNotFoundError – empty folder received.

gst(name: str, **kw) str[source]#

Render nvinfer with gst-launch-like syntax.

Parameters:
  • name – nvinfer gstreamer element name property.

  • kw – nvinfer gstreamer property name and value.

Returns:

Rendered string

labels_file: Path#
static locate_compiled_model(folder: Path, source_model: Path | None) Path | None[source]#

Find the first model engine file in a folder.

Returns a file matching the *.engine pattern

Parameters:
  • folder – Directory to search the model.

  • source_model – If set, use this path’s stem to try to locate the .engine file. Otherwise, finds any *.engine.

Returns:

path to the found configuration file.

Raises:

FileNotFoundError – No configuration file found using any of the strategies.

classmethod locate_config_file(folder: Path) Path[source]#

Find the first model config file in a folder.

Iterate over the known nvinfer-compatible config-file-path file extensions, and returns at the first success.

Parameters:

folder – Directory to search the model.

Returns:

path to the found configuration file.

Raises:

FileNotFoundError – No configuration file found.

static locate_labels_file(folder: Path) Path[source]#

Find labels file from a directory.

Parameters:

folder – directory to search labels file.

Returns:

The first file matching the *label* pattern inside the directory.

Raises:

FileNotFoundError – no file matches the expected labels pattern.

classmethod locate_source_model(folder: Path) Path | None[source]#

Find the first deepstream model file in a folder.

It iterates over the known nvinfer-compatible model file extensions, and returns at the first success.

Parameters:

folder – Directory to search the model.

Returns:

Found model, or None if not found.

static pop_property_or_get_from_nvinfer_conf(config_file: Path, props: dict[str, str], *, property_names: Collection[str]) Path | None[source]#

Pop nvinfer property, or get from config_file if not found.

Parameters:
  • config_filenvinfer.conf ini file. Used to compute absolute paths, and default source for property values if not found in the props arg.

  • props – element properties where to look for the desired properties. Note: If the property is found, its popped from this dict.

  • property_names – possible property names to look for.

Returns:

First occurence of the property_names, as found either in

the props dict or in the nvinfer.conf [property] section.

Raises:

FileNotFoundError – None of the requested names is available in the properties, and the config file does not exist.

source_model: Optional[Path] = None#
class pythia.models.base.Tracker(config_file: ~pathlib.Path, low_level_library: ~pathlib.Path = PosixPath('/opt/nvidia/deepstream/deepstream-6.1/lib/libnvds_nvmultiobjecttracker.so'), _string: ~typing.Optional[str] = None, _default_props: ~typing.Dict[str, str] = <factory>, CONNECTIONS: ~typing.Dict[str, ~typing.Dict[str, ~typing.Callable]] = <factory>)[source]#

Bases: HasConnections

Pythia wrapper around nvtracker gst element.

CONNECTIONS: Dict[str, Dict[str, Callable]]#
_abc_impl = <_abc_data object>#
_default_props: Dict[str, str]#
_is_protocol = False#
_string: Optional[str] = None#
config_file: Path#
classmethod from_element(element: Element) T[source]#

Factory from nvtracker.

Parameters:

element – The nvtracker to use as source.

Returns:

The instantiated nvtracker wrapper.

classmethod from_file(config_file: Path, low_level_library: Path = PosixPath('/opt/nvidia/deepstream/deepstream-6.1/lib/libnvds_nvmultiobjecttracker.so')) T[source]#

Factory to create Tracker s from configuration file.

Parameters:
  • config_file – path for the nvtracker gstreamer element ‘ll-config-file’ property.

  • low_level_library – path for the nvtracker gstreamer element ‘ll-lib-file’ property (shared object).

Returns:

Instantiated Tracker.

Raises:

FileNotFoundError – Tracker config file does not exist.

gst(**kwargs: str) str[source]#

Render nvtracker element with gst-launch-like syntax.

Parameters:

kwargs – Additional gst element properties.

Returns:

Rendered string.

Raises:

FileNotFoundError – Tracker ll-config-file not found.

low_level_library: Path = PosixPath('/opt/nvidia/deepstream/deepstream-6.1/lib/libnvds_nvmultiobjecttracker.so')#