Skip to main content

Utils

Miscellaneous utility functions for ApertureDB. This class contains a collection of helper functions to interact with the database.

Utils Objects

class Utils(object)

Helper methods to get information from aperturedb, or affect it's state.

Arguments:

  • object Connector - The underlying Connector.

execute

def execute(query, blobs=[], success_statuses=[0])

Execute a query.

Arguments:

  • query list - The query to execute.
  • blobs list, optional - The blobs to send with the query.
  • success_statuses list, optional - The list of success statuses.

Returns:

  • result - The result of the query.
  • blobs - The blobs returned by the query.

status

def status()

Executes a GetStatus query. See GetStatus in the ApertureDB documentation for more information.

get_schema

def get_schema(refresh=False)

Get the schema of the database. See GetSchema in the ApertureDB documentation for more information.

visualize_schema

def visualize_schema(filename: str = None, format: str = "png") -> Source

Visualize the schema of the database. Optionally save the visualization to a file in the specified format.

The returned object can be rendered to a file as follows:

It can also be displayed inline in a Jupyter notebook:

Relies on graphviz to be installed.

s = utils.visualize_schema()
s.render("schema", format="png")
from IPython.display import display
s = utils.visualize_schema()
display(s)

Arguments:

  • filename str, optional - The filename to save the visualization to. Default is None.
  • format str, optional - The format to save the visualization to. Default is "png".

Returns:

  • source - The visualization of the schema.

summary

def summary()

Print a summary of the database.

This is essentially a call to GetSchema, with the results formatted in a more human-readable way.

create_entity_index

def create_entity_index(class_name, property_key, property_type=None)

Create an index for an entity class. See CreateIndex in the ApertureDB documentation for more information.

create_connection_index

def create_connection_index(class_name, property_key, property_type=None)

Create an index for a connection class. See CreateIndex in the ApertureDB documentation for more information.

remove_entity_index

def remove_entity_index(class_name, property_key)

Remove an index for an entity class. See RemoveIndex in the ApertureDB documentation for more information.

remove_connection_index

def remove_connection_index(class_name, property_key)

Remove an index for a connection class. See RemoveIndex in the ApertureDB documentation for more information.

count_images

def count_images(constraints={}) -> int

Count the number of images in the database.

Arguments:

  • constraints dict, optional - The constraints to apply to the query. See the Constraints wrapper class for more information.

Returns:

  • count - The number of images in the database.

count_bboxes

def count_bboxes(constraints=None) -> int

Count the number of bounding boxes in the database.

Arguments:

  • constraints dict, optional - The constraints to apply to the query. See the Constraints wrapper class for more information.

Returns:

  • count - The number of bounding boxes in the database.

count_entities

def count_entities(entity_class, constraints=None) -> int

Count the number of entities in the database.

Arguments:

  • constraints dict, optional - The constraints to apply to the query. See the Constraints wrapper class for more information.

Returns:

  • count - The number of entities in the database.

count_connections

def count_connections(connections_class, constraints=None) -> int

Count the number of connections in the database.

Arguments:

  • constraints dict, optional - The constraints to apply to the query. See the Constraints wrapper class for more information.

Returns:

  • count - The number of connections in the database.

add_descriptorset

def add_descriptorset(name: str,
dim: int,
metric="L2",
engine="FaissFlat",
properties: Optional[Dict] = None) -> bool

Add a descriptor set to the database.

Arguments:

  • name str - The name of the descriptor set.
  • dim int - The dimension of the descriptors.
  • metric str, optional - The metric to use for the descriptors.
  • engine str, optional - The engine to use for the descriptors.
  • properties dict, optional - The properties of the descriptor set.

Returns:

  • success bool - True if the operation was successful, False otherwise.

count_descriptorsets

def count_descriptorsets() -> int

Count the number of descriptor sets in the database.

Returns:

  • count - The number of descriptor sets in the database.

get_descriptorset_list

def get_descriptorset_list() -> List[str]

Get the list of descriptor sets in the database.

Returns:

  • sets list of str - The list of descriptor sets in the database.

remove_descriptorset

def remove_descriptorset(set_name: str) -> bool

Remove a descriptor set from the database.

See DeleteDescriptorSet in the ApertureDB documentation for more information.

Arguments:

  • set_name str - The name of the descriptor set.

Returns:

  • success bool - True if the operation was successful, False otherwise.

remove_entities

def remove_entities(class_name: str,
batched: bool = False,
batch_size: int = 10000) -> bool

Remove all entities of a given class from the database.

See DeleteEntity in the ApertureDB documentation for more information.

Arguments:

  • class_name str - The class of the entities to remove.
  • batched bool, optional - Whether to batch the operation. Default is False.
  • batch_size int, optional - The batch size to use. Default is 10000.

Returns:

  • success bool - True if the operation was successful, False otherwise.

remove_connections

def remove_connections(class_name, batched=False, batch_size=10000)

Remove all connections of a given class from the database.

See DeleteConnection in the ApertureDB documentation for more information.

Arguments:

  • class_name str - The class of the connections to remove.
  • batched bool, optional - Whether to batch the operation. Default is False.
  • batch_size int, optional - The batch size to use. Default is 10000.

Returns:

  • success bool - True if the operation was successful, False otherwise.

remove_all_descriptorsets

def remove_all_descriptorsets() -> bool

Remove all descriptor sets from the database, together with descriptors, indexes and connections.

Returns:

  • success bool - True if the operation was successful, False otherwise.

get_indexed_props

def get_indexed_props(class_name: str, type="entities") -> List[str]

Returns all the indexed properties for a given class.

Arguments:

  • class_name str - The class name.
  • type str, optional - The type of the class. Default is "entities".

Returns:

  • indexed_props list of str - The list of indexed properties.

count_descriptors_in_set

def count_descriptors_in_set(set_name: str) -> int

Count the number of descriptors in a descriptor set.

Arguments:

  • set_name str - The name of the descriptor set.

Returns:

  • total int - The number of descriptors in the set.

remove_all_indexes

def remove_all_indexes() -> bool

Remove all indexes from the database.

This may improve the performance of remove_all_objects. It may improve or degrade the performance of other operations.

Note that this only removes populated indexes.

Returns:

  • success bool - True if the operation was successful, False otherwise.

remove_all_objects

def remove_all_objects() -> bool

Remove all objects from the database.

This includes images, videos, blobs, clips, descriptor sets, descriptors, bounding boxes, polygons, frames, entities, connections, indexes and connections.

Returns:

  • success bool - True if the operation was successful, False otherwise.

user_log_message

def user_log_message(message: str, level: str = "INFO") -> None

Log a message to the user log.

This is useful because it can later be seen in Grafana, not only as log entries in the ApertureDB Logging dashboard, but also as event markers in the ApertureDB Status dashboard.

Arguments:

  • message str - The message to log.
  • level str - The level of the message. Default is "INFO".