
    ڧgnh                     D   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZ d dlZd dlZd dlmZmZmZmZ g dZ ej                    	 	 	 	 	 	 d;deej        eej                 f         dedededeeeef                  dededej        fd            Z ej                    	 d<deej        eej                 f         deeej        e
f         dee         ddfd            Z  ej                    	 	 	 	 	 	 d=dej        dej        deee                  deeeeeeeeef         f                  eeeeef         f                  dee         dedee         dee         dej        fd             Z! ej                    	 	 d>dej        d"ej        d#edeeeeeeeeef         f                  eeeeef         f                  dej        f
d$            Z" ej                    	 	 	 	 	 d?dej        d&ej        d'eeeeef                           deeeeeeef         f                  d(eded)eej                 dej        fd*            Z# ej                    d+ej        dej        fd,            Z$ ej                    d-ej        dej        fd.            Z%dej        fd/Z&d0efd1Z'ej(        d2dedeeeeef         eeeeeeef         f                  f         d0ed3ej)        deeeeef                  fd4Z*d5e	ddfd6Z+d7e	d8edee	d9f         fd:Z,dS )@    N)repeat)FunctionType)AnyBinaryIOListOptionalTupleUnion)Image
ImageColor	ImageDraw	ImageFont)	make_grid
save_imagedraw_bounding_boxesdraw_segmentation_masksdraw_keypointsflow_to_image      F        tensornrowpadding	normalizevalue_range
scale_each	pad_valuereturnc                    t           j                                        s2t           j                                        st	          t
                     t          j        |           smt          | t                    r9| D ]5}t          j        |          st          dt          |                     6nt          dt          |                      t          | t                    rt          j        | d          } |                                 dk    r|                     d          } |                                 dk    rF|                     d          dk    rt          j        | | | fd          } |                     d          } |                                 dk    r1|                     d          dk    rt          j        | | | fd          } |d	u rd|                                 } |$t          |t"                    st          d          d fd}|d	u r| D ]} |||           n || |           t          | t           j                  st          d          |                     d          dk    r|                     d          S |                     d          }	t)          ||	          }
