
    kh                     ~    d dl Z d dlZd dlmZmZmZmZmZmZ d dl	m
Z
 ddlmZ ddlmZmZ ddlmZ  G d d	e      Zy)
    N)AnyCallableListOptionalTupleUnion)urlparse   )default_loader)download_and_extract_archiveverify_str_arg)VisionDatasetc                        e Zd ZdZdZdZddddefdeee	j                  f   ded	ee   d
ee   dedeeee	j                  f   gef   dd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defdZ xZS )CLEVRClassificationa  `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 or torch.Tensor, depends on the given loader,
            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.
        loader (callable, optional): A function to load an image given its path.
            By default, it uses PIL as its image loader, but users could also pass in
            ``torchvision.io.decode_image`` for decoding image data into tensors directly.
    z3https://dl.fbaipublicfiles.com/clevr/CLEVR_v1.0.zip b11922020e72d0cd9154779b2d3d07d2trainNFrootsplit	transformtarget_transformdownloadloaderreturnc                    t        |dd      | _        t        |   |||       || _        t        j                  | j                        dz  | _        | j                  t        j                  t        | j                        j                        j                  z  | _        |r| j                          | j                         st!        d      t#        | j                  j%                  d| j                        j'                  d            | _        |  | j                  dk7  rt+        | j                  d	z  d
| j                   dz        5 }t-        j.                  |      }d d d        d	   D 	ci c]  }	|	d   t1        |	d          }
}	| j(                  D cg c]  }|
|j2                      c}| _        y d gt1        | j(                        z  | _        y # 1 sw Y   wxY wc c}	w c c}w )Nr   )r   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__r   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   r   filecontentscenenum_objects
image_file	__class__s               V/var/www/teggl/fontify/venv/lib/python3.12/site-packages/torchvision/datasets/clevr.pyr&   z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/*W^_gWhie5!12Ci8H4IIiKiKOK\K\]ZK
8]DL 6C(9(9$::DL* *i]s   G1G$G)G!c                 ,    t        | j                        S N)r8   r4   r;   s    rB   __len__zCLEVRClassification.__len__B   s    4$$%%    idxc                     | j                   |   }| j                  |   }| j                  |      }| j                  r| j                  |      }| j                  r| j	                  |      }||fS rD   )r4   r:   r   r   r   )r;   rH   r@   labelimages        rB   __getitem__zCLEVRClassification.__getitem__E   sf    &&s+
S!J'>>NN5)E  ))%0Ee|rG   c                 n    | j                   j                         xr | j                   j                         S rD   )r-   existsis_dirrE   s    rB   r/   z!CLEVRClassification._check_existsS   s+      '')Hd.?.?.F.F.HHrG   c                     | j                         ry t        | j                  t        | j                        | j
                         y )N)md5)r/   r   r*   strr)   _MD5rE   s    rB   r.   zCLEVRClassification._downloadV   s0    $TYYD4E4E0FDIIVrG   c                      d| j                    S )Nzsplit=)r$   rE   s    rB   
extra_reprzCLEVRClassification.extra_repr\   s    }%%rG   )r   N)__name__
__module____qualname____doc__r*   rS   r   r   rR   r'   r(   r   r   boolr   r&   intrF   r   rL   r/   r.   rU   __classcell__)rA   s   @rB   r   r      s    $ AD-D
 (,/3<J;C%&; ; H%	;
 #8,; ; %W\\ 123S89; 
;@& &s uS#X It IW&C &rG   r   )r6   r'   typingr   r   r   r   r   r   urllib.parser	   folderr   utilsr   r   visionr   r    rG   rB   <module>rc      s+      > > ! " ? !Q&- Q&rG   