
    9im                     <   S SK JrJr  S SKrS SKrS SKrS SKJr  S SK	Js  J
r  S SKJr  S SKJrJrJr   " S S\R$                  5      r     SS jr " S S	\R$                  5      r " S
 S\5      r " S S\\S9r " S S\5      r " S S\R$                  5      rg)    )ABCMetaabstractmethodN)
ConvModule)
BaseModule	auto_fp16
force_fp32c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )LinearClassifier   c                 `   > [         [        U ]  5         [        R                  " X5      U l        g N)superr
   __init__nnLinear
classifier)selfin_channelsnum_classes	__class__s      k/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/models/cv/vision_middleware/head.pyr   LinearClassifier.__init__   s!    .0))K=    c                 *    U R                  US   5      $ )Nr   )r   xs     r   forwardLinearClassifier.forward   s    qu%%r   r   __name__
__module____qualname____firstlineno__r   r   __static_attributes____classcell__r   s   @r   r
   r
      s    >& &r   r
   c                 2    [         R                  " XX#U5      $ r   )Finterpolate)inputsizescale_factormodealign_cornerswarnings         r   resizer1      s     ==l-HHr   c                   :   ^  \ rS rSr    SU 4S jjrS rSrU =r$ )Upsample%   c                    > [         [        U ]  5         Xl        [	        U[
        5      (       a  [        S U 5       5      U l        OU(       a  [        U5      OS U l        X0l        X@l	        g )Nc              3   8   #    U  H  n[        U5      v   M     g 7fr   )float).0factors     r   	<genexpr>$Upsample.__init__.<locals>.<genexpr>/   s     %O,eFmm,s   )
r   r3   r   r,   
isinstancetupler-   r7   r.   r/   )r   r,   r-   r.   r/   r   s        r   r   Upsample.__init__'   sS    
 	h&(	lE** %%O,%O OD7Cl 3D	*r   c                     U R                   (       d5  UR                  SS   Vs/ s H  n[        X R                  -  5      PM     nnOU R                   n[	        XS U R
                  U R                  5      $ s  snf )N)r,   shapeintr-   r1   r.   r/   )r   r   tr,   s       r   r   Upsample.forward5   sa    yy89E1C---.DED99DatTYY0B0BCC Fs   !A5)r/   r.   r-   r,   )NNnearestNr    r'   s   @r   r3   r3   %   s"     "#	+D Dr   r3   c                   t   ^  \ rS rSrSrSSSSSSSSS\" SS9\" S	S
SS94U 4S jjr\" 5       S 5       rSr	U =r
$ )FPN=   aJ
  Feature Pyramid Network.
This neck is the implementation of `Feature Pyramid Networks for Object
Detection <https://arxiv.org/abs/1612.03144>`_.
Args:
    in_channels (list[int]): Number of input channels per scale.
    out_channels (int): Number of output channels (used at each scale).
    num_outs (int): Number of output scales.
    start_level (int): Index of the start input backbone level used to
        build the feature pyramid. Default: 0.
    end_level (int): Index of the end input backbone level (exclusive) to
        build the feature pyramid. Default: -1, which means the last level.
    add_extra_convs (bool | str): If bool, it decides whether to add conv
        layers on top of the original feature maps. Default to False.
        If True, its actual mode is specified by `extra_convs_on_inputs`.
        If str, it specifies the source feature map of the extra convs.
        Only the following options are allowed
        - 'on_input': Last feat map of neck inputs (i.e. backbone feature).
        - 'on_lateral': Last feature map after lateral convs.
        - 'on_output': The last output feature map after fpn convs.
    extra_convs_on_inputs (bool, deprecated): Whether to apply extra convs
        on the original feature from the backbone. If True,
        it is equivalent to `add_extra_convs='on_input'`. If False, it is
        equivalent to set `add_extra_convs='on_output'`. Default to True.
    relu_before_extra_convs (bool): Whether to apply relu before the extra
        conv. Default: False.
    no_norm_on_lateral (bool): Whether to apply norm on lateral.
        Default: False.
    conv_cfg (dict): Config dict for convolution layer. Default: None.
    norm_cfg (dict): Config dict for normalization layer. Default: None.
    act_cfg (dict): Config dict for activation layer in ConvModule.
        Default: None.
    upsample_cfg (dict): Config dict for interpolate layer.
        Default: dict(mode='nearest').
    init_cfg (dict or list[dict], optional): Initialization config dict.
