Pipeline Module¶
This module provides a custom segmentation pipeline for image and video processing.
It extends the functionality of the Hugging Face Transformers library's ImageSegmentationPipeline to support various segmentation models and create detailed segmentation maps with associated metadata.
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
SegmentationPipeline
¶
Bases: ImageSegmentationPipeline
A custom segmentation pipeline that extends ImageSegmentationPipeline.
This class provides additional functionality for creating and processing segmentation maps, including support for different color palettes and batch processing of images.
| ATTRIBUTE | DESCRIPTION |
|---|---|
palette |
The color palette used for visualization.
TYPE:
|
Source code in cityseg/pipeline.py
create_single_segmentation_map
¶
Create a single segmentation map from annotations.
| PARAMETER | DESCRIPTION |
|---|---|
annotations |
List of annotation dictionaries.
TYPE:
|
target_size |
The target size of the segmentation map.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the segmentation map and associated metadata. |
Source code in cityseg/pipeline.py
__call__
¶
Process the input image(s) and create segmentation map(s).
| PARAMETER | DESCRIPTION |
|---|---|
images |
The input image(s) to process.
TYPE:
|
**kwargs |
Additional keyword arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing segmentation maps and metadata. |
Source code in cityseg/pipeline.py
create_segmentation_pipeline
¶
Create and return a SegmentationPipeline instance based on the specified model.
This function initializes the appropriate model and image processor based on the model name, and creates a SegmentationPipeline instance with these components.
| PARAMETER | DESCRIPTION |
|---|---|
config |
TYPE:
|
**kwargs |
Additional keyword arguments to pass to the SegmentationPipeline constructor.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SegmentationPipeline
|
An instance of the SegmentationPipeline class.
TYPE:
|
Source code in cityseg/pipeline.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |