
    h1                          S SK r S SKJrJr  S SKJr  S SKJrJrJ	r	J
r
  S SKrS SKJr  SSKJrJrJrJr  SSKJr   " S	 S
\5      rg)    N)abspath
expanduser)Path)AnyCallableOptionalUnion)Image   )download_and_extract_archivedownload_file_from_google_driveextract_archiveverify_str_arg)VisionDatasetc                      ^  \ rS rSrSrSr/ SQrSr    SS\\	\
4   S\	S	\\   S
\\   S\SS4U 4S jjjrS\S\\\4   4S jrS\4S jrS\	4S jrSS jrSS jrS\4S jrSS jrSrU =r$ )	WIDERFace   u  `WIDERFace <http://shuoyang1213.me/WIDERFACE/>`_ Dataset.

Args:
    root (str or ``pathlib.Path``): Root directory where images and annotations are downloaded to.
        Expects the following folder structure if download=False:

        .. code::

            <root>
                └── widerface
                    ├── wider_face_split ('wider_face_split.zip' if compressed)
                    ├── WIDER_train ('WIDER_train.zip' if compressed)
                    ├── WIDER_val ('WIDER_val.zip' if compressed)
                    └── WIDER_test ('WIDER_test.zip' if compressed)
    split (string): The dataset split to use. One of {``train``, ``val``, ``test``}.
        Defaults to ``train``.
    transform (callable, optional): A function/transform that takes in a PIL image
        and returns a transformed version. E.g, ``transforms.RandomCrop``
    target_transform (callable, optional): A function/transform that takes in the
        target and transforms it.
    download (bool, optional): If true, downloads the dataset from the internet and
        puts it in root directory. If dataset is already downloaded, it is not
        downloaded again.

        .. warning::

            To download the dataset `gdown <https://github.com/wkentaro/gdown>`_ is required.

	widerface))!15hGDLhsx8bLgLcIRD5DhYt5iBxnjNF1M 3fedf70df600953d25982bcd13d91ba2zWIDER_train.zip)!1GUCogbp16PMGa39thoMMeWxp7Rp5oM8Q dfa7d7e790efa35df3788964cf0bbaeazWIDER_val.zip)!1HIfDbVEWKmsYKJZm4lchTBDLW5N7dY5T e5d8f4248ed24c334bbd12f49c29dd40zWIDER_test.zip)zLhttp://shuoyang1213.me/WIDERFACE/support/bbx_annotation/wider_face_split.zip 0e3767bcf0e326556d407bf5bff5d27czwider_face_split.zipNrootsplit	transformtarget_transformdownloadreturnc                 r  > [         TU ]  [        R                  R	                  XR
                  5      X4S9  [        USS5      U l        U(       a  U R                  5         U R                  5       (       d  [        S5      e/ U l        U R                  S;   a  U R                  5         g U R                  5         g )N)r   r   r   r   )trainvaltestzTDataset not found or corrupted. You can use download=True to download and prepare it)r#   r$   )super__init__ospathjoinBASE_FOLDERr   r   r    _check_integrityRuntimeErrorimg_info parse_train_val_annotations_fileparse_test_annotations_file)selfr   r   r   r   r    	__class__s         V/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/datasets/widerface.pyr'   WIDERFace.__init__:   s     	d$4$45 	 	
 $E74LM
MMO$$&&uvvNP::))113,,.    indexc                    [         R                  " U R                  U   S   5      nU R                  b  U R                  U5      nU R                  S:X  a  SOU R                  U   S   nU R
                  b  U R                  U5      nX#4$ )z
Args:
    index (int): Index

Returns:
    tuple: (image, target) where target is a dict of annotations for all faces in the image.
    target=None for the test split.
img_pathNr%   annotations)r
   openr.   r   r   r   )r1   r6   imgtargets       r3   __getitem__WIDERFace.__getitem__T   s|     jju-j9:>>%..%Cv-4==3G3V  ,**62F{r5   c                 ,    [        U R                  5      $ )N)lenr.   )r1   s    r3   __len__WIDERFace.__len__j   s    4==!!r5   c                 ^    S/nSR                  U5      R                  " S0 U R                  D6$ )NzSplit: {split}
 )r*   format__dict__)r1   liness     r3   