Example:
    >>> import torch
    >>> in_channels = [2, 3, 5, 7]
    >>> scales = [340, 170, 84, 43]
    >>> inputs = [torch.rand(1, c, s, s)
    ...           for c, s in zip(in_channels, scales)]
    >>> self = FPN(in_channels, 11, len(in_channels)).eval()
    >>> outputs = self.forward(inputs)
    >>> for i in range(len(outputs)):
    ...     print(f'outputs[{i}].shape = {outputs[i].shape}')
    outputs[0].shape = torch.Size([1, 11, 340, 340])
    outputs[1].shape = torch.Size([1, 11, 170, 170])
    outputs[2].shape = torch.Size([1, 11, 84, 84])
    outputs[3].shape = torch.Size([1, 11, 43, 43])
r   r   FNrE   )r.   XavierConv2duniform)typelayerdistributionc                 4  > [         [        U ]  U5        [        U[        5      (       d   eXl        X l        [        U5      U l        X0l	        Xl
        Xl        SU l        UR                  5       U l        US:X  a&  U R                  U l        X0R                  U-
  :  d   eO!XPl        U[        U5      ::  d   eX5U-
  :X  d   eX@l        XPl        X`l        [        U[&        [(        45      (       d   e[        U[&        5      (       a	  US;   d   eOU(       a  U(       a  SU l        OSU l        [*        R,                  " 5       U l        [*        R,                  " 5       U l        [3        U R                   U R                  5       Hm  n[5        X   USU
U R                  (       d  UOS USS9n[5        UUSSU
UUSS	9nU R.                  R7                  U5        U R0                  R7                  U5        Mo     X0R                  -
  U R                   -   nU R$                  (       a{  US:  at  [3        U5       Hd  nUS
:X  a-  U R$                  S:X  a  U R
                  U R                  S-
     nOUn[5        UUSSSU
UUSS9	nU R0                  R7                  U5        Mf     g g g )NFr   )on_input
on_lateral	on_outputrP   rR      )conv_cfgnorm_cfgact_cfginplace   )paddingrT   rU   rV   rW   r      )striderY   rT   rU   rV   rW   )r   rG   r   r<   listr   out_channelslennum_insnum_outsrelu_before_extra_convsno_norm_on_lateralfp16_enabledcopyupsample_cfgbackbone_end_levelstart_level	end_leveladd_extra_convsstrboolr   
ModuleListlateral_convs	fpn_convsranger   append)r   r   r]   r`   rg   rh   ri   extra_convs_on_inputsra   rb   rT   rU   rV   re   init_cfgil_convfpn_convextra_levelsextra_fpn_convr   s                       r   r   FPN.__init__p   sx     	c4!(++t,,,,&(;' '>$"4!(--/?&*llD#||k9999 '0#K 0000;6666&"./C;7777os++"&MMMM$ (2$'2$]]_t'')@)@AA!)-)@)@dF "!!H %%f-NN!!(+) B.  "9"99D<L<LLLA$5<(6d22j@"&"2"243J3JQ3N"OK".K!+ %%#!	"# %%n5 ) %6r   c           	      z   [        U5      [        U R                  5      :X  d   e[        U R                  5       VVs/ s H  u  p#U" XU R                  -      5      PM     nnn[        U5      n[        US-
  SS5       Hu  nSU R                  ;   a'  XBS-
     [        XB   40 U R                  D6-   XBS-
  '   M:  XBS-
     R                  SS  nXBS-
     [        XB   4SU0U R                  D6-   XBS-
  '   Mw     [        U5       Vs/ s H  o R                  U   " XB   5      PM     nnU R                  [        U5      :  Gag  U R                  (       dI  [        U R                  U-
  5       H+  nUR                  [        R                  " US   SSS95        M-     GOU R                  S:X  a  XR                  S-
     nO2U R                  S	:X  a  US   nOU R                  S
:X  a  US   nO[         eUR                  U R                  U   " U5      5        [        US-   U R                  5       Hx  nU R"                  (       a=  UR                  U R                  U   " [        R$                  " US   5      5      5        MQ  UR                  U R                  U   " US   5      5        Mz     ['        U5      $ s  snnf s  snf )NrS   r   r   r-   rZ   r,   )r[   rP   rQ   rR   )r^   r   	enumeraterm   rg   ro   re   r1   rA   rn   r`   ri   rp   r)   
max_pool2drf   NotImplementedErrorra   relur=   )	r   inputsrs   lateral_convlateralsused_backbone_levels
prev_shapeoutsextra_sources	            r   r   FPN.forward   s   6{c$"2"23333
 $-T-?-?#@
#@ D$4$4 456#@ 	 
  #8}+a/B7A !2!22"*q5/FK56#'#4#456 #6Q &!e_22126
"*q5/FK5G&05G484E4E5G #GQ 8 5::N4O
4OqNN1hk*4O 	 
 ==3t9$ ''t}}/CCDAKKT"Xq CD E '':5#)*A*AA*E#FL))\9#+B<L))[8#'8L--DNN+?@NO3a7GA33DNN1$5affT"X6F$GHDNN1$5d2h$?@	 H
 T{]
(
s   #J2 J8)ri   rf   rh   rc   rn   r   rm   rb   r_   r`   r]   ra   rg   re   )r!   r"   r#   r$   __doc__dictr   r   r   r%   r&   r'   s   @r   rG   rG   =   s[    0l !&',).$)"	2"(L]6~ [2 2r   rG   c                      ^  \ rS rSrSrSSSSS\" SS9SS\" SS	S
S9SSS	\" SS\" SS9S9S.U 4S jjrS rS rS r	\
" 5       \S 5       5       rS rS rS rSrU =r$ )BaseDecodeHeadi  a[  Base class for BaseDecodeHead.
Args:
    in_channels (int|Sequence[int]): Input channels.
    channels (int): Channels after modules, before conv_seg.
    num_classes (int): Number of classes.
    out_channels (int): Output channels of conv_seg.
    threshold (float): Threshold for binary segmentation in the case of
        `out_channels==1`. Default: None.
    dropout_ratio (float): Ratio of dropout layer. Default: 0.1.
    conv_cfg (dict|None): Config of conv layers. Default: None.
    norm_cfg (dict|None): Config of norm layers. Default: None.
    act_cfg (dict): Config of activation layers.
        Default: dict(type='ReLU')
    in_index (int|Sequence[int]): Input feature index. Default: -1
    input_transform (str|None): Transformation type of input features.
        Options: 'resize_concat', 'multiple_select', None.
        'resize_concat': Multiple feature maps will be resize to the
            same size as first one and than concat together.
            Usually used in FCN head of HRNet.
        'multiple_select': Multiple feature maps will be bundle into
            a list and passed into decode head.
        None: Only one select feature map is allowed.
        Default: None.
    loss_decode (dict | Sequence[dict]): Config of decode loss.
        The `loss_name` is property of corresponding loss function which
        could be shown in training log. If you want this loss
        item to be included into the backward graph, `loss_` must be the
        prefix of the name. Defaults to 'loss_ce'.
         e.g. dict(type='CrossEntropyLoss'),
         [dict(type='CrossEntropyLoss', loss_name='loss_ce'),
          dict(type='DiceLoss', loss_name='loss_dice')]
        Default: dict(type='CrossEntropyLoss').
    ignore_index (int | None): The label index to be ignored. When using
        masked BCE loss, ignore_index should be set to None. Default: 255.
    sampler (dict|None): The config of segmentation map sampler.
        Default: None.
    align_corners (bool): align_corners argument of F.interpolate.
        Default: False.
    init_cfg (dict or list[dict], optional): Initialization config dict.
N皙?ReLU)rL   r   CrossEntropyLossF      ?rL   use_sigmoidloss_weight   Normalg{Gz?conv_seg)name)rL   stdoverride)r]   	thresholddropout_ratiorT   rU   rV   in_indexinput_transformloss_decodeignore_indexsamplerr/   rr   c                4  > [         [        U ]  U5        U R                  XU5        X l        X`l        Xpl        Xl        Xl        Xl	        Xl
        Xl        Uc  US:X  a  [        R                  S5        UnXC:w  a  US:w  a  [        SU SU 35      eUS:X  a  Uc  Sn[        R                  S5        X0l        X@l        XPl        [$        R&                  " X R                   SS9U l        US	:  a  [$        R*                  " U5      U l        OS U l        S
U l        g )NrZ   zFor binary segmentation, we suggest using`out_channels = 1` to define the outputchannels of segmentor, and use `threshold`to convert seg_logist into a predictionapplying a thresholdrS   zout_channels should be equal to num_classes,except binary segmentation set out_channels == 1 andnum_classes == 2, but got out_channels=zand num_classes=g333333?z7threshold is not defined for binary, and defaultsto 0.3)kernel_sizer   F)r   r   r   _init_inputschannelsr   rT   rU   rV   r   r   r/   warningswarn
ValueErrorr   r]   r   r   rJ   r   	Dropout2ddropoutrc   )r   r   r   r   r]   r   r   rT   rU   rV   r   r   r   r   r   r/   rr   r   s                    r   r   BaseDecodeHead.__init__/  s   , 	nd,X6+A *   (*a 5 6
 'L&<1+<::F";-12 2 1!2IMM # $&("		(,=,=1M1<<6DLDL!r   c                 X    SU R                    SU R                   SU R                   3nU$ )zExtra repr.zinput_transform=z, ignore_index=z, align_corners=)r   r   r/   )r   ss     r   
extra_reprBaseDecodeHead.extra_reprp  s@    t334 5 --. /!//02 r   c                    Ub  US;   d   eX0l         X l        Ubr  [        U[        [        45      (       d   e[        U[        [        45      (       d   e[        U5      [        U5      :X  d   eUS:X  a  [        U5      U l        gXl        g[        U[        5      (       d   e[        U[        5      (       d   eXl        g)aM  Check and initialize input transforms.
The in_channels, in_index and input_transform must match.
Specifically, when input_transform is None, only single feature map
will be selected. So in_channels and in_index must be of type int.
When input_transform
Args:
    in_channels (int|Sequence[int]): Input channels.
    in_index (int|Sequence[int]): Input feature index.
    input_transform (str|None): Transformation type of input features.
        Options: 'resize_concat', 'multiple_select', None.
        'resize_concat': Multiple feature maps will be resize to the
            same size as first one and than concat together.
            Usually used in FCN head of HRNet.
        'multiple_select': Multiple feature maps will be bundle into
            a list and passed into decode head.
        None: Only one select feature map is allowed.
N)resize_concatmultiple_selectr   )	r   r   r<   r\   r=   r^   sumr   rB   )r   r   r   r   s       r   r   BaseDecodeHead._init_inputsw  s    & &"&JJJJ. &kD%=9999hu6666{#s8}444/1#&{#3 #. k3////h,,,,*r   c           
         U R                   S:X  ak  U R                   Vs/ s H  o!U   PM	     nnU Vs/ s H)  n[        UUS   R                  SS SU R                  S9PM+     nn[
        R                  " USS9nU$ U R                   S	:X  a   U R                   Vs/ s H  o!U   PM	     nnU$ XR                     nU$ s  snf s  snf s  snf )
zTransform inputs for decoder.
Args:
    inputs (list[Tensor]): List of multi-level img features.
Returns:
    Tensor: The transformed inputs
r   r   rZ   Nbilinear)r+   r,   r.   r/   rS   dimr   )r   r   r1   rA   r/   torchcat)r   r~   rs   r   upsampled_inputss        r   _transform_inputs BaseDecodeHead._transform_inputs  s     ?2)-7AQiF7 @F 
 @F!	 ,#"&"4"4	6 @F    YY/Q7F  !!%66)-7AQiF7  MM*F 8  8s   B<0CCc                     g)z Placeholder of forward function.N )r   r~   s     r   r   BaseDecodeHead.forward  s     	r   c                 8    U " U5      nU R                  XS5      nU$ )a  Forward function for training.
Args:
    inputs (list[Tensor]): List of multi-level img features.
    img_metas (list[dict]): List of image info dict where each dict
        has: 'img_shape', 'scale_factor', 'flip', and may also contain
        'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'.
        For details on the values of these keys see
        `mmseg/datasets/pipelines/formatting.py:Collect`.
    gt_semantic_seg (Tensor): Semantic segmentation masks
        used if the architecture supports semantic segmentation task.
    train_cfg (dict): The training config.
Returns:
    dict[str, Tensor]: a dictionary of loss components
)losses)r   r~   	img_metasgt_semantic_seg	train_cfg
seg_logitsr   s          r   forward_trainBaseDecodeHead.forward_train  s      &\
Z9r   c                 $    U R                  U5      $ )a  Forward function for testing.
Args:
    inputs (list[Tensor]): List of multi-level img features.
    img_metas (list[dict]): List of image info dict where each dict
        has: 'img_shape', 'scale_factor', 'flip', and may also contain
        'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'.
        For details on the values of these keys see
        `mmseg/datasets/pipelines/formatting.py:Collect`.
    test_cfg (dict): The testing config.
Returns:
    Tensor: Output segmentation map.
)r   )r   r~   r   test_cfgs       r   forward_testBaseDecodeHead.forward_test  s     ||F##r   c                 d    U R                   b  U R                  U5      nU R                  U5      nU$ )zClassify each pixel.)r   r   )r   featoutputs      r   cls_segBaseDecodeHead.cls_seg  s-    <<#<<%Dt$r   )rV   r/   r   rT   r   r   r   rc   r   r   r   r   rU   r   r]   r   )r!   r"   r#   r$   r   r   r   r   r   r   r   r   r   r   r   r   r%   r&   r'   s   @r   r   r     s    '\ #"6*!%!,!&!$& "$"t7LN)?" ?"B"+H2 [  &$ r   r   )	metaclassc                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )FPNHeadi  a3  Panoptic Feature Pyramid Networks.
This head is the implementation of `Semantic FPN
<https://arxiv.org/abs/1901.02446>`_.
Args:
    feature_strides (tuple[int]): The strides for input feature maps.
        stack_lateral. All strides suppose to be power of 2. The first
        one is of largest resolution.
c                 R  > [         [        U ]
  " S
SS0UD6  [        U5      [        U R                  5      :X  d   e[        U5      US   :X  d   eXl        [        R                  " 5       U l	        [        [        U5      5       GH  n[        S[        [        R                  " X   5      [        R                  " US   5      -
  5      5      n/ n[        U5       H  nUR                  [!        US:X  a  U R                  U   OU R"                  U R"                  SSU R$                  U R&                  U R(                  S95        X   US   :w  d  Mu  UR                  [+        SSU R,                  S	95        M     U R                  R                  [        R.                  " U6 5        GM"     g )Nr   r   r   rS   rX   )rY   rT   rU   rV   rZ   r   )r-   r.   r/   r   )r   r   r   r^   r   minfeature_stridesr   rl   scale_headsro   maxrB   nplog2rp   r   r   rT   rU   rV   r3   r/   
Sequential)r   r   kwargsrs   head_length
scale_headkr   s          r   r   FPNHead.__init__  ss   gt% 	9-	917	9?#s4+;+;'<<<<?#q'9999.==?s?+,ABGGO./"''/!:L2MMNPK J;'!!/0Av((+4== !!%!% $./ #%);;%% )*!+*.*<*<>? (  ##BMM:$>?+ -r   c           	      <   U R                  U5      nU R                  S   " US   5      n[        S[        U R                  5      5       H>  nU[        U R                  U   " X$   5      UR                  SS  SU R                  S9-   nM@     U R                  U5      nU$ )Nr   rS   rZ   r   )r,   r.   r/   )	r   r   ro   r^   r   r1   rA   r/   r   )r   r~   r   r   rs   s        r   r   FPNHead.forward  s    ""6*!!!$QqT*q#d2234Af  #AD)\\!"%"00	2 2F 5 f%r   )r   r   )	r!   r"   r#   r$   r   r   r   r%   r&   r'   s   @r   r   r     s    @> r   r   c                      ^  \ rS rSrSrS\" / SQSSS9\" / SQ/ S	Q/ S
QSSS\" SSS9S\" SSSS9S9	4U 4S jjr      SS jrS rSr	U =r
$ )FPNSegmentori  z
Packed Sementor Head
Args:
    fpn_layer_indices: tuple of the indices of layers
    neck_cfg: dict of FPN params
    head_cfg: dict of FPNHead params
)rX            )   r   r   r         )r   r]   r`   )r   r   r   r   )r   rS   rZ   rX   )r      r          r      BNT)rL   requires_gradFr   r   r   )	r   r   r   r   r   r   rU   r/   r   c                 2  > [         [        U ]  5         Xl        US   S   n[        R
                  " [        R                  " [        R                  " XDSSS9[        R                  " U5      [        R                  " 5       [        R                  " XDSSS95      [        R                  " XDSSS9[        R                  " 5       [        R                  " SSS9/5      U l        [        S
0 UD6U l        [        S
0 UD6U l        US   U l        [$        R&                  R)                  5       n[$        R&                  R+                  S5        [$        R&                  R-                  SSU R"                  S4S	9n[$        R&                  R/                  U5        X`l        g )Nr   r   rZ   )r   r[   r   *   r   rX   r,   r   )r   r   r   fpn_layer_indicesr   rl   r   ConvTranspose2dBatchNorm2dGELUIdentity	MaxPool2dpre_fpnrG   fpn_neckr   fpn_headNUM_CLASSESr   random	get_stateseedrandint	set_statePALETTE)r   r   neck_cfghead_cfgwidthstatepaletter   s          r   r   FPNSegmentor.__init__'  s8   & 	lD*,!2'*}}MM""5QqIu%	""5QqI	 u1EKKMLLQq1
&
 
 h+(+ $M2		##%
		r))##As$2B2BA1F#G
		E"r   c	                    [         R                  " U5      nUR                  5       nUn	Uc  U R                  c  [        R
                  R                  5       n
[        R
                  R                  S5        [        R
                  R                  SSU R                  S4S9n[        R
                  R                  U
5        OU R                  n[        R                  " U5      nUR                  S   U R                  :X  d   eUR                  S   S:X  d   e[        UR                  5      S:X  d   eSUs=:  a  S	::  d   e   eU	R                  S   U R                  :X  d   eU	R                  S   UR                  S   :w  d   U	R                  S   UR                  S   :w  a*  [        XR                  S   UR                  S   4SS
S5      n	U	S   n	[        R                   " U	SS9n	[        R"                  " U	R                  S   U	R                  S   S4[        R$                  S9n['        U5       H  u  pXX:H  SS24'   M     USSSS24   nUSU-
  -  X-  -   nUR)                  [        R$                  5      nUb  SnU(       a  [         R*                  " XU5        Ub  [         R,                  " X5        U(       d  U(       d  [.        R1                  S5        ggg)a  Draw `result` over `img`.
Args:
    img (str or Tensor): The image to be displayed.
    result (Tensor): The semantic segmentation results to draw over
        `img`.
    palette (list[list[int]]] | np.ndarray | None): The palette of
        segmentation map. If None is given, random palette will be
        generated. Default: None
    win_name (str): The window name.
    wait_time (int): Value of waitKey param.
        Default: 0.
    show (bool): Whether to show the image.
        Default: False.
    out_file (str or None): The filename to write the image.
        Default: None.
    opacity(float): Opacity of painted segmentation map.
        Default 0.5.
        Must be in (0, 1] range.
Returns:
    img (Tensor): Only if not `show` or `out_file`
Nr   r   r   rX   r   rS   rZ   r   r   Tr   )dtype.r   FzMshow==False and out_file is not specified, only result image will be returned)mmcvimreadrd   r   r   r   r   r   r   r   r   arrayrA   r^   r1   r   argmaxzerosuint8rz   astypeimshowimwriter   r   )r   imgresultr  win_nameshow	wait_timeout_fileopacitysegr  	color_seglabelcolors                 r   show_resultFPNSegmentor.show_resultV  sh   < kk#hhj?||# 		++-		r"))++As$:J:JA9N+O		##E*,,((7#}}Q4#3#3333}}Q1$$$7==!Q&&&7!c!!!!!yy|t/////99Q<399Q<'399Q<399Q<+Gyy|SYYq\:D*C!fll3A&HHciilCIIaL!<BHHM	%g.LE).clAo& / c4R4i(	Q[!I$77jj"DKKy1LL'MM : ; !r   c                 
   U R                    Vs/ s H  o!U   PM	     nn[        [        U5      5       Vs/ s H  o0R                  U   " X   5      PM     nnU R	                  U5      nU R                  U5      nU$ s  snf s  snf r   )r   ro   r^   r   r   r   )r   r   idxrs   s       r   r   FPNSegmentor.forward  sr    #5565sV56,1#a&M:Mq\\!_QT"M:MM!MM! 7:s
   A; B )r   r   r   r   r   r   )N Fr   Ng      ?)r!   r"   r#   r$   r   r   r   r  r   r%   r&   r'   s   @r   r   r     s     $1!5"%! !5*%3!#&!#"DA#(!%0%*%("*+-d !!Qf r   r   )NNrE   NT)abcr   r   r	  numpyr   r   torch.nnr   torch.nn.functional
functionalr)   mmcv.cnnr   mmcv.runnerr   r   r   Moduler
   r1   r3   rG   r   r   r   r   r   r   <module>r+     s    (        9 9&ryy & IDryy D0E* EP\Z7 \~7n 7tR299 Rr   