Skip to content

Plate Config

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

PlateOCRConfig

Bases: BaseModel

Model License Plate OCR 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.

load_plate_config_from_yaml

load_plate_config_from_yaml(
    yaml_path: PathLike,
) -> PlateOCRConfig

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
PlateOCRConfig PlateOCRConfig

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) -> PlateOCRConfig:
    """
    Reads and parses a YAML file containing the plate configuration.

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

    Returns:
        PlateOCRConfig: 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 = PlateOCRConfig(**yaml_content)
    return config