#                🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
#           This file was automatically generated from src/transformers/models/pp_ocrv5_mobile_det/modular_pp_ocrv5_mobile_det.py.
#               Do NOT edit this file manually as any edits will be overwritten by the generation of
#             the file from the modular. If any change should be done, please apply the change to the
#                          modular_pp_ocrv5_mobile_det.py file directly. One of our CI enforces this.
#                🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
# Copyright 2026 The PaddlePaddle Team and The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from huggingface_hub.dataclasses import strict

from ...backbone_utils import consolidate_backbone_kwargs_to_config
from ...configuration_utils import PreTrainedConfig
from ...utils import auto_docstring
from ..auto import AutoConfig


@auto_docstring(checkpoint="PaddlePaddle/PP-OCRv5_mobile_det_safetensors")
@strict
class PPOCRV5MobileDetConfig(PreTrainedConfig):
    r"""
    reduction (`int`, *optional*, defaults to 4):
        The reduction factor for feature channel dimensions, used to reduce the number of model parameters and
        computational complexity while maintaining feature representability.
    neck_out_channels (`int`, *optional*, defaults to 96):
        The number of output channels from the neck network, which is responsible for feature fusion and
        refinement before passing features to the head network.
    interpolate_mode (`str`, *optional*, defaults to `"nearest"`):
        The interpolation mode used for upsampling or downsampling feature maps in the neck network. Supported
        modes include `"nearest"` (nearest neighbor interpolation) and `"bilinear"`.
    kernel_list (`List[int]`, *optional*, defaults to `[3, 2, 2]`):
        The list of kernel sizes for convolutional layers in the head network, used for multi-scale feature
        extraction to detect text regions of different sizes.
    layer_list_out_channels (`List[int]`, *optional*, defaults to `[12, 18, 42, 360]`):
        The list of output channels for each backbone stage, used to configure the input channels of the RSE layers
        in the neck network for multi-scale feature fusion.
    """

    model_type = "pp_ocrv5_mobile_det"
    sub_configs = {"backbone_config": AutoConfig}

    backbone_config: dict | PreTrainedConfig | None = None
    reduction: int = 4
    neck_out_channels: int = 96
    interpolate_mode: str = "nearest"
    kernel_list: list[int] | tuple[int, ...] = (3, 2, 2)
    layer_list_out_channels: list[int] | tuple[int, ...] = (12, 18, 42, 360)

    def __post_init__(self, **kwargs):
        self.backbone_config, kwargs = consolidate_backbone_kwargs_to_config(
            backbone_config=self.backbone_config,
            default_config_type="pp_lcnet_v3",
            default_config_kwargs={
                "scale": 0.75,
                "out_features": ["stage2", "stage3", "stage4", "stage5"],
                "out_indices": [2, 3, 4, 5],
                "divisor": 16,
            },
            **kwargs,
        )

        # For object detection pipeline compatibility: single class "text"
        self.id2label = {0: "text"} if self.id2label is None else self.id2label
        super().__post_init__(**kwargs)


__all__ = ["PPOCRV5MobileDetConfig"]
