
    jb&                     x   U d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 ddlmZ g d	Zd
dd ee
d                   ddd
dd ee
d                   ddd
dd ee
d                   ddd
dd ee
d                   ddd
ddg dddd
ddg ddddZeeeeef         f         ed<   	 	 d(dededee         dz  dee         dz  dedej        fd Zd)dededej        fd"Zd)dededej        fd#Zd)dededej        fd$Zd)dededej        fd%Zd)dededej        fd&Zd)dededej        fd'ZdS )*    N)deepcopy)Any)mobilenetv3)MobileNetV3)VOCABS   load_pretrained_params)r   mobilenet_v3_smallmobilenet_v3_small_rmobilenet_v3_largemobilenet_v3_large_r#mobilenet_v3_small_crop_orientation#mobilenet_v3_small_page_orientation)gh|?5?g=
ףp=?gV-?)gA`"?gl?g$C?)r       r   frenchzUhttps://doctr-static.mindee.com/models?id=v0.4.1/mobilenet_v3_large-11fc8cb9.pt&src=0)meanstdinput_shapeclassesurlzWhttps://doctr-static.mindee.com/models?id=v0.4.1/mobilenet_v3_large_r-74a22066.pt&src=0zUhttps://doctr-static.mindee.com/models?id=v0.4.1/mobilenet_v3_small-6a4bfa6b.pt&src=0zWhttps://doctr-static.mindee.com/models?id=v0.4.1/mobilenet_v3_small_r-1a8a3530.pt&src=0)r      r   )r   i   Z   zfhttps://doctr-static.mindee.com/models?id=v0.8.1/mobilenet_v3_small_crop_orientation-f0847a18.pt&src=0)r      r   zfhttps://doctr-static.mindee.com/models?id=v0.8.1/mobilenet_v3_small_page_orientation-8e60325c.pt&src=0)r   r   r   r   r   r   default_cfgsarch
pretrainedrect_stridesignore_keyskwargsreturnc                    |                     dt          t          |          d                             |d<   |                     dt          |          d                   |d<   t          t          |                    }|d         |d<   |d         |d<   |                    d           |                     d          rt          j        di |dd i}nt          j        di |dd i}t          |t                    r6|D ]3}|}|                    d          D ]}	t          ||	          }d|_        4dt          dt          d	d fd
}
t!          j        |
|          |_        |rV|d         t          t          |          d                   k    r|nd }|                    t          |          d         |           ||_        |S )Nnum_classesr   r   weights.)      path_or_urlr!   r"   c                 "    t          | |fi | dS )zLoad pretrained parameters onto the model

        Args:
            path_or_url: the path or URL to the model parameters (checkpoint)
            **kwargs: additional arguments to be passed to `doctr.models.utils.load_pretrained_params`
        Nr	   )selfr)   r!   s      p/var/www/html/Carbon-Document/venv/lib/python3.11/site-packages/doctr/models/classification/mobilenet/pytorch.pyfrom_pretrainedz&_mobilenet_v3.<locals>.from_pretrainedh   s"     	t[;;F;;;;;    r   )r     )getlenr   r   pop
startswithr   r   r   
isinstancelistsplitgetattrstridestrr   types
MethodTyper-   cfg)r   r   r   r    r!   _cfgmodel
layer_namemchildr-   _ignore_keyss               r,   _mobilenet_v3rC   K   s    #JJ}c,t:LY:W6X6XYYF=

9l4.@.KLLF9L&''D /DY'DO
JJy+,, G.FFFFFFF.FFFFFFF ,%% & 	 	JA#))#.. & &Au%%AHH<3 <# <$ < < < < ",_eDDE  S '-]&;s<PTCUV_C`?a?a&a&a{{gkl407\RRREILr.   Fc                 &    t          d| fdddgi|S )a  MobileNetV3-Small architecture as described in
    `"Searching for MobileNetV3",
    <https://arxiv.org/pdf/1905.02244.pdf>`_.

    >>> import torch
    >>> from doctr.models import mobilenet_v3_small
    >>> model = mobilenetv3_small(pretrained=False)
    >>> input_tensor = torch.rand((1, 3, 512, 512), dtype=torch.float32)
    >>> out = model(input_tensor)

    Args:
        pretrained: boolean, True if model is pretrained
        **kwargs: keyword arguments of the MobileNetV3 architecture

    Returns:
        a torch.nn.Module
    r   r    classifier.3.weightclassifier.3.biasrC   r   r!   s     r,   r   r      s6    $ j 7LNa6bfl  r.   c                 ,    t          d| g dfdddgi|S )a;  MobileNetV3-Small architecture as described in
    `"Searching for MobileNetV3",
    <https://arxiv.org/pdf/1905.02244.pdf>`_, with rectangular pooling.

    >>> import torch
    >>> from doctr.models import mobilenet_v3_small_r
    >>> model = mobilenet_v3_small_r(pretrained=False)
    >>> input_tensor = torch.rand((1, 3, 512, 512), dtype=torch.float32)
    >>> out = model(input_tensor)

    Args:
        pretrained: boolean, True if model is pretrained
        **kwargs: keyword arguments of the MobileNetV3 architecture

    Returns:
        a torch.nn.Module
    r   )zfeatures.2.block.1.0features.4.block.1.0zfeatures.9.block.1.0r    rE   rF   rG   rH   s     r,   r   r      sD    $ PPP  +,?@	
   r.   c                 &    t          d| fdddgi|S )a  MobileNetV3-Large architecture as described in
    `"Searching for MobileNetV3",
    <https://arxiv.org/pdf/1905.02244.pdf>`_.

    >>> import torch
    >>> from doctr.models import mobilenet_v3_large
    >>> model = mobilenet_v3_large(pretrained=False)
    >>> input_tensor = torch.rand((1, 3, 512, 512), dtype=torch.float32)
    >>> out = model(input_tensor)

    Args:
        pretrained: boolean, True if model is pretrained
        **kwargs: keyword arguments of the MobileNetV3 architecture

    Returns:
        a torch.nn.Module
    r   r    rE   rF   rG   rH   s     r,   r   r      s;    $   +,?@ 	  r.   c                 ,    t          d| g dfdddgi|S )a;  MobileNetV3-Large architecture as described in
    `"Searching for MobileNetV3",
    <https://arxiv.org/pdf/1905.02244.pdf>`_, with rectangular pooling.

    >>> import torch
    >>> from doctr.models import mobilenet_v3_large_r
    >>> model = mobilenet_v3_large_r(pretrained=False)
    >>> input_tensor = torch.rand((1, 3, 512, 512), dtype=torch.float32)
    >>> out = model(input_tensor)

    Args:
        pretrained: boolean, True if model is pretrained
        **kwargs: keyword arguments of the MobileNetV3 architecture

    Returns:
        a torch.nn.Module
    r   )rJ   zfeatures.7.block.1.0zfeatures.13.block.1.0r    rE   rF   rG   rH   s     r,   r   r      sD    $ QQQ  +,?@	
   r.   c                 &    t          d| fdddgi|S )a?  MobileNetV3-Small architecture as described in
    `"Searching for MobileNetV3",
    <https://arxiv.org/pdf/1905.02244.pdf>`_.

    >>> import torch
    >>> from doctr.models import mobilenet_v3_small_crop_orientation
    >>> model = mobilenet_v3_small_crop_orientation(pretrained=False)
    >>> input_tensor = torch.rand((1, 3, 512, 512), dtype=torch.float32)
    >>> out = model(input_tensor)

    Args:
        pretrained: boolean, True if model is pretrained
        **kwargs: keyword arguments of the MobileNetV3 architecture

    Returns:
        a torch.nn.Module
    r   r    rE   rF   rG   rH   s     r,   r   r      ;    $ -  +,?@ 	  r.   c                 &    t          d| fdddgi|S )a?  MobileNetV3-Small architecture as described in
    `"Searching for MobileNetV3",
    <https://arxiv.org/pdf/1905.02244.pdf>`_.

    >>> import torch
    >>> from doctr.models import mobilenet_v3_small_page_orientation
    >>> model = mobilenet_v3_small_page_orientation(pretrained=False)
    >>> input_tensor = torch.rand((1, 3, 512, 512), dtype=torch.float32)
    >>> out = model(input_tensor)

    Args:
        pretrained: boolean, True if model is pretrained
        **kwargs: keyword arguments of the MobileNetV3 architecture

    Returns:
        a torch.nn.Module
    r   r    rE   rF   rG   rH   s     r,   r   r     rN   r.   )NN)F)r:   copyr   typingr   torchvision.modelsr   torchvision.models.mobilenetv3r   doctr.datasetsr   utilsr
   __all__r5   r   dictr9   __annotations__boolrC   r   r   r   r   r   r   r/   r.   r,   <module>rZ      sK                * * * * * * 6 6 6 6 6 6 ! ! ! ! ! ! + + + + + +   &$"4x())f  &$"4x())h  &$"4x())f  &$"4x())h  &$$$$$w, , &$$$$$w, ,I++ ++d3S#X&' + + +b &*$(	2 2
22 s)d"2 cT!	2
 2 2 2 2 2j 4 3 ;CZ    . T S [E\    6 4 3 ;CZ    4 T S [E\    6 D C T_Tk    4 D C T_Tk      r.   