t+          t-          j        t1          |	          |
z                      }t+          |                     d          |z             t+          |                     d          |z             }}|                     d          }|                     |||z  |z   ||
z  |z   f|          }d}t5          |          D ]x}t5          |
          D ]f}||	k    r n]|                    d||z  |z   ||z
                                d||z  |z   ||z
                                | |                    |dz   }gy|S )a`  
    Make a grid of images.

    Args:
        tensor (Tensor or list): 4D mini-batch Tensor of shape (B x C x H x W)
            or a list of images all of the same size.
        nrow (int, optional): Number of images displayed in each row of the grid.
            The final grid size is ``(B / nrow, nrow)``. Default: ``8``.
        padding (int, optional): amount of padding. Default: ``2``.
        normalize (bool, optional): If True, shift the image to the range (0, 1),
            by the min and max values specified by ``value_range``. Default: ``False``.
        value_range (tuple, optional): tuple (min, max) where min and max are numbers,
            then these numbers are used to normalize the image. By default, min and max
            are computed from the tensor.
        scale_each (bool, optional): If ``True``, scale each image in the batch of
            images separately rather than the (min, max) over all images. Default: ``False``.
        pad_value (float, optional): Value for the padded pixels. Default: ``0``.

    Returns:
        grid (Tensor): the tensor containing grid of images.
    z:tensor or list of tensors expected, got a list containing z(tensor or list of tensors expected, got r   dimr            TNzNvalue_range has to be a tuple (min, max) if specified. min and max are numbersc                     |                      ||           |                     |                              t          ||z
  d                     d S )N)minmaxgh㈵>)clamp_sub_div_r(   )imglowhighs      M/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/utils.pynorm_ipzmake_grid.<locals>.norm_ipT   sJ    JJ3DJ)))HHSMMs4#:t4455555    c                     | | |d         |d                    d S  | t          |                                           t          |                                                      d S )Nr   r$   )floatr'   r(   )tr   r0   s     r/   
norm_rangezmake_grid.<locals>.norm_rangeX   sa    &;q>;q>:::::5>>5>>:::::r1   z%tensor should be of type torch.Tensor)torchjitis_scripting
is_tracing_log_api_usage_oncer   	is_tensor
isinstancelist	TypeErrortypestackr"   	unsqueezesizecatclonetupleTensorsqueezer'   intmathceilr3   new_fullrangenarrowcopy_)r   r   r   r   r   r   r   r4   r5   nmapsxmapsymapsheightwidthnum_channelsgridkyxr0   s                      @r/   r   r      s   > 9!!## 'EI,@,@,B,B 'I&&&?6"" Wfd## 	W l lq)) l#$jaefgahah$j$jkkkll UtF||UUVVV &$ ,V+++zz||q!!!$$zz||q;;q>>QY7;;F!!!$$zz||qV[[^^q00FFF3Q77D":k5+I+I"lmmm	6 	6 	6	; 	; 	; 	; 	;  + +
1k****+ Jv{+++fel++ A?@@@{{1~~~~a    KKNNEeE	%,,.//00EA0113v{{1~~7O3P3PEF;;q>>L??L&5.7*BEEMT[D[\^ghhD	A5\\ 	 	u 	 	AEzz KK1v:/'1ABBII1u9w& eF1IAAAKr1   fpformatc                    t           j                                        s2t           j                                        st	          t
                     t          | fi |}|                    d                              d          	                    dd          
                    ddd                              dt           j                                                  }t          j        |          }|                    ||           dS )	a#  
    Save a given Tensor into an image file.

    Args:
        tensor (Tensor or list): Image to be saved. If given a mini-batch tensor,
            saves the tensor as a grid of images by calling ``make_grid``.
        fp (string or file object): A filename or a file object
        format(Optional):  If omitted, the format to use is determined from the filename extension.
            If a file object was used instead of a filename, this parameter should always be used.
        **kwargs: Other arguments are documented in ``make_grid``.
       g      ?r   r$   r   cpu)rZ   N)r6   r7   r8   r9   r:   r   r   muladd_r)   permutetouint8numpyr   	fromarraysave)r   rY   rZ   kwargsrU   ndarrims          r/   r   r   ~   s    & 9!!## (EI,@,@,B,B (J'''V&&v&&DHHSMMs##**1c22::1aCCFFuekZZ``bbE			BGGBvGr1   r$   imageboxeslabelscolorsfillrS   font	font_sizec                    ddl mc mc m} t          j                                        s2t          j                                        st          t                     t          | t          j                  st          dt          |                      | j        t          j        k    s+|                                 st#          d| j                   |                                 dk    rt#          d          |                     d          dvrt#          d          |dddf         |ddd	f         k                                    s,|ddd
f         |dddf         k                                    rt#          d          |j        d         }	|	dk    rt-          j        d           | S |dg|	z  }n6t1          |          |	k    r#t#          d|	 dt1          |           d          t3          ||	          }|*|t-          j        d           t5          j                    }
nt5          j        ||pd          }
|                     d          d
k    rt	          j        | d          } | j        }|j        r"|                    | t          j        d          } |                    |           }|                     t          j!                  "                                }|rtG          j$        |d          }ntG          j$        |          }tK          |||          D ]s\  }}}|r|dz   }|&                    ||||           n|&                    |||           |2|d
z   }|'                    |d         |z   |d
         |z   f|||
           t|(                    |          }|j        r|                    ||d          }|S )a  
    Draws bounding boxes on given RGB image.
    The image values should be uint8 in [0, 255] or float in [0, 1].
    If fill is True, Resulting Tensor should be saved as PNG image.

    Args:
        image (Tensor): Tensor of shape (C, H, W) and dtype uint8 or float.
        boxes (Tensor): Tensor of size (N, 4) containing bounding boxes in (xmin, ymin, xmax, ymax) format. Note that
            the boxes are absolute coordinates with respect to the image. In other words: `0 <= xmin < xmax < W` and
            `0 <= ymin < ymax < H`.
        labels (List[str]): List containing the labels of bounding boxes.
        colors (color or list of colors, optional): List containing the colors
            of the boxes or single color for all boxes. The color can be represented as
            PIL strings e.g. "red" or "#FF00FF", or as RGB tuples e.g. ``(240, 10, 157)``.
            By default, random colors are generated for boxes.
        fill (bool): If `True` fills the bounding box with specified color.
        width (int): Width of bounding box.
        font (str): A filename containing a TrueType font. If the file is not found in this filename, the loader may
            also search in other directories, such as the `fonts/` directory on Windows or `/Library/Fonts/`,
            `/System/Library/Fonts/` and `~/Library/Fonts/` on macOS.
        font_size (int): The requested font size in points.

    Returns:
        img (Tensor[C, H, W]): Image Tensor of dtype uint8 with bounding boxes plotted.
    r   NzTensor expected, got ,The image dtype must be uint8 or float, got r#   #Pass individual images, not batches>   r$   r#   z+Only grayscale and RGB images are supportedr   r$   zdBoxes need to be in (xmin, ymin, xmax, ymax) format. Use torchvision.ops.box_convert to convert themz/boxes doesn't contain any box. No box was drawnzNumber of boxes (z) and labels (z/) mismatch. Please specify labels for each box.)num_objectsz=Argument 'font_size' will be ignored since 'font' is not set.
   )rn   rB   )r#   r$   r$   TdtypescaleRGBA)d   )rS   outlinerm   )rS   rz   )rm   rn   ))$torchvision.transforms.v2.functional
transformsv2
functionalr6   r7   r8   r9   r:   r   r<   rF   r>   r?   rv   rb   is_floating_point
ValueErrorr"   rB   anyshapewarningswarnlen_parse_colorsr   load_defaulttruetypetileto_dtypeto_pil_imagera   int64tolistr   Drawzip	rectangletextpil_to_tensor)ri   rj   rk   rl   rm   rS   rn   ro   F	num_boxestxt_fontoriginal_dtypeimg_to_draw	img_boxesdrawbboxcolorlabel
fill_colormarginouts                        r/   r   r      s   J 5444444444449!!## 1EI,@,@,B,B 1/000eU\** 
=U==>>>kU[((E,C,C,E,E(UUUVVV			>???	Af	$	$FGGG
1+aaad
#	(	(	*	* 
uQQQT{U111a4[/H.M.M.O.O 
r
 
 	
 AIA~~GHHH~04v	/A	V		!	!u	uuVuuu
 
 	
 6y999F| MYZZZ)++%4io2FFF zz!}}
5),,[N' A

54
@@..''K%%,,..I +~k622~k**!)VV<< 	^ 	^eU 	=JNN4ue*NMMMMNN4ueN<<<QYFIItAw'a6)9:ET\I]]]
//+
&
&C' @jjN$j??Jr1   皙?masksalphac                 @   
 t           j                                        s2t           j                                        st	          t
                     t           t           j                  st          dt                                 j
        t           j        k    s+                                 st          d j
                                                    dk    rt          d                                           d         dk    rt          d          |j        dk    r|dddddf         }|j        dk    rt          d	          |j
        t           j        k    rt          d
|j
                   |j        dd          j        dd         k    rt          d          |                                d         }|                    d          dk    }|dk    rt)          j        d            S  j
        
 
fdt-          ||
          D             }                                                                 }t3          ||          D ]\  }}|dddf         |dd|f<   d|dd|f<    d|z
  z  ||z  z   }	|	                    
          S )ah  
    Draws segmentation masks on given RGB image.
    The image values should be uint8 in [0, 255] or float in [0, 1].

    Args:
        image (Tensor): Tensor of shape (3, H, W) and dtype uint8 or float.
        masks (Tensor): Tensor of shape (num_masks, H, W) or (H, W) and dtype bool.
        alpha (float): Float number between 0 and 1 denoting the transparency of the masks.
            0 means full transparency, 1 means no transparency.
        colors (color or list of colors, optional): List containing the colors
            of the masks or single color for all masks. The color can be represented as
            PIL strings e.g. "red" or "#FF00FF", or as RGB tuples e.g. ``(240, 10, 157)``.
            By default, random colors are generated for each mask.

    Returns:
        img (Tensor[C, H, W]): Image Tensor, with segmentation masks drawn on top.
     The image must be a tensor, got rq   r#   rr   r   8Pass an RGB image. Other Image formats are not supportedr   Nz3masks must be of shape (H, W) or (batch_size, H, W)z%The masks must be of dtype bool. Got z;The image and the masks must have the same height and widthr!   r$   z1masks doesn't contain any mask. No mask was drawnc                 H    g | ]}t          j        |j                   S )rv   device)r6   r   r   ).0r   ri   r   s     r/   
<listcomp>z+draw_segmentation_masks.<locals>.<listcomp><  s<        	U.FFF  r1   )rs   rv   )r6   r7   r8   r9   r:   r   r<   rF   r>   r?   rv   rb   r   r   r"   rB   ndimboolr   sumr   r   r   detachrD   r   ra   )ri   r   r   rl   	num_masksoverlapping_masksr   maskr   r   r   s   `         @r/   r   r     s   4 9!!## 5EI,@,@,B,B 53444eU\** UH4;;HHIIIkU[((E,C,C,E,E(UUUVVV			>???	aA		STTTzQdAAAqqqj!zQNOOO{ej  NNNOOO{2335;rss+++VWWW

