
    hp"                        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 d dlmZ ddlmZmZ dd	lmZ d
ddej.                  j1                  dd      ddddej.                  j1                  ddd      ddddej.                  j1                  dd      ddddej.                  j1                  dd      ddddej.                  j1                  dd      dd d!d"ej.                  j1                  dd#      dd$d%d&ej.                  j1                  dd#      dd'Z G d( d)e      Z G d* d+e      Z G d, d-e      Zy# e$ r
 d dl	mZ Y (w xY w).    N)Path)AnyCallableOptionalUnion)Element)parse)Image   )download_and_extract_archiveverify_str_arg)VisionDatasetzJhttp://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tarzVOCtrainval_11-May-2012.tar 6cd6e144f989b92b3379bac3b3de84fd	VOCdevkitVOC2012)urlfilenamemd5base_dirzJhttp://host.robots.ox.ac.uk/pascal/VOC/voc2011/VOCtrainval_25-May-2011.tarzVOCtrainval_25-May-2011.tar 6c3384ef61512963050cb5d687e5bf1eTrainValVOC2011zJhttp://host.robots.ox.ac.uk/pascal/VOC/voc2010/VOCtrainval_03-May-2010.tarzVOCtrainval_03-May-2010.tar da459979d0c395079b5c75ee67908abbVOC2010zJhttp://host.robots.ox.ac.uk/pascal/VOC/voc2009/VOCtrainval_11-May-2009.tarzVOCtrainval_11-May-2009.tar a3e00b113cfcfebf17e343f59da3caa1VOC2009zJhttp://host.robots.ox.ac.uk/pascal/VOC/voc2008/VOCtrainval_14-Jul-2008.tar 2629fa636546599198acfcfbfcf1904aVOC2008zJhttp://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tarzVOCtrainval_06-Nov-2007.tar c52e279531787c972589f7e41ab4ae64VOC2007zFhttp://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tarzVOCtest_06-Nov-2007.tar b6e924de25625d8de591ea690078ad9f)201220112010200920082007	2007-testc                        e Zd ZU eed<   eed<   eed<   	 	 	 	 	 	 ddeeef   dedededee	   d	ee	   d
ee	   f fdZ
defdZ xZS )_VOCBase_SPLITS_DIR_TARGET_DIR_TARGET_FILE_EXTrootyear	image_setdownload	transformtarget_transform
transformsc           
         t         |   ||||       t        |dt        dd      D cg c]  }t	        |       c}      | _        g d}	|dk(  r|	j                  d       t        |d|	      | _        |dk(  r|dk(  rd	n|}
t        |
   }|d
   | _	        |d   | _
        |d   | _        |d   }t        j                  j                  | j                  |      }|r7t!        | j                  | j                  | j                  | j                         t        j                  j#                  |      st%        d      t        j                  j                  |d| j&                        }t        j                  j                  ||j)                  d      dz         }t+        t        j                  j                  |            5 }|j-                         D cg c]  }|j/                          }}d d d        t        j                  j                  |d      }D cg c]%  }t        j                  j                  ||dz         ' c}| _        t        j                  j                  || j2                        }|D cg c]/  }t        j                  j                  ||| j4                  z         1 c}| _        t9        | j0                        t9        | j6                        k(  sJ y c c}w c c}w # 1 sw Y   xY wc c}w c c}w )Nr/   i  i  )valid_values)traintrainvalvalr'   testr0   r(   r   r   r   r   )r   r   zHDataset not found or corrupted. You can use download=True to download it	ImageSets
z.txt
JPEGImagesz.jpg)super__init__r   rangestrr/   appendr0   DATASET_YEAR_DICTr   r   r   ospathjoinr.   r   isdirRuntimeErrorr+   rstripopen	readlinesstripimagesr,   r-   targetslen)selfr.   r/   r0   r1   r2   r3   r4   yrvalid_image_setskeydataset_year_dictr   voc_root
splits_dirsplit_ffx
file_names	image_dir
target_dir	__class__s                        V/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/torchvision/datasets/voc.pyr?   z_VOCBase.__init__D   sW    	z96FG"4QVW[]aQb>c2s2w>cd	76>##F+'	;@PQ!V^	V0Ck-c2$U+)*5$U+$Z077<<		84(499t}}Z^ZbZbcww}}X&ijjWW\\(K9I9IJ
'',,z9+;+;D+AF+JK"'',,w'( 	<A-.[[];!'');J;	< GGLL<8	DNOqrww||Iq6z:OWW\\(D,<,<=
U_`PQZT5J5J1JK`4;;3t||#4444E ?d4 <	< 	< P as/   K" K,K'*K,*K984K>'K,,K6returnc                 ,    t        | j                        S N)rO   rM   rP   s    r^   __len__z_VOCBase.__len__t   s    4;;    )r"   r7   FNNN)__name__
__module____qualname__rA   __annotations__r   r   boolr   r   r?   intrc   __classcell__)r]   s   @r^   r*   r*   ?   s    
  (,/3)-.5CI.5 .5 	.5
 .5 H%.5 #8,.5 X&.5`   rd   r*   c                   R    e Zd ZdZdZdZdZedee	   fd       Z
