o
    ôjÚ  ã                   @   sŒ   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	„ d	eƒZG d
d„ deƒZdS )é    N)ÚPath)ÚAnyÚCallableÚOptionalÚTupleÚUnion)ÚImageé   )Úcheck_integrityÚdownload_and_extract_archive)ÚVisionDatasetc                       sô   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d „Zd/d!d"„Zd#edeeef fd$d%„Zdefd&d'„Zdefd(d)„Zd/d*d+„Zdefd,d-„Z‡  ZS )0Ú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.gzZ c58f30108f718f92721af3b95e74349aZdata_batch_1Z c99cafc152244af753f735de768cd75fZdata_batch_2Z d4bba439e000b95fd0a9bffe97cbabecZdata_batch_3Z 54ebc095f3ab1f0389bbae665268c751Zdata_batch_4Z 634d18415352ddfa80567beed471001aZdata_batch_5Z 482c414d41f54cd18b22e5b47cb7c3cbZ
test_batchZ 40351d587109b95175f43aff81a1287ezbatches.metaZlabel_namesZ 5ff9c542aee3614f3951f8cda6e48888©ÚfilenameÚkeyÚmd5TNFÚrootÚtrainÚ	transformÚtarget_transformÚdownloadÚreturnc              	      s  t ƒ j|||d� || _|r|  ¡  |  ¡ stdƒ‚| jr!| j}n| j}g | _g | _	|D ]G\}}t
j | j| j|¡}	t|	dƒ�,}
tj|
dd�}| j |d ¡ d|v r\| j	 |d ¡ n| j	 |d ¡ W d   ƒ n1 snw   Y  q,t | 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ÚlabelsZfine_labelséÿÿÿÿé   é    )r   é   r   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   Zdownloaded_listÚ	file_nameÚchecksumÚ	file_pathÚfÚentry©Ú	__class__© úk/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchvision/datasets/cifar.pyr#   4   s2   	€ú€zCIFAR10.__init__c                 C   s”   t j | j| j| jd ¡}t|| jd ƒstdƒ‚t|dƒ�}t	j
|dd�}|| jd  | _W d   ƒ n1 s8w   Y  d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                 S   s   i | ]\}}||“qS r?   r?   )Ú.0ÚiÚ_classr?   r?   r@   Ú
<dictcomp>f   s    z&CIFAR10._load_meta.<locals>.<dictcomp>)r)   r*   r+   r   r,   Úmetar
   r%   r-   r.   r/   ÚclassesÚ	enumerateZclass_to_idx)r7   r*   Úinfiler   r?   r?   r@   r6   _   s   þzCIFAR10._load_metaÚindexc                 C   sP   | j | | j| }}t |¡}| jdur|  |¡}| jdur$|  |¡}||fS )z–
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target class.
        N)r   r(   r   Ú	fromarrayr   r   )r7   rI   ÚimgÚtargetr?   r?   r@   Ú__getitem__h   s   




zCIFAR10.__getitem__c                 C   s
   t | jƒS )N)Úlenr   ©r7   r?   r?   r@   Ú__len__~   s   
zCIFAR10.__len__c                 C   s>   | j | j D ]\}}tj | j| j|¡}t||ƒs dS qdS )NFT)r&   r'   r)   r*   r+   r   r,   r
   )r7   r   r   Úfpathr?   r?   r@   r$   �   s   
ÿzCIFAR10._check_integrityc                 C   s0   |   ¡ r
tdƒ d S t| j| j| j| jd� d S )Nz%Files already downloaded and verified)r   r   )r$   Úprintr   Úurlr   r   Útgz_md5rO   r?   r?   r@   r   ˆ   s   zCIFAR10.downloadc                 C   s   | j du rdnd}d|› �S )NTÚTrainÚTestzSplit: )r   )r7   Úsplitr?   r?   r@   Ú
extra_reprŽ   s   
zCIFAR10.extra_repr)TNNF)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r,   rS   r   rT   r&   r'   rE   r   Ústrr   Úboolr   r   r#   r6   Úintr   r   rM   rP   r$   r   rX   Ú__classcell__r?   r?   r=   r@   r      sR    û	ÿý	ú
þýüûúù
+	
r   c                   @   s@   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.gzZ eb9058c3a382ffc7106e4002c42a8d85r   Z 16019d7e3df5f24257cddd939b257f8dÚtestZ f0ef6b0ae62326f3e7ffdfab6717acfcrE   Zfine_label_namesZ 7973b15100ade9c7d40fb424638fde48r   N)rY   rZ   r[   r\   r,   rS   r   rT   r&   r'   rE   r?   r?   r?   r@   ra   “   s    ÿÿ
ýra   )Úos.pathr)   r.   Úpathlibr   Útypingr   r   r   r   r   Únumpyr2   ÚPILr   Úutilsr
   r   Úvisionr   r   ra   r?   r?   r?   r@   Ú<module>   s     