pocketpose.utils#

The utils module contains utility functions and classes.

Subpackages#

Submodules#

Package Contents#

Classes#

Registry

A registry to map names to classes.

Functions#

download_file(url, save_path[, google_drive])

Download a file from the specified URL.

write_to_table(data, save_path[, tablefmt])

Save the data as a table in the specified format.

build_from_cfg(cfg, registry[, default_args])

Build a class from the config.

estimate_flops_tflite(→ float)

Estimates the number of floating point operations in a TFLite model.

estimate_parameters_tflite(→ int)

Estimates the number of parameters in a TFLite model.

get_stats_tflite(→ tuple[str, dict[str, Any]])

tabulate_stats(statistics)

Converts raw statistics into list of dictionaries.

pocketpose.utils.download_file(url, save_path, google_drive=False)#

Download a file from the specified URL.

Args:

url (str): The URL to download the file from. save_path (str): The path of the file to save the downloaded file to. google_drive (bool): Whether the file is hosted on Google Drive. If True,

the url must be a Google Drive sharing link and the file will be downloaded using the gdown package. Defaults to False.

Returns:

True if the file was downloaded successfully, False otherwise.

pocketpose.utils.write_to_table(data, save_path, tablefmt=None)#

Save the data as a table in the specified format.

Args:

data (list of dict): The data to be saved as key-value pairs. save_path (str): The path of the file to save the data to. tablefmt (str): The format of the table. If None, the format is

determined from the extension of the save path.

class pocketpose.utils.Registry(name)#

A registry to map names to classes.

This is a generic registry that can be used to register any class, e.g. skeletons, datasets, models, etc. It is used by different modules to register their classes.

Args:

name (str): The name of the registry.

Attributes:

name (str): The name of the registry. _registry (dict): The dictionary mapping names to classes.

Example:
>>> model_registry = Registry("model")
>>> @model_registry.register("movenet")
register(name)#

Register a class using the name.

Args:

name (str): The name of the class.

get(name)#

Get the class corresponding to the name.

Args:

name (str): The name of the class.

Returns:

The corresponding class.

Raises:

ValueError: If the name is not registered in the registry.

list()#

List all the registered names.

pocketpose.utils.build_from_cfg(cfg, registry, default_args=None)#

Build a class from the config.

Args:

cfg (dict): The config. registry (Registry): The registry to look up the class. default_args (dict): The default arguments to the class.

Returns:

The built class.

pocketpose.utils.estimate_flops_tflite(model_path: str) float#

Estimates the number of floating point operations in a TFLite model.

Note: This is a rough estimate which only considers CONV_2D, DEPTHWISE_CONV_2D, FULLY_CONNECTED, ADD, and MUL operators.

For FULLY_CONNECTED layer, we assume that the number of FLOPs is approximately 2 times the number of elements in the weight matrix, which assumes that each weight participates in one multiplication and one addition.

For ADD and MUL layers, we assume that each operation is performed element-wise, and so the number of FLOPs is equal to the total number of elements in the input tensor.

Args:

model_path (str): Path to TFLite model

Returns:

float: Number of estimated GFLOPs in the model

pocketpose.utils.estimate_parameters_tflite(model_path: str) int#

Estimates the number of parameters in a TFLite model.

Args:

model_path (str): Path to TFLite model

Returns:

int: Number of parameters in the model

pocketpose.utils.get_stats_tflite(model_path: str) tuple[str, dict[str, Any]]#
pocketpose.utils.tabulate_stats(statistics)#

Converts raw statistics into list of dictionaries.

Args:

statistics (dict): The raw statistics.

Returns:
list of dict: The statistics in a tabular format. These can be

directly written to a table using the tabulate package or the write_to_table function in io module.