dedeeef   fdZy	)
VOCSegmentationa2  `Pascal VOC <http://host.robots.ox.ac.uk/pascal/VOC/>`_ Segmentation Dataset.

    Args:
        root (str or ``pathlib.Path``): Root directory of the VOC Dataset.
        year (string, optional): The dataset year, supports years ``"2007"`` to ``"2012"``.
        image_set (string, optional): Select the image_set to use, ``"train"``, ``"trainval"`` or ``"val"``. If
            ``year=="2007"``, can also be ``"test"``.
        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.
        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.
    SegmentationSegmentationClassz.pngr_   c                     | j                   S ra   rN   rb   s    r^   maskszVOCSegmentation.masks       ||rd   indexc                     t        j                  | j                  |         j                  d      }t        j                  | j                  |         }| j
                  | j                  ||      \  }}||fS )z
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is the image segmentation.
        RGB)r
   rJ   rM   convertrr   r4   rP   rt   imgtargets       r^   __getitem__zVOCSegmentation.__getitem__   se     jjU+,44U;DJJu-.??&//#v6KCF{rd   N)re   rf   rg   __doc__r+   r,   r-   propertylistrA   rr   rj   tupler   r{    rd   r^   rm   rm   x   sQ    $ !K%KtCy   sCx rd   rm   c                   v    e Zd ZdZdZdZdZedee	   fd       Z
dedeeef   fdZed	edee	ef   fd
       Zy)VOCDetectionan  `Pascal VOC <http://host.robots.ox.ac.uk/pascal/VOC/>`_ Detection Dataset.

    Args:
        root (str or ``pathlib.Path``): Root directory of the VOC Dataset.
        year (string, optional): The dataset year, supports years ``"2007"`` to ``"2012"``.
        image_set (string, optional): Select the image_set to use, ``"train"``, ``"trainval"`` or ``"val"``. If
            ``year=="2007"``, can also be ``"test"``.
        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.
            (default: alphabetic indexing of VOC's 20 classes).
        transform (callable, optional): A function/transform that takes in a PIL image
            and returns a transformed version. E.g, ``transforms.RandomCrop``
        target_transform (callable, required): 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.
    MainAnnotationsz.xmlr_   c                     | j                   S ra   rq   rb   s    r^   annotationszVOCDetection.annotations   rs   rd   rt   c                    t        j                  | j                  |         j                  d      }| j	                  t        | j                  |         j                               }| j                  | j                  ||      \  }}||fS )z
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is a dictionary of the XML tree.
        rv   )	r
   rJ   rM   rw   parse_voc_xmlET_parser   getrootr4   rx   s       r^   r{   zVOCDetection.__getitem__   sw     jjU+,44U;##HT-=-=e-D$E$M$M$OP??&//#v6KCF{rd   nodec           	         i }t        |       }|rt        j                  t               }t        t        j
                  |      D ].  }|j                         D ]  \  }}||   j                  |        0 | j                  dk(  r	|d   g|d<   | j                  |j                         D ci c]  \  }}|t        |      dk(  r|d   n| c}}i}| j                  r+| j                  j                         }|s||| j                  <   |S c c}}w )N
annotationobjectr   r   )r~   collectionsdefaultdictmapr   r   itemsrB   tagrO   textrL   )r   voc_dictchildrendef_dicdcindvr   s           r^   r   zVOCDetection.parse_voc_xml   s    #%:&1&=&=d&CG,44h? + hhj +FCCL''*++ xx<'%,X%6$7!QXQ^Q^Q`"avsA3A!!#B"abH9999??$D%)" #bs   * DN)re   rf   rg   r|   r+   r,   r-   r}   r~   rA   r   rj   r   r   r{   staticmethod
ET_Elementdictr   r   rd   r^   r   r      s{    & KKT#Y   sCx   J 4S>  rd   r   )r   rD   pathlibr   typingr   r   r   r   xml.etree.ElementTreer   r   defusedxml.ElementTreer	   r   ImportErrorPILr
   utilsr   r   visionr   rE   rF   rC   r*   rm   r   r   rd   r^   <module>r      si    	  1 1 788  ? ! \11GGLLi8	 \11GGLL[)D	 \11GGLLi8	 \11GGLLi8	 \11GGLLi8	 \11GGLLi8	 X-1GGLLi8	K+ \6 } 6 r)h )X<8 <w  8778s   E EE