Skip to content

Training Plate Config

This is the training-time PlateConfig schema validated with Pydantic. It defines plate alphabet, image dimensions, preprocessing options, and region metadata used during training and export.

License Plate OCR config. This config file defines how license plate images and text should be preprocessed for OCR model training and inference.

PlateConfig

Bases: BaseModel

Model License Plate config.

max_plate_slots instance-attribute

max_plate_slots: PositiveInt

Max number of plate slots supported. This represents the number of model classification heads.

alphabet instance-attribute

alphabet: str

All the possible character set for the model output.

pad_char instance-attribute

pad_char: Annotated[
    str, StringConstraints(min_length=1, max_length=1)
]

Padding character for plates which length is smaller than MAX_PLATE_SLOTS.

img_height instance-attribute

img_height: PositiveInt

Image height which is fed to the model.

img_width instance-attribute

img_width: PositiveInt

Image width which is fed to the model.

keep_aspect_ratio class-attribute instance-attribute

keep_aspect_ratio: bool = False

Keep aspect ratio of the input image.

interpolation class-attribute instance-attribute

interpolation: ImageInterpolation = 'linear'

Interpolation method used for resizing the input image.

image_color_mode class-attribute instance-attribute

image_color_mode: ImageColorMode = 'grayscale'

Input image color mode. Use 'grayscale' for single-channel input or 'rgb' for 3-channel input.

padding_color class-attribute instance-attribute

padding_color: tuple[UInt8, UInt8, UInt8] | UInt8 = (
    114,
    114,
    114,
)

Padding color used when keep_aspect_ratio is True. For grayscale images, this should be a single integer and for RGB images, this must be a tuple of three integers.

plate_regions class-attribute instance-attribute

plate_regions: list[str] | None = None

Optional list specifying the regions/countries whose license plates the model can recognize.

load_plate_config_from_yaml

load_plate_config_from_yaml(
    yaml_path: PathLike,
) -> PlateConfig

Reads and parses a YAML file containing the plate configuration.

Parameters:

Name Type Description Default
yaml_path PathLike

Path to the YAML file containing the plate config.

required

Returns:

Name Type Description
PlateConfig PlateConfig

Parsed and validated plate configuration.

Raises:

Type Description
FileNotFoundError

If the YAML file does not exist.

Source code in fast_plate_ocr/train/model/config.py
def load_plate_config_from_yaml(yaml_path: PathLike) -> PlateConfig:
    """
    Reads and parses a YAML file containing the plate configuration.

    Args:
        yaml_path: Path to the YAML file containing the plate config.

    Returns:
        PlateConfig: Parsed and validated plate configuration.

    Raises:
        FileNotFoundError: If the YAML file does not exist.
    """
    if not Path(yaml_path).is_file():
        raise FileNotFoundError(f"Plate config '{yaml_path}' doesn't exist.")
    with open(yaml_path, encoding="utf-8") as f_in:
        yaml_content = yaml.safe_load(f_in)
    config = PlateConfig(**yaml_content)
    return config