
    \h@                     ~    S SK r S SK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KJrJr  SSKJr   " S S	\5      rg)
    N)Sequence)AnyCallableOptionalUnion)Image   )download_and_extract_archiveverify_str_arg)VisionDatasetc                      ^  \ rS rSrSrSrSr      SS\\\	R                  4   S\S\\\   \4   S\\   S	\\   S
\\   S\4U 4S jjjrS\4S jrS\S\\\4   4S jrS\4S jrSS jrSrU =r$ )OxfordIIITPet   aX  `Oxford-IIIT Pet Dataset   <https://www.robots.ox.ac.uk/~vgg/data/pets/>`_.

Args:
    root (str or ``pathlib.Path``): Root directory of the dataset.
    split (string, optional): The dataset split, supports ``"trainval"`` (default) or ``"test"``.
    target_types (string, sequence of strings, optional): Types of target to use. Can be ``category`` (default) or
        ``segmentation``. Can also be a list to output a tuple with all specified target types. The types represent:

            - ``category`` (int): Label for one of the 37 pet categories.
            - ``binary-category`` (int): Binary label for cat or dog.
            - ``segmentation`` (PIL image): Segmentation trimap of the image.

        If empty, ``None`` will be returned as target.

    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.
    transforms (callable, optional): A function/transform that takes input sample
        and its target as entry and returns a transformed version.
    download (bool, optional): If True, downloads the dataset from the internet and puts it into
        ``root/oxford-iiit-pet``. If dataset is already downloaded, it is not downloaded again.
))z=https://www.robots.ox.ac.uk/~vgg/data/pets/data/images.tar.gz 5c4f3ee8e5d25df40f4fd59a7f44e54c)zBhttps://www.robots.ox.ac.uk/~vgg/data/pets/data/annotations.tar.gz 95a8c909bbe2e81eed6a22bccdf3f68f)categorybinary-categorysegmentationrootsplittarget_types
transforms	transformtarget_transformdownloadc           
        > [        USS5      U l        [        U[        5      (       a  U/nU Vs/ s H  n[        USU R                  5      PM     snU l        [        TU ]  XXVS9  [        R                  " U R                  5      S-  U l        U R                  S-  U l        U R                  S-  U l        U R                  S-  U l        U(       a  U R                  5         U R!                  5       (       d  [#        S	5      e/ n	/ U l        / U l        [)        U R                  U R                   S
3-  5       n
U
 H  nUR+                  5       R-                  5       u  ppU	R/                  U5        U R$                  R/                  [1        U5      S-
  5        U R&                  R/                  [1        U5      S-
  5        M     S S S 5        SS/U l        [5        [7        XR$                  5       VVs1 s H  u  pUR9                  SS5      S   U4iM     snnS S9 VVs/ s H-  u  nnSR;                  S UR-                  S5       5       5      PM/     snnU l        [?        [7        U R2                  [A        [C        U R2                  5      5      5      5      U l"        [?        [7        U R<                  [A        [C        U R<                  5      5      5      5      U l#        U	 Vs/ s H  oR                  U S3-  PM     snU l$        U	 Vs/ s H  oR                  U S3-  PM     snU l%        g s  snf ! , (       d  f       GNt= fs  snnf s  snnf s  snf s  snf )Nr   )trainvaltestr   )r   r   r   zoxford-iiit-petimagesannotationstrimapsz;Dataset not found. You can use download=True to download itz.txtr	   CatDog_r   c                     U S   $ )Nr	    )image_id_and_labels    ^/var/www/fran/franai/venv/lib/python3.13/site-packages/torchvision/datasets/oxford_iiit_pet.py<lambda>(OxfordIIITPet.__init__.<locals>.<lambda>W   s
    /A!/D    )key c              3   @   #    U  H  oR                  5       v   M     g 7fN)title).0parts     r(   	<genexpr>)OxfordIIITPet.__init__.<locals>.<genexpr>T   s     A.@dZZ\\.@s   z.jpgz.png)&r   _split
isinstancestr_VALID_TARGET_TYPES_target_typessuper__init__pathlibPathr   _base_folder_images_folder_anns_folder_segs_folder	_download_check_existsRuntimeError_labels_bin_labelsopenstripr   appendintbin_classessortedziprsplitjoinclassesdictrangelenbin_class_to_idxclass_to_idx_images_segs)selfr   r   r   r   r   r   r   target_type	image_idsfilelineimage_idlabel	bin_labelr$   raw_cls	__class__s                    r(   r;   OxfordIIITPet.__init__+   s    %UG5IJlC(((>Leq
eqVaN;8P8PQeq
 		m#LL36GG"//(: --= --	9NN!!##\]]	$##T&::;t04

0B0B0D-  *##CJN3  ''I(:;	  < "5> %LOPY[g[gLhiLh(//#q)!,e4LhiD

 HHAgmmC.@AA
 !%S)9)95TEUEUAV;W%X Y T\\5T\\9J3K!LMPYZPYH++
$.??PYZLUVI''XJd*;;IV
M
& <; j
 [Vs*   !L)7B
L./#M 
4MMM.
L=returnc                 ,    [        U R                  5      $ r/   )rS   rV   )rX   s    r(   __len__OxfordIIITPet.__len__`   s    4<<  r+   idxc                 .   [         R                  " U R                  U   5      R                  S5      n/ nU R                   H  nUS:X  a   UR                  U R                  U   5        M)  US:X  a   UR                  U R                  U   5        MO  UR                  [         R                  " U R                  U   5      5        M     U(       d  S nO [        U5      S:X  a  US   nO[        U5      nU R                  (       a  U R                  X#5      u  p#X#4$ )NRGBr   r   r	   r   )r   rG   rV   convertr9   rI   rE   rF   rW   rS   tupler   )rX   rg   imagetargetrY   s        r(   __getitem__OxfordIIITPet.__getitem__c   s    

4<<,-55e<--Kj(dll3/0 11d..s34ejjC9: . F[AAYF6]F?? OOE:ME}r+   c                     U R                   U R                  4 HM  n[        R                  R	                  U5      (       a&  [        R                  R                  U5      (       a  MM    g   g)NFT)r?   r@   ospathexistsisdir)rX   folders     r(   rC   OxfordIIITPet._check_exists{   sJ    **D,=,=>FGGNN6**rww}}V/D/D ? r+   c                     U R                  5       (       a  g U R                   H#  u  p[        U[        U R                  5      US9  M%     g )N)download_rootmd5)rC   
_RESOURCESr
   r7   r>   )rX   urlry   s      r(   rB   OxfordIIITPet._download   s<    HC(C@Q@Q<RX[\ (r+   )r@   r>   rF   rV   r?   rE   rW   rA   r5   r9   rT   rK   rU   rP   )r   r   NNNF)rc   N)__name__
__module____qualname____firstlineno____doc__rz   r8   r   r7   r<   r=   r   r   r   boolr;   rJ   re   rk   r   rn   rC   rB   __static_attributes____classcell__)ra   s   @r(   r   r      s    .J J
  2<)-(,/33WC%&3W 3W HSM3./	3W
 X&3W H%3W #8,3W 3W 3Wj! !s uS#X 0t ] ]r+   r   )rq   os.pathr<   collections.abcr   typingr   r   r   r   PILr   utilsr
   r   visionr   r   r&   r+   r(   <module>r      s0    	   $ 1 1  ? !z]M z]r+   