
    ڧg                         d dl Zd dlZd dlmZ d dlmZmZmZm	Z	m
Z
 d dlZd dlmZ ddlmZmZ ddlmZ  G d d	e          Z G d
 de          ZdS )    N)Path)AnyCallableOptionalTupleUnion)Image   )check_integritydownload_and_extract_archive)VisionDatasetc                   
    e Zd ZdZdZdZdZdZddgdd	gd
dgddgddggZddggZ	ddddZ
	 	 	 	 d'deeef         dedee         dee         deddf fdZd(d Zd!edeeef         fd"Zdefd#Zdefd$Zd(d%Zdefd&Z xZS ))CIFAR10ab  `CIFAR10 <https://www.cs.toronto.edu/~kriz/cifar.html>`_ Dataset.

    Args:
        root (str or ``pathlib.Path``): Root directory of dataset where directory
            ``cifar-10-batches-py`` exists or will be saved to if download is set to True.
        train (bool, optional): If True, creates dataset from training set, otherwise
            creates from test set.
        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.
        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.

    zcifar-10-batches-pyz7https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gzzcifar-10-python.tar.gz c58f30108f718f92721af3b95e74349adata_batch_1 c99cafc152244af753f735de768cd75fdata_batch_2 d4bba439e000b95fd0a9bffe97cbabecdata_batch_3 54ebc095f3ab1f0389bbae665268c751data_batch_4 634d18415352ddfa80567beed471001adata_batch_5 482c414d41f54cd18b22e5b47cb7c3cb
test_batch 40351d587109b95175f43aff81a1287ezbatches.metalabel_names 5ff9c542aee3614f3951f8cda6e48888filenamekeymd5TNFroottrain	transformtarget_transformdownloadreturnc                    t                                          |||           || _        |r|                                  |                                 st          d          | j        r| j        }n| j        }g | _        g | _	        |D ]\  }}t          j                            | j        | j        |          }	t          |	d          5 }
t!          j        |
d          }| j                            |d                    d|v r!| j	                            |d                    n | j	                            |d                    d d d            n# 1 swxY w Y   t)          j        | j                                      d	d
dd          | _        | j                            d          | _        |                                  d S )N)r%   r&   zHDataset not found or corrupted. You can use download=True to download itrblatin1encodingdatalabelsfine_labels       )r      r2   r
   )super__init__r$   r'   _check_integrityRuntimeError
train_list	test_listr.   targetsospathjoinr#   base_folderopenpickleloadappendextendnpvstackreshape	transpose
_load_meta)selfr#   r$   r%   r&   r'   downloaded_list	file_namechecksum	file_pathfentry	__class__s               V/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/datasets/cifar.pyr6   zCIFAR10.__init__4   s    	EUVVV
 	MMOOO$$&& 	kijjj: 	-"oOO"nO	 $3 	> 	>IxTY0@)LLIi&& >!A999	  v///u$$L''h8888L''m(<===> > > > > > > > > > > > > > > Idi((00QB??	I''55	s   A<EE	E	c                    t           j                            | j        | j        | j        d                   }t          || j        d                   st          d          t          |d          5 }t          j
        |d          }|| j        d                  | _        d d d            n# 1 swxY w Y   d t          | j                  D             | _        d S )	Nr    r"   zVDataset metadata file not found or corrupted. You can use download=True to download itr*   r+   r,   r!   c                     i | ]\  }}||	S  rU   ).0i_classs      rR   
<dictcomp>z&CIFAR10._load_meta.<locals>.<dictcomp>f   s    PPP91fVQPPP    )r<   r=   r>   r#   r?   metar   r8   r@   rA   rB   classes	enumerateclass_to_idx)rJ   r=   infiler.   s       rR   rI   zCIFAR10._load_meta_   s    w||DIt'7:9NOOtTYu%566 	ywxxx$ 	2;v999D	% 01DL	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 QP	$,8O8OPPPs   1/B,,B03B0indexc                     | j         |         | j        |         }}t          j        |          }| j        |                     |          }| j        |                     |          }||fS )z
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target class.
        )r.   r;   r	   	fromarrayr%   r&   )rJ   r`   imgtargets       rR   __getitem__zCIFAR10.__getitem__h   sk     i&U(;V oc"">%..%%C ,**622FF{rZ   c                 *    t          | j                  S )N)lenr.   rJ   s    rR   __len__zCIFAR10.__len__~   s    49~~rZ   c                     | j         | j        z   D ]C\  }}t          j                            | j        | j        |          }t          ||          s dS DdS )NFT)r9   r:   r<   r=   r>   r#   r?   r   )rJ   r    r"   fpaths       rR   r7   zCIFAR10._check_integrity   s]    !_t~= 	 	MHcGLLD,<hGGE"5#.. uutrZ   c                     |                                  rt          d           d S t          | j        | j        | j        | j                   d S )Nz%Files already downloaded and verified)r    r"   )r7   printr   urlr#   r    tgz_md5rh   s    rR   r'   zCIFAR10.download   sQ      "" 	9:::F$TXty4=VZVbccccccrZ   c                 &    | j         du rdnd}d| S )NTTrainTestzSplit: )r$   )rJ   splits     rR   
extra_reprzCIFAR10.extra_repr   s%    :--6    rZ   )TNNF)r(   N)__name__
__module____qualname____doc__r?   rn   r    ro   r9   r:   r[   r   strr   boolr   r   r6   rI   intr   r   re   ri   r7   r'   rt   __classcell__)rQ   s   @rR   r   r      s        " (K
CC'H0G	;<	;<	;<	;<	;<J 
9:I #1 D (,/3) )CI) ) H%	)
 #8,) ) 
) ) ) ) ) )VQ Q Q Q sCx    ,    $    d d d d!C ! ! ! ! ! ! ! !rZ   r   c                   B    e Zd ZdZdZdZdZdZddggZdd	ggZ	d
dddZ
dS )CIFAR100zy`CIFAR100 <https://www.cs.toronto.edu/~kriz/cifar.html>`_ Dataset.

    This is a subclass of the `CIFAR10` Dataset.
    zcifar-100-pythonz8https://www.cs.toronto.edu/~kriz/cifar-100-python.tar.gzzcifar-100-python.tar.gz eb9058c3a382ffc7106e4002c42a8d85r$    16019d7e3df5f24257cddd939b257f8dtest f0ef6b0ae62326f3e7ffdfab6717acfcr[   fine_label_names 7973b15100ade9c7d40fb424638fde48r   N)ru   rv   rw   rx   r?   rn   r    ro   r9   r:   r[   rU   rZ   rR   r~   r~      sg         
 %K
DC(H0G	45J
 
34I !1 DDDrZ   r~   )os.pathr<   rA   pathlibr   typingr   r   r   r   r   numpyrE   PILr	   utilsr   r   visionr   r   r~   rU   rZ   rR   <module>r      s           8 8 8 8 8 8 8 8 8 8 8 8 8 8           @ @ @ @ @ @ @ @ ! ! ! ! ! !C! C! C! C! C!m C! C! C!L    w     rZ   