
    QЦi                     ~    S SK r S SKrS SKJrJrJrJrJrJr  S SK	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)AnyCallableListOptionalTupleUnion)urlparse)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\\   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\4S jrSrU =r$ )CLEVRClassification   aT  `CLEVR <https://cs.stanford.edu/people/jcjohns/clevr/>`_  classification dataset.

The number of objects in a scene are used as label.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset where directory ``root/clevr`` exists or will be saved to if download is
        set to True.
    split (string, optional): The dataset split, supports ``"train"`` (default), ``"val"``, or ``"test"``.
    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 them 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.
z3https://dl.fbaipublicfiles.com/clevr/CLEVR_v1.0.zip b11922020e72d0cd9154779b2d3d07d2Nrootsplit	transformtarget_transformdownloadreturnc                   > [        USS5      U l        [        TU ]  XUS9  [        R
                  " U R                  5      S-  U l        U R                  [        R
                  " [        U R                  5      R                  5      R                  -  U l        U(       a  U R                  5         U R                  5       (       d  [        S5      e[!        U R                  R#                  SU R                  5      R%                  S5      5      U l        U   U R                  S:w  a  [)        U R                  S	-  S
U R                   S3-  5       n[*        R,                  " U5      nS S S 5        WS	    Vs0 s H  oS   [/        US   5      _M     n	nU R&                   V
s/ s H  oU
R0                     PM     sn
U l        g S /[/        U R&                  5      -  U l        g ! , (       d  f       N= fs  snf s  sn
f )Nr   )trainvaltest)r   r   clevrzHDataset not found or corrupted. You can use download=True to download itimages*r   scenesCLEVR_z_scenes.jsonimage_filenameobjects)r   _splitsuper__init__pathlibPathr   _base_folderr	   _URLpathstem_data_folder	_download_check_existsRuntimeErrorsortedjoinpathglob_image_filesopenjsonloadlenname_labels)selfr   r   r   r   r   filecontentscenenum_objects
image_file	__class__s              Y/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/datasets/clevr.pyr&   CLEVRClassification.__init__   s    %UG5MNEUV#LL3g= --Xdii=P=U=U0V0[0[[NN!!##ijj"4#4#4#=#=h#T#Y#YZ]#^_;;& d''(2vdkk],5WWX\`))D/ YW^_gWhiWhe!12Ci8H4IIWhKiKOK\K\]K\Z
8K\]DL 6C(9(9$::DL YXi]s   G4G0G5
G-c                 ,    [        U R                  5      $ N)r8   r4   r;   s    rB   __len__CLEVRClassification.__len__=   s    4$$%%    idxc                    U R                   U   nU R                  U   n[        R                  " U5      R	                  S5      nU R
                  (       a  U R                  U5      nU R                  (       a  U R                  U5      nXC4$ )NRGB)r4   r:   r
   r5   convertr   r   )r;   rJ   r@   labelimages        rB   __getitem__CLEVRClassification.__getitem__@   so    &&s+
S!

:&..u5>>NN5)E  ))%0E|rI   c                 x    U R                   R                  5       =(       a    U R                   R                  5       $ rE   )r-   existsis_dirrF   s    rB   r/   !CLEVRClassification._check_existsN   s+      '')Hd.?.?.F.F.HHrI   c                     U R                  5       (       a  g [        U R                  [        U R                  5      U R
                  S9  g )N)md5)r/   r   r*   strr)   _MD5rF   s    rB   r.   CLEVRClassification._downloadQ   s3    $TYYD4E4E0FDIIVrI   c                      SU R                    3$ )Nzsplit=)r$   rF   s    rB   
extra_reprCLEVRClassification.extra_reprW   s    }%%rI   )r)   r-   r4   r:   r$   )r   NNF)r   N)__name__
__module____qualname____firstlineno____doc__r*   rY   r   rX   r'   r(   r   r   boolr&   intrG   r   r   rP   r/   r.   r\   __static_attributes____classcell__)rA   s   @rB   r   r      s     AD-D
 (,/3;C%&; ; H%	;
 #8,; ; 
; ;<& &s uS#X It IW&C & &rI   r   )r6   r'   typingr   r   r   r   r   r   urllib.parser	   PILr
   utilsr   r   visionr   r    rI   rB   <module>rm      s+      > > !  ? !L&- L&rI   