extra_reprWIDERFace.extra_reprm   s+    !"yy&&777r5   c                    U R                   S:X  a  SOSn[        R                  R                  U R                  SU5      n[        U5       nUR                  5       nSu  pVnSu  p/ n
U GH  nUR                  5       nU(       aS  [        R                  R                  U R                  SU R                   -   SU5      n[        [        U5      5      nS	nS
nMn  U(       a  [        U5      nS	nS
nM  U(       Ga4  U	S-  n	UR                  S5      nU Vs/ s H  n[        U5      PM     nnU
R                  U5        X:  a  S	nS
n[        R                  " U
5      nU R                  R                  WUS S 2SS24   R                  5       US S 2S4   R                  5       US S 2S4   R                  5       US S 2S4   R                  5       US S 2S4   R                  5       US S 2S4   R                  5       US S 2S4   R                  5       S.S.5        Sn	U
R!                  5         GM  GM  [#        SU 35      e   S S S 5        g s  snf ! , (       d  f       g = f)Nr#   zwider_face_train_bbx_gt.txtzwider_face_val_bbx_gt.txtwider_face_split)TFF)r   r   WIDER_imagesFTr    r                  	   )bboxblur
expressionillumination	occlusionposeinvalid)r8   r9   zError parsing annotation file )r   r(   r)   r*   r   r:   	readlinesrstripr   r   intappendtorchtensorr.   cloneclearr-   )r1   filenamefilepathfrH   file_name_linenum_boxes_linebox_annotation_line	num_boxesbox_counterlabelsliner8   
line_splitxline_valueslabels_tensors                    r3   r/   *WIDERFace.parse_train_val_annotations_fileq   s   48JJ'4I0Oj77<<		+=xH(^qKKMEBT?N,?%)"IF{{}!!ww||DIIx$**7LhX\]H&z(';<H%*N%)N# #D	I%*N*.'(1$K!%CJ3=">:a3q6:K">MM+."/.3+)-(-V(<,,,4,9!QqS&,A,G,G,I,9!Q$,?,E,E,G2?12E2K2K2M4A!Q$4G4M4M4O1>q!t1D1J1J1L,9!Q$,?,E,E,G/<QT/B/H/H/J0" '(' 0* ')Gz'RSSK  ^& #?' ^s    CI	I&DI	I		
Ic                    [         R                  R                  U R                  SS5      n[	        [        U5      5      n[        U5       nUR                  5       nU Hp  nUR                  5       n[         R                  R                  U R                  SSU5      n[	        [        U5      5      nU R                  R                  SU05        Mr     S S S 5        g ! , (       d  f       g = f)NrL   zwider_face_test_filelist.txt
WIDER_testrN   r8   )r(   r)   r*   r   r   r   r:   r]   r^   r.   r`   )r1   rf   rg   rH   rn   r8   s         r3   r0   %WIDERFace.parse_test_annotations_file   s    77<<		+=?]^:h/0(^qKKME{{}77<<		<4P":h#78$$j(%;<	  ^^s   BC
C)c                 h   U R                   R                  5       nUR                  U R                  5        U Hw  u  p#n[        R
                  R                  U5      u  pV[        R
                  R                  U R                  U5      n[        R
                  R                  U5      (       a  Mw    g   g)NFT)
	FILE_LISTcopyr`   ANNOTATIONS_FILEr(   r)   splitextr*   r   exists)r1   	all_files_md5re   fileextextracted_dirs           r3   r,   WIDERFace._check_integrity   s    NN'')	../ )AH((2IDGGLLD9M77>>-00	 !*
 r5   c                 P   U R                  5       (       a  g U R                   HQ  u  pn[        XR                  X25        [        R
                  R                  U R                  U5      n[        U5        MS     [        U R                  S   U R                  U R                  S   S9  g )Nr   r   )urldownload_rootr   )
r,   rx   r   r   r(   r)   r*   r   r   rz   )r1   file_idr   re   rf   s        r3   r    WIDERFace.download   s      "" '+nn"G(+GYYNww||DIIx8HH% '5 	%%%a(		tG\G\]^G_	
r5   )r.   r   )r#   NNF)r!   N)__name__
__module____qualname____firstlineno____doc__r+   rx   rz   r	   strr   r   r   boolr'   r_   tupler   r=   rA   rI   r/   r0   r,   r    __static_attributes____classcell__)r2   s   @r3   r   r      s    < KI (,/3/CI/ / H%	/
 #8,/ / 
/ /4 sCx ," "8C 8.T`	=	$ 	
 
r5   r   )r(   os.pathr   r   pathlibr   typingr   r   r   r	   ra   PILr
   utilsr   r   r   r   visionr   r   rE   r5   r3   <module>r      s1    	 '  1 1   q q !v
 v
r5   