QI		a	((1,A~~IJJJ[N    "6yWWW  F
 ,,..&&((K5&)) . .e$QQQW~AAAtG()K$$%
1u9
e 3
3C66.!!!r1   r#   	keypointsconnectivityradius
visibilityc                 f   t           j                                        s2t           j                                        st	          t
                     t          | t           j                  st          dt          |                      | j
        t           j        k    s+|                                 st          d| j
                   |                                 dk    rt          d          |                                 d         dk    rt          d          |j        dk    rt          d          |-t          j        |j        dd	         t           j        
          }|j        dk    r|                    d	          }|j        dk    rt          d|j                   |j        |j        dd	         k    rt          d|j        d|j                  | j
        }|j        rddlm}  || t           j        d          } |                     ddd                                                                          }	t5          j        |	          }
t9          j        |
          }|                    t           j                                                   }|                                                                                                 }tC          ||          D ]\  }}tC          ||          D ]Q\  }}|s|d         |z
  }|d         |z   }|d         |z
  }|d         |z   }|"                    ||||g|dd           R|r|D ]}||d                  r||d                  s||d                  d         }||d                  d         }||d                  d         }||d                  d         }|#                    ||f||ff|           t          j$        tK          j&        |
                                        ddd          }|j        r |||d          }|S )a  
    Draws Keypoints on given RGB image.
    The image values should be uint8 in [0, 255] or float in [0, 1].
    Keypoints can be drawn for multiple instances at a time.

    This method allows that keypoints and their connectivity are drawn based on the visibility of this keypoint.

    Args:
        image (Tensor): Tensor of shape (3, H, W) and dtype uint8 or float.
        keypoints (Tensor): Tensor of shape (num_instances, K, 2) the K keypoint locations for each of the N instances,
            in the format [x, y].
        connectivity (List[Tuple[int, int]]]): A List of tuple where each tuple contains a pair of keypoints
            to be connected.
            If at least one of the two connected keypoints has a ``visibility`` of False,
            this specific connection is not drawn.
            Exclusions due to invisibility are computed per-instance.
        colors (str, Tuple): The color can be represented as
            PIL strings e.g. "red" or "#FF00FF", or as RGB tuples e.g. ``(240, 10, 157)``.
        radius (int): Integer denoting radius of keypoint.
        width (int): Integer denoting width of line connecting keypoints.
        visibility (Tensor): Tensor of shape (num_instances, K) specifying the visibility of the K
            keypoints for each of the N instances.
            True means that the respective keypoint is visible and should be drawn.
            False means invisible, so neither the point nor possible connections containing it are drawn.
            The input tensor will be cast to bool.
            Default ``None`` means that all the keypoints are visible.
            For more details, see :ref:`draw_keypoints_with_visibility`.

    Returns:
        img (Tensor[C, H, W]): Image Tensor with keypoints drawn.
    r   rq   r#   rr   r   r   z0keypoints must be of shape (num_instances, K, 2)Nrv   r   z9visibility must be of shape (num_instances, K). Got ndim=zkkeypoints and visibility must have the same dimensionality for num_instances and K. Got visibility.shape = z and keypoints.shape = )r   Tru   r$   )rm   rz   rS   )rS   )'r6   r7   r8   r9   r:   r   r<   rF   r>   r?   rv   rb   r   r   r"   rB   r   onesr   r   rG   r{   r   r`   r]   rc   r   rd   r   r   ra   r   r   r   ellipseline
