o
    ôjh  ã                   @   st   d dl mZ d dlmZmZmZmZmZ d dlm	Z	 ddl
mZmZ ddlmZmZ ddlmZ G dd	„ d	eƒZd
S )é    )ÚPath)ÚAnyÚCallableÚOptionalÚTupleÚUnion)ÚImageé   )Úfind_classesÚmake_dataset)Údownload_and_extract_archiveÚverify_str_arg)ÚVisionDatasetc                       sº   e Zd ZdZddddœZdddd	d
ddddddœ
Z					d&deeef dedede	e
 de	e
 ddf‡ fdd„Zdefdd„Zdd „ Zd!edeeef fd"d#„Zdefd$d%„Z‡  ZS )'Ú
Imagenettea`  `Imagenette <https://github.com/fastai/imagenette#imagenette-1>`_ image classification dataset.

    Args:
        root (str or ``pathlib.Path``): Root directory of the Imagenette dataset.
        split (string, optional): The dataset split. Supports ``"train"`` (default), and ``"val"``.
        size (string, optional): The image size. Supports ``"full"`` (default), ``"320px"``, and ``"160px"``.
        download (bool, optional): If ``True``, downloads the dataset components and places them in ``root``. Already
            downloaded archives are not downloaded again.
        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.

     Attributes:
        classes (list): List of the class name tuples.
        class_to_idx (dict): Dict with items (class name, class index).
        wnids (list): List of the WordNet IDs.
        wnid_to_idx (dict): Dict with items (WordNet ID, class index).
    )z:https://s3.amazonaws.com/fast-ai-imageclas/imagenette2.tgzZ fe2fc210e6bb7c5664d602c3cd71e612)z>https://s3.amazonaws.com/fast-ai-imageclas/imagenette2-320.tgzZ 3df6f0d01a2c9592104656642f5e78a3)z>https://s3.amazonaws.com/fast-ai-imageclas/imagenette2-160.tgzZ e793b78cc4c9e9a4ccc0c1155377a412©ÚfullZ320pxZ160px)ZtenchzTinca tinca)zEnglish springerzEnglish springer spaniel)zcassette player)z	chain sawZchainsaw)Zchurchzchurch building)zFrench hornZhorn)zgarbage truckZdustcart)zgas pumpzgasoline pumpzpetrol pumpzisland dispenser)z	golf ball)Z	parachuteZchute)
Z	n01440764Z	n02102040Z	n02979186Z	n03000684Z	n03028079Z	n03394916Z	n03417042Z	n03425413Z	n03445777Z	n03888257Útrainr   FNÚrootÚsplitÚsizeÚ	transformÚtarget_transformÚreturnc                    sì   t ƒ j|||d� t|dddgƒˆ _t|dg d¢ƒˆ _ˆ jˆ j \ˆ _ˆ _tˆ j	ƒtˆ jƒj
 ˆ _tˆ jˆ j ƒˆ _|rAˆ  ¡  nˆ  ¡ sItdƒ‚tˆ jƒ\ˆ _ˆ _‡ fdd	„ˆ jD ƒˆ _‡ fd
d„ˆ j ¡ D ƒˆ _tˆ jˆ jdd�ˆ _d S )N)r   r   r   r   Úvalr   r   z<Dataset not found. You can use download=True to download it.c                    s   g | ]}ˆ j | ‘qS © ©Ú_WNID_TO_CLASS)Ú.0Úwnid©Úselfr   úp/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchvision/datasets/imagenette.pyÚ
<listcomp>I   s    z'Imagenette.__init__.<locals>.<listcomp>c                    s&   i | ]\}}ˆ j | D ]}||“qqS r   r   )r   r   ÚidxÚ
class_namer   r   r!   Ú
<dictcomp>J   s
    ÿÿz'Imagenette.__init__.<locals>.<dictcomp>z.jpeg)Ú
extensions)ÚsuperÚ__init__r   Ú_splitÚ_sizeÚ	_ARCHIVESÚ_urlÚ_md5r   r   ÚstemÚ
_size_rootÚstrZ_image_rootÚ	_downloadÚ_check_existsÚRuntimeErrorr
   ÚwnidsÚwnid_to_idxÚclassesÚitemsÚclass_to_idxr   Ú_samples)r    r   r   r   Údownloadr   r   ©Ú	__class__r   r!   r(   1   s    	

ÿzImagenette.__init__c                 C   s
   | j  ¡ S ©N)r/   Úexistsr   r   r   r!   r2   O   ó   
zImagenette._check_existsc                 C   s2   |   ¡ rtd| j› d�ƒ‚t| j| j| jd� d S )NzThe directory z[ already exists. If you want to re-download or re-extract the images, delete the directory.)Úmd5)r2   r3   r/   r   r,   r   r-   r   r   r   r!   r1   R   s
   ÿzImagenette._downloadr#   c                 C   sN   | j | \}}t |¡ d¡}| jd ur|  |¡}| jd ur#|  |¡}||fS )NÚRGB)r9   r   ÚopenÚconvertr   r   )r    r#   ÚpathÚlabelÚimager   r   r!   Ú__getitem__[   s   



zImagenette.__getitem__c                 C   s
   t | jƒS r=   )Úlenr9   r   r   r   r!   Ú__len__g   r?   zImagenette.__len__)r   r   FNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r+   r   r   r0   r   r   r   r(   Úboolr2   r1   Úintr   r   rG   rI   Ú__classcell__r   r   r;   r!   r      sN    ýöù
þýüúùø	r   N)Úpathlibr   Útypingr   r   r   r   r   ÚPILr   Úfolderr
   r   Úutilsr   r   Úvisionr   r   r   r   r   r!   Ú<module>   s    