Skip to content

API Reference

Dataset Loader

src.dataset_loader

This module is responsible for searching and listing all relevant files(images/videos) in a given dataset directory. In will be used as the first step in order to create a demopgraphic analysis.

Loader

ARCHIVE_EXTENSIONS = ('.tar.gz', '.tar.bz2', '.tar.xz', '.tgz', '.zip', '.tar') class-attribute instance-attribute

This class' functions can be used to manipulate the dataset.

__init__(dataset)

:param dataset: Path to the dataset directory.

find_images()

This function finds the images in a given path. :return: List of image file paths.

find_videos()

This function finds the videos in a given path. ::return: List of videos file paths.

is_archive(file_path) classmethod

Return True if file_path matches a supported archive extension.

Demographic Estimator

src.demographic_estimator

This module is responsible for estimating age, gender, and race using DeepFace. It acts as a wrapper for the deep learning model.

analyze_image(image_path, detector_backend='retinaface', min_confidence=0.9)

This function takes an image path and returns a LIST of demographic info for all faces found. :param image_path: Path to the image file. :return: List of dictionaries with demographic information for each face.

analyze_video(video_path, skip_frames=1, detector_backend='retinaface', min_confidence=0.9)

This function takes a video path and analyzes frames periodically. :param video_path: Path to the video file. :param skip_frames: Analyze every n-th frame. Use 1 to analyze all frames. :return: List of dictionaries with demographic information for each face found.

Data Writing

src.data_writing

This module is used to write out the results.

write_csv(file_path, data)

Write data to a CSV file.

:param file_path: Path to the output CSV file. :param data: List of dictionaries containing the data to write.

Visualization

src.visualization

This module is responsible for visualizing the demographic data using Bokeh. It generates an interactive HTML dashboard directly from memory.

Visualizer

__init__(data_list, output_dir)

:param data_list: List of dictionaries containing demographic data. :param output_dir: Directory where the dashboard.html will be saved.

plot_charts()

This function creates an HTML dashboard.

Logger

src.logger

This module handles the logging configuration for the application. It logs messages to both the console and a file named 'application.log'.

setup_logger(name=__name__)

Sets up a logger that writes to console and a log file.

:param name: Name of the logger instance. :return: Configured logger object.