from_numpynparray)ri   r   r   rl   r   rS   r   r   r   rg   r   r   img_kptsimg_viskpt_instvis_inst	kpt_coordkp_visx1x2y1y2
connection
start_pt_x
start_pt_yend_pt_xend_pt_yr   s                               r/   r   r   M  s]   V 9!!## ,EI,@,@,B,B ,N+++eU\** UH4;;HHIIIkU[((E,C,C,E,E(UUUVVV			>???	aA		STTT ~KLLL Z	 4EJGGG
!  ''++
!fU_Udffggg9?3B3///B#B B-6_B B
 
 	

 [N' ?AAAAAAek>>>MM!Q""&&((..00E/%((K>+&&D||EK((//11Hnn##%%,,..G!(G44  (!$Xx!8!8 	O 	OIv 1&B1&B1&B1&BLL"b"b)ALNNNN 	*  
 A/ *Q-9P %jm4Q7
%jm4Q7
#JqM215#JqM215		 *-(/CD     
 
28K00
1
1
9
9!Q
B
BC' >hs.===Jr1   flowc                    | j         t          j        k    rt          d| j          d          | j        }| j        dk    r| d         } | j        dk    s| j        d         dk    rt          d| d          t          j        | dz  d	                                                                          }t          j	        | j                   j
        }| ||z   z  }t          |          }t          |          dk    r|d
         }|S )aJ  
    Converts a flow to an RGB image.

    Args:
        flow (Tensor): Flow of shape (N, 2, H, W) or (2, H, W) and dtype torch.float.

    Returns:
        img (Tensor): Image Tensor of dtype uint8 where each color corresponds
            to a given flow direction. Shape is (N, 3, H, W) or (3, H, W) depending on the input.
    z)Flow should be of dtype torch.float, got .r#   Nr%   r$   r   z<Input flow should have shape (2, H, W) or (N, 2, H, W), got r!   r   )rv   r6   r3   r   r   r   r   sqrtr(   finfoeps_normalized_flow_to_imager   )r   
