
    Ph                     z    d dl Z d dlZd dl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)urlparse)Image   )download_and_extract_archiveverify_str_arg)VisionDatasetc                        e Zd ZdZdZdZ	 	 	 	 ddededee   dee   d	e	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 )CLEVRClassificationap  `CLEVR <https://cs.stanford.edu/people/jcjohns/clevr/>`_  classification dataset.

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

    Args:
        root (string): 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 an 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                    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   t/        |d          }	}| j&                  D 
cg c]  }
|	|
j0                      c}
| _        y d gt/        | j&                        z  | _        y # 1 sw Y   wxY wc c}w c c}
w )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              eC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\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/ YW^_gWhiWhe5!12Ci8H4IIWhKiKOK\K\]K\ZK
8K\]DL 6C(9(9$::DL YXi]s   G*GG"Gc                 ,    t        | j                        S N)r6   r2   r9   s    r@   __len__zCLEVRClassification.__len__=   s    4$$%%    idxc                    | j                   |   }| j                  |   }t        j                  |      j	                  d      }| j
                  r| j                  |      }| j                  r| j                  |      }||fS )NRGB)r2   r8   r	   r3   convertr   r   )r9   rF   r>   labelimages        r@   __getitem__zCLEVRClassification.__getitem__@   sq    &&s+
S!

:&..u5>>NN5)E  ))%0Ee|rE   c                 n    | j                   j                         xr | j                   j                         S rB   )r+   existsis_dirrC   s    r@   r-   z!CLEVRClassification._check_existsN   s+      '')Hd.?.?.F.F.HHrE   c                     | j                         ry t        | j                  t        | j                        | j
                         y )N)md5)r-   r   r(   strr'   _MD5rC   s    r@   r,   zCLEVRClassification._downloadQ   s0    $TYYD4E4E0FDIIVrE   c                      d| j                    S )Nzsplit=)r"   rC   s    r@   
extra_reprzCLEVRClassification.extra_reprW   s    }%%rE   )r   NNF)r   N)__name__
__module____qualname____doc__r(   rS   rR   r   r   boolr$   intrD   r   r   rL   r-   r,   rU   __classcell__)r?   s   @r@   r   r      s     AD-D
 (,/3;; ; H%	;
 #8,; ; 
;<& &s uS#X It IW&C &rE   r   )r4   r%   typingr   r   r   r   r   urllib.parser   PILr	   utilsr   r   visionr   r    rE   r@   <module>rc      s+      7 7 !  ? !L&- L&rE   