Config Module¶
This module defines the configuration classes and utilities for the semantic segmentation pipeline.
It includes classes for input type enumeration, model configuration, visualization configuration, and the main configuration class that encapsulates all settings for the segmentation process.
InputType
¶
Bases: Enum
Enumeration of supported input types for the segmentation pipeline.
ModelConfig
¶
ModelConfig(
name,
model_type=None,
max_size=None,
device=None,
dataset=None,
num_workers=8,
pipe_batch=1,
)
Configuration class for the segmentation model.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
The name or path of the pre-trained model to use.
TYPE:
|
model_type |
The type of the model (e.g., 'oneformer', 'mask2former').
TYPE:
|
max_size |
The maximum size for input image resizing.
TYPE:
|
device |
The device to use for processing (e.g., 'cpu', 'cuda').
TYPE:
|
__post_init__
¶
Post-initialization method to set up the model type if not provided.
Source code in cityseg/config.py
auto_detect_model_type
¶
Automatically detect the model type from the model name if not provided.
Source code in cityseg/config.py
VisualizationConfig
¶
Configuration class for visualization settings.
| ATTRIBUTE | DESCRIPTION |
|---|---|
alpha |
The alpha value for blending the segmentation mask with the original image.
TYPE:
|
colormap |
The colormap to use for visualizing the segmentation mask.
TYPE:
|
Config
¶
Config(
input,
output_dir,
output_prefix,
model,
ignore_files=None,
frame_step=1,
batch_size=16,
output_fps=None,
save_raw_segmentation=True,
save_colored_segmentation=False,
save_overlay=True,
analyze_results=True,
visualization=VisualizationConfig(),
force_reprocess=False,
disable_tqdm=False,
)
Main configuration class for the segmentation pipeline.
This class encapsulates all settings required for the segmentation process, including input/output paths, model configuration, processing parameters, and visualization settings.
| ATTRIBUTE | DESCRIPTION |
|---|---|
input |
The input path (file or directory) for processing.
TYPE:
|
output_dir |
The output directory for saving results.
TYPE:
|
output_prefix |
The prefix for output file names.
TYPE:
|
model |
The model configuration.
TYPE:
|
frame_step |
The frame step for video processing.
TYPE:
|
batch_size |
The batch size for processing.
TYPE:
|
output_fps |
The output FPS for processed videos.
TYPE:
|
save_raw_segmentation |
Whether to save raw segmentation maps.
TYPE:
|
save_colored_segmentation |
Whether to save colored segmentation maps.
TYPE:
|
save_overlay |
Whether to save overlay visualizations.
TYPE:
|
visualization |
The visualization configuration.
TYPE:
|
input_type |
The type of input (automatically determined).
TYPE:
|
force_reprocess |
Whether to force reprocessing of existing results.
TYPE:
|
disable_tqdm |
Whether to disable the progress bar display.
TYPE:
|
__post_init__
¶
Post-initialization method to set up the input path and determine the input type.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the input path does not exist. |
Source code in cityseg/config.py
generate_output_prefix
¶
Generate an output prefix based on the input file name and model configuration.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The generated output prefix.
TYPE:
|
Source code in cityseg/config.py
get_output_path
¶
Get the full output path based on the configuration.
This method determines the appropriate output directory and file name based on the input type and configuration settings.
| RETURNS | DESCRIPTION |
|---|---|
Path
|
The full output path.
TYPE:
|
Source code in cityseg/config.py
from_yaml
¶
Create a Config instance from a YAML file.
| PARAMETER | DESCRIPTION |
|---|---|
config_path |
Path to the YAML configuration file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Config
|
An instance of the Config class.
TYPE:
|
Source code in cityseg/config.py
to_dict
¶
Convert the Config instance to a dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary representation of the Config instance. |
Source code in cityseg/config.py
ConfigHasher
¶
A utility class for generating hashes of relevant configuration settings.
get_relevant_config
¶
Extract the relevant configuration settings for hashing.
This method filters out configuration settings that don't affect the analysis results or output format, focusing only on settings that would require reprocessing if changed.
| PARAMETER | DESCRIPTION |
|---|---|
config |
The full configuration object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary of relevant configuration settings. |
Source code in cityseg/config.py
calculate_hash
¶
Calculate a hash of the relevant configuration settings.
This method creates a deterministic hash of the configuration settings that affect the analysis results or output format.
| PARAMETER | DESCRIPTION |
|---|---|
config |
The full configuration object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
A hexadecimal string representing the hash of the relevant config.
TYPE:
|