orig_shapemax_normepsilonnormalized_flowr,   s         r/   r   r     s     zU[  RTZRRRSSSJyA~~DzyA~~A!++eXbeeefffyqa(((--//3355Hk4,''+Gh01O
#O
4
4C
:!!fJr1   r   c           	      L   | j         \  }}}}| j        }t          j        |d||ft          j        |          }t                                          |          }|j         d         }t          j        | dz  d                                          }	t          j	        | dddddddf          | dddddddf                    t          j
        z  }
|
dz   dz  |dz
  z  }t          j        |                              t          j                  }|dz   }d|||k    <   ||z
  }t          |j         d                   D ]a}|dd|f         }||         dz  }||         dz  }d|z
  |z  ||z  z   }d|	d|z
  z  z
  }t          j        d	|z            |dd|ddddf<   b|S )
z
    Converts a batch of normalized flow to an RGB image.

    Args:
        normalized_flow (torch.Tensor): Normalized flow tensor of shape (N, 2, H, W)
    Returns:
       img (Tensor(N, 3, H, W)): Flow visualization image of dtype uint8.
    r#   r   r   r   r$   r!   Ng     o@r\   )r   r   r6   zerosrb   _make_colorwheelra   r   r   atan2pifloorlongrL   )r   N_HWr   
