pandora2d.memory_estimation
This module contains methods associated to the pandora2d memory estimation
Attributes
Classes
Represents the range of rows or columns in a region of interest (ROI). |
|
Represents a 2D region of interest, defined by row and column bounds. |
Functions
|
Estimate the total memory consumption of all objects that will be allocated. |
|
Compute the effective image size (height, width), including ROI and global margins. |
|
Get width and height from an image path. |
|
Get number of disparities. |
|
Get ROI margins according to row and col disparities and global margins calculated in the check conf step. |
|
Return image dataset size (MB) according to width, height and sum of the number of bytes corresponding |
|
Estimate input configuration size (MB) according to image width, height |
|
Estimate 4D cost volumes size (MB) according to image width, height, |
|
Estimate the size in MB of the list of shifted right images (excluding the original right image itself). |
|
Estimate the size in MB of the cost volume according to image width, height, and refinement margins. |
|
Estimate the size in MB of the disparity map dataset. |
|
Split an image into multiple horizontal ROI segments that fit within memory constraints. |
Module Contents
- pandora2d.memory_estimation.IMG_DATA_VAR = ['im', 'row_disparity_min', 'row_disparity_max', 'col_disparity_min', 'col_disparity_max'][source]
- pandora2d.memory_estimation.IMG_DATA_VAR_MASK = ['im', 'row_disparity_min', 'row_disparity_max', 'col_disparity_min', 'col_disparity_max', 'msk'][source]
- pandora2d.memory_estimation.estimate_total_consumption(config: dict, height: int, width: int, margin_disp: pandora2d.margins.Margins = NullMargins()) float[source]
Estimate the total memory consumption of all objects that will be allocated. :param config: configuration with ROI margins if necessary. :param height: Image height including any ROI adjustments. :param width: Image width including any ROI adjustments. :param margin_disp: Disparity margins. :return: Memory consumption estimate in megabytes.
- pandora2d.memory_estimation.compute_effective_image_size(config: dict, image_margins: pandora2d.margins.Margins) tuple[int, int][source]
Compute the effective image size (height, width), including ROI and global margins.
- Parameters:
config – Configuration dictionary containing the image path and optional ROI information.
image_margins – Margins to apply around the ROI to ensure the full region is processed. Used only when a ROI is defined. Defaults to None.
- Returns:
Image dimensions as (height, width) including margins.
- pandora2d.memory_estimation.get_img_size(img_path: str, roi: dict = None) tuple[int, int][source]
Get width and height from an image path. If a ROI is given, its width and height are returned without taking margins into account.
- Parameters:
img_path – img path
- Returns:
width and height of the image
- pandora2d.memory_estimation.get_nb_disp(disparity: dict, before_margins: int = 0, after_margins: int = 0, subpix: int = 1, roi: dict | None = None, from_previous_run: bool = False) int[source]
Get number of disparities.
- Parameters:
disparity – init and range for disparities.
before_margins – Margins before the minimum disparity.
after_margins – Margins after the maximum disparity.
subpix – subpix
roi – optional ROI dict with keys “row” and “col”, each containing “first” and “last”.
from_previous_run – True when disparity grids come from a previous Pandora2D run.
- Returns:
number of disparities
- pandora2d.memory_estimation.get_roi_margins(row_disparity: dict, col_disparity: dict, global_margins: pandora2d.margins.Margins, roi: dict | None = None, from_previous_run: bool = False) pandora2d.margins.Margins[source]
Get ROI margins according to row and col disparities and global margins calculated in the check conf step.
- Parameters:
row_disparity – init and range for disparities in rows.
col_disparity – init and range for disparities in columns.
global_margins – global image margins computed in the check conf
roi – optional ROI dict with keys “row” and “col”, each containing “first” and “last”.
from_previous_run – True when initial disparity grids come from a previous Pandora2D run.
- Returns:
ROI margins updated according to disparity values
- pandora2d.memory_estimation.img_dataset_size(height: int, width: int, nb_bytes: int) float[source]
Return image dataset size (MB) according to width, height and sum of the number of bytes corresponding to the different data types contained in the image dataset.
- Parameters:
height – image or ROI number of rows
width – image or ROI number of columns
nb_bytes – sum of the number of bytes.
- Returns:
size of image dataset in MB
- pandora2d.memory_estimation.estimate_input_size(height: int, width: int, data_vars: list[str]) float[source]
Estimate input configuration size (MB) according to image width, height and data variables contained in the image dataset.
- Parameters:
height – image or ROI number of rows
width – image or ROI number of columns
data_vars – data variables contained in the image dataset.
- Returns:
size of image dataset in MB
- pandora2d.memory_estimation.estimate_cost_volumes_size(user_cfg: dict, height: int, width: int, margins_disp: pandora2d.margins.Margins, data_vars: list[str]) float[source]
Estimate 4D cost volumes size (MB) according to image width, height, number of disparities, subpix, step and data variables contained in the cost volumes dataset.
- Parameters:
user_cfg – user configuration
height – image or ROI number of rows
width – image or ROI number of columns
margins_disp – disparity margins computed in the check conf
data_vars – data variables contained in the cost_volumes dataset.
- Returns:
size of image dataset in MB
- pandora2d.memory_estimation.estimate_shifted_right_images_size(height: int, width: int, subpix: int) float[source]
Estimate the size in MB of the list of shifted right images (excluding the original right image itself).
- Parameters:
height – height of image
width – width of image
subpix – subpixel
- Returns:
estimated size in MB
- pandora2d.memory_estimation.estimate_pandora_cost_volume_size(config: dict, height: int, width: int, margins: pandora2d.margins.Margins) float[source]
Estimate the size in MB of the cost volume according to image width, height, and refinement margins.
- Parameters:
config – user configuration.
height – image or ROI number of rows
width – image or ROI number of columns
margins – Refinement margins.
- Returns:
estimated size in MB.
- pandora2d.memory_estimation.estimate_dataset_disp_map_size(height: int, width: int, step: list, dtype: numpy.typing.DTypeLike, cost_volume_confidence_step: bool) float[source]
Estimate the size in MB of the disparity map dataset.
- Parameters:
height – image or ROI number of rows.
width – image or ROI number of columns.
step – step.
dtype – dtype of the disparity map (should be same as cost volumes dataset).
cost_volume_confidence_step – whether to include the cost volume confidence step.
- Returns:
estimated size in MB.
- class pandora2d.memory_estimation.RoiRange[source]
Bases:
TypedDictRepresents the range of rows or columns in a region of interest (ROI).
- Parameters:
first – Index of the first row or column.
last – Index of the last row or column (inclusive).
- class pandora2d.memory_estimation.Roi[source]
Bases:
TypedDictRepresents a 2D region of interest, defined by row and column bounds.
- Parameters:
row – Row range of the ROI.
col – Column range of the ROI.
- pandora2d.memory_estimation.segment_image_by_rows(config: dict, disp_margins: pandora2d.margins.Margins, image_margins: pandora2d.margins.Margins) list[Roi][source]
Split an image into multiple horizontal ROI segments that fit within memory constraints.
This function estimates the memory required to process the full image with the provided disparity margins. If the memory requirement exceeds the configured memory_per_work, the image is split into horizontal segments whose individual memory usage remains within the allowed limit.
- Parameters:
config – Configuration dictionary containing keys such as ‘segment_mode’ and ‘pipeline’.
disp_margins – Margins applied during disparity computation. Defaults to NullMargins.
image_margins – Margins applied to image.
- Returns:
List of segment dictionaries with row and column bounds.
- Raises:
ValueError – If the minimum memory required for processing a basic segment exceeds the configured memory_per_work.