
    %`i@                         d dl Z d dlZ d dlZd dlmZ d dlmZmZmZm	Z	 d dl
mZ ddlmZmZ ddlmZ  G d d	e          ZdS )
    N)Sequence)AnyCallableOptionalUnion)Image   )download_and_extract_archiveverify_str_arg)VisionDatasetc                        e Zd ZdZdZdZ	 	 	 	 	 	 ddeeej	        f         d	ed
ee
e         ef         dee         dee         dee         def fdZdefdZdedeeef         fdZdefdZddZ xZS )OxfordIIITPeta  `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trainvalr   NFrootsplittarget_types
transforms	transformtarget_transformdownloadc           
          t          |dd           _        t          |t                    r|g} fd|D              _        t                                          ||||           t          j         j	                  dz   _
         j
        dz   _         j
        dz   _         j        dz   _        |r                                                                   st!          d	          g }g  _        g  _        t'           j         j         d
z            5 }	|	D ]}
|
                                                                \  }}}}|                    |            j                            t/          |          dz
              j                            t/          |          dz
             	 d d d            n# 1 swxY w Y   ddg _        d t3          d t5          | j                  D             d           D              _        t9          t5           j        t;          t=           j                                                 _        t9          t5           j        t;          t=           j                                                 _          fd|D              _!         fd|D              _"        d S )Nr   )r   testc                 <    g | ]}t          |d j                  S )r   )r   _VALID_TARGET_TYPES).0target_typeselfs     x/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchvision/datasets/oxford_iiit_pet.py
<listcomp>z*OxfordIIITPet.__init__.<locals>.<listcomp>8   s5     
 
 
VaN;8PQQ
 
 
    )r   r   r   zoxford-iiit-petimagesannotationstrimapsz;Dataset not found. You can use download=True to download itz.txtr	   CatDogc                 x    g | ]7\  }}d                      d |                    d          D                       8S ) c              3   >   K   | ]}|                                 V  d S N)title)r    parts     r#   	<genexpr>z4OxfordIIITPet.__init__.<locals>.<listcomp>.<genexpr>T   s*      AAdTZZ\\AAAAAAr%   _)joinr   )r    raw_clsr2   s      r#   r$   z*OxfordIIITPet.__init__.<locals>.<listcomp>S   sS     
 
 
 HHAAgmmC.@.@AAAAA
 
 
r%   c                 P    h | ]#\  }}|                     d d          d         |f$S )r2   r	   r   )rsplit)r    image_idlabels      r#   	<setcomp>z)OxfordIIITPet.__init__.<locals>.<setcomp>V   s4    iii5(//#q))!,e4iiir%   c                     | d         S )Nr	    )image_id_and_labels    r#   <lambda>z(OxfordIIITPet.__init__.<locals>.<lambda>W   s    /A!/D r%   )keyc                 *    g | ]}j         | d z  S )z.jpg)_images_folderr    r7   r"   s     r#   r$   z*OxfordIIITPet.__init__.<locals>.<listcomp>]   s*    ZZZH+.?.?.??ZZZr%   c                 *    g | ]}j         | d z  S )z.png)_segs_folderrA   s     r#   r$   z*OxfordIIITPet.__init__.<locals>.<listcomp>^   s*    VVVd'X*;*;*;;VVVr%   )#r   _split
isinstancestr_target_typessuper__init__pathlibPathr   _base_folderr@   _anns_folderrC   	_download_check_existsRuntimeError_labels_bin_labelsopenstripr   appendintbin_classessortedzipclassesdictrangelenbin_class_to_idxclass_to_idx_images_segs)r"   r   r   r   r   r   r   r   	image_idsfileliner7   r8   	bin_labelr2   	__class__s   `              r#   rI   zOxfordIIITPet.__init__+   s    %UG5IJJlC(( 	*(>L
 
 
 
eq
 
 
 	*	\lmmm#L336GG"/(: -= -	9 	NN!!## 	^\]]]	$#&:&:&::;; 	<t < <04

0B0B0D0D-%A  ***##CJJN333 ''I(:;;;;	<	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< "5>
 
$iiCPY[_[gLhLhiiiDD  
 
 
 !%S)95TEUAVAV;W;W%X%X Y Y T\5T\9J9J3K3K!L!LMMZZZZPYZZZVVVVIVVV


s   BGG
G
returnc                 *    t          | j                  S r.   )r]   r`   )r"   s    r#   __len__zOxfordIIITPet.__len__`   s    4<   r%   idxc                 &   t          j        | j        |                                       d          }g }| j        D ]}|dk    r!|                    | j        |                    )|dk    r!|                    | j        |                    P|                    t          j        | j        |                              |sd }n+t          |          dk    r	|d         }nt          |          }| j        r|                     ||          \  }}||fS )NRGBr   r   r	   r   )r   rS   r`   convertrG   rU   rQ   rR   ra   r]   tupler   )r"   rj   imagetargetr!   s        r#   __getitem__zOxfordIIITPet.__getitem__c   s   
4<,--55e<<- 	; 	;Kj((dl3/0000 111d.s34444ejC99:::: 	#FF[[AAYFF6]]F? 	; OOE6::ME6f}r%   c                     | j         | j        fD ]C}t          j                            |          rt          j                            |          s dS DdS )NFT)r@   rM   ospathexistsisdir)r"   folders     r#   rO   zOxfordIIITPet._check_exists{   sZ    *D,=> 	 	FGNN6** rw}}V/D/D uu 4r%   c                     |                                  rd S | j        D ])\  }}t          |t          | j                  |           *d S )N)download_rootmd5)rO   
_RESOURCESr
   rF   rL   )r"   urlrz   s      r#   rN   zOxfordIIITPet._download   sb     	F 	] 	]HC(C@Q<R<RX[\\\\\	] 	]r%   )r   r   NNNF)rg   N)__name__
__module____qualname____doc__r{   r   r   rF   rJ   rK   r   r   r   boolrI   rV   ri   rn   r   rq   rO   rN   __classcell__)rf   s   @r#   r   r      sh        .J J
  2<)-(,/33W 3WC%&3W 3W HSM3./	3W
 X&3W H%3W #8,3W 3W 3W 3W 3W 3W 3Wj! ! ! ! !s uS#X    0t    ] ] ] ] ] ] ] ]r%   r   )rs   os.pathrJ   collections.abcr   typingr   r   r   r   PILr   utilsr
   r   visionr   r   r;   r%   r#   <module>r      s    				   $ $ $ $ $ $ 1 1 1 1 1 1 1 1 1 1 1 1       ? ? ? ? ? ? ? ? ! ! ! ! ! !z] z] z] z] z]M z] z] z] z] z]r%   