flow_image
colorwheelnum_colsnormafkk0k1fctmpcol0col1cols                       r/   r   r     s    !&JAq!Q#FaAq\VLLLJ!##&&v..J"H9_a'Q///4466D_QQQ111aaaZ00?111aAAA:3N2NOORWRZZA
a%11	%B	R		EJ	'	'B	aBBrX~
RA:#A&'' 8 8A2w2w1unq4x'$!c'""!&S3Y!7!7
111aAAA:r1   c                     d} d}d}d}d}d}| |z   |z   |z   |z   |z   }t          j        |df          }d}d|d| df<   t          j        dt          j        d|           z  | z            |d| d	f<   || z   }dt          j        dt          j        d|          z  |z            z
  ||||z   df<   d||||z   d	f<   ||z   }d||||z   d	f<   t          j        dt          j        d|          z  |z            ||||z   d
f<   ||z   }dt          j        dt          j        |          z  |z            z
  ||||z   d	f<   d||||z   d
f<   ||z   }d||||z   d
f<   t          j        dt          j        d|          z  |z            ||||z   df<   ||z   }dt          j        dt          j        |          z  |z            z
  ||||z   d
f<   d||||z   df<   |S )a-  
    Generates a color wheel for optical flow visualization as presented in:
    Baker et al. "A Database and Evaluation Methodology for Optical Flow" (ICCV, 2007)
    URL: http://vision.middlebury.edu/flow/flowEval-iccv07.pdf.

    Returns:
        colorwheel (Tensor[55, 3]): Colorwheel Tensor.
          r%         r#   r   r\   r$   r   )r6   r   r   arange)	RYYGGCCBBMMRncolsr   r   s	            r/   r   r     sa    
B	
B	
B	B	B	
BGbL2"R'EeQZ((J
C JqtQw+cELB,?,?&?"&DEEJqtQw
(C$'%+cELB<O<O6ORT6T*U*U$UJsS2X~q !$'JsS2X~q !
(C$'JsS2X~q !$)Kel1b6I6I0IB0N$O$OJsS2X~q !
(C$'%+cEL<L<L6Lr6Q*R*R$RJsS2X~q !$'JsS2X~q !
(C$'JsS2X~q !$)Kel1b6I6I0IB0N$O$OJsS2X~q !
(C$'%+cEL<L<L6Lr6Q*R*R$RJsS2X~q !$'JsS2X~q !r1   rs   c                 f    t          j        g d          fdt          |           D             S )N)ii  i c                 :    g | ]}t          |z  d z            S )r\   rE   )r   ipalettes     r/   r   z+_generate_color_palette.<locals>.<listcomp>9  s*    CCC1E1w;#%&&CCCr1   )r6   r   rL   )rs   r  s    @r/   _generate_color_paletter  7  s;    l<<<==GCCCCk0B0BCCCCr1   r   rv   c                   | t          |          } nt          | t                    r7t          |           |k     r#t	          dt          |            d| d          npt          | t
          t          f          st	          d|  d          t          | t
                    r&t          |           dk    rt	          d|  d          | g|z  } d | D             } |j        rd	 | D             } | S )
a  
    Parses a specification of colors for a set of objects.

    Args:
        colors: A specification of colors for the objects. This can be one of the following:
            - None: to generate a color palette automatically.
            - A list of colors: where each color is either a string (specifying a named color) or an RGB tuple.
            - A string or an RGB tuple: to use the same color for all objects.

            If `colors` is a tuple, it should be a 3-tuple specifying the RGB values of the color.
            If `colors` is a list, it should have at least as many elements as the number of objects to color.

        num_objects (int): The number of objects to color.

    Returns:
        A list of 3-tuples, specifying the RGB values of the colors.

    Raises:
        ValueError: If the number of colors in the list is less than the number of objects to color.
                    If `colors` is not a list, tuple, string or None.
    NzMNumber of colors must be equal or larger than the number of objects, but got z < r   zA`colors` must be a tuple or a string, or a list thereof, but got r#   z=If passed as tuple, colors should be an RGB triplet, but got c                 d    g | ]-}t          |t                    rt          j        |          n|.S  )r<   strr   getrgbr   r   s     r/   r   z!_parse_colors.<locals>.<listcomp>e  s8    ```PU*UC*@*@Kj&&&e```r1   c                 @    g | ]}t          d  |D                       S )c              3       K   | ]	}|d z  V  
dS )r\   Nr  )r   vs     r/   	<genexpr>z+_parse_colors.<locals>.<listcomp>.<genexpr>g  s&      //AC//////r1   r  r  s     r/   r   z!_parse_colors.<locals>.<listcomp>g  s/    DDDE%///////DDDr1   )r  r<   r=   r   r   rE   r	  r   )rl   rs   rv   s      r/   r   r   <  s'   6 ~(55	FD	!	! 
(v;;$$~`cdj`k`k~~p{~~~   % -- (f]cfffggg	FE	"	" (s6{{a'7'7bY_bbbcccK'``Y_```F EDDVDDDMr1   objc                     | j         }|                    d          sd| }| j        j        }t	          | t
                    r| j        }t          j                            | d|            dS )a  
    Logs API usage(module and name) within an organization.
    In a large ecosystem, it's often useful to track the PyTorch and
    TorchVision APIs usage. This API provides the similar functionality to the
    logging module in the Python stdlib. It can be used for debugging purpose
    to log which methods are used and by default it is inactive, unless the user
    manually subscribes a logger via the `SetAPIUsageLogger method <https://github.com/pytorch/pytorch/blob/eb3b9fe719b21fae13c7a7cf3253f970290a573e/c10/util/Logging.cpp#L114>`_.
    Please note it is triggered only once for the same API call within a process.
    It does not collect any data from open-source users since it is no-op by default.
    For more information, please refer to
    * PyTorch note: https://pytorch.org/docs/stable/notes/large_scale_deployments.html#api-usage-logging;
    * Logging policy: https://github.com/pytorch/vision/issues/5052;

    Args:
        obj (class instance or method): an object to extract info from.
    torchvisionztorchvision.internal.r   N)	
__module__
startswith	__class____name__r<   r   r6   _Cr:   )r  modulenames      r/   r:   r:   k  s{    $ ^F]++ 2111=!D#|$$ |	H  F!3!3T!3!344444r1   rX   n.c                     t          | t          j        j                  rt	          |           S t	          t          | |                    S )aS  
    Make n-tuple from input x. If x is an iterable, then we just convert it to tuple.
    Otherwise, we will make a tuple of length n, all with value of x.
    reference: https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/utils.py#L8

    Args:
        x (Any): input value
        n (int): length of the resulting tuple
    )r<   collectionsabcIterablerE   r   )rX   r  s     r/   _make_ntupler    s<     ![_-.. Qxx1r1   )r   r   FNFr   )N)NNFr$   NN)r   N)NNr   r#   N)-r  rI   pathlibr   	itertoolsr   typesr   typingr   r   r   r   r	   r
   rc   r   r6   PILr   r   r   r   __all__no_gradrF   rH   r   r3   r   r	  Pathr   r   r   r   r   r   r   r  rb   rv   r   r:   r  r  r1   r/   <module>r(     s                      > > > > > > > > > > > > > > > >      7 7 7 7 7 7 7 7 7 7 7 7    -1b b%,U\ 223b
b b 	b
 %S/*b b b \b b b bJ  ! %,U\ 223c7<)* SM
 
   6  #'ae #i i<i<i T#Yi U4c5c3+?&? @A3cSVX[mH\\]^	i
 4.i i 3-i }i \i i i iX  ae	B" B"<B"<B" B" U4c5c3+?&? @A3cSVX[mH\\]^	B"
 \B" B" B" B"J  599=)-q q<q|q 4c3h01q U3c3m 4456	q
 q q &q \q q q qj      B u|     D,%, , , , ,^D D D D D 	, , ,$U3S=14c5cSVCW>W8X3YYZ, , ;	,
 
%S#
, , , ,^5S 5T 5 5 5 56C C E#s(O      r1   