
    ڧgh                         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	e          Zd
S )    )Path)AnyCallableOptionalTupleUnion)Image   )find_classesmake_dataset)download_and_extract_archiveverify_str_arg)VisionDatasetc                        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ZdefdZd Zdedeeef         fdZdefd Z x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.tgz fe2fc210e6bb7c5664d602c3cd71e612)z>https://s3.amazonaws.com/fast-ai-imageclas/imagenette2-320.tgz 3df6f0d01a2c9592104656642f5e78a3)z>https://s3.amazonaws.com/fast-ai-imageclas/imagenette2-160.tgz e793b78cc4c9e9a4ccc0c1155377a412full320px160px)tenchzTinca tinca)zEnglish springerzEnglish springer spaniel)zcassette player)z	chain sawchainsaw)churchzchurch building)zFrench hornhorn)zgarbage truckdustcart)zgas pumpzgasoline pumpzpetrol pumpzisland dispenser)z	golf ball)	parachutechute)
	n01440764	n02102040	n02979186	n03000684	n03028079	n03394916	n03417042	n03425413	n03445777	n03888257trainr   FNrootsplitsize	transformtarget_transformreturnc                     t                                          |||           t          |dddg           _        t          |dg d           _         j         j                 \   _         _        t           j	                  t           j                  j
        z   _        t           j         j        z             _        |r                                  n#                                 st!          d          t#           j                  \   _         _         fd j        D              _         fd	 j                                        D              _        t/           j         j        d
           _        d S )N)r.   r/   r,   r*   valr-   r   z<Dataset not found. You can use download=True to download it.c                 *    g | ]}j         |         S  _WNID_TO_CLASS).0wnidselfs     [/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/datasets/imagenette.py
<listcomp>z'Imagenette.__init__.<locals>.<listcomp>I   s!    IIId+D1III    c                 <    i | ]\  }}j         |         D ]}||S r4   r5   )r7   r8   idx
class_namer9   s       r:   
<dictcomp>z'Imagenette.__init__.<locals>.<dictcomp>J   sJ     
 
 
 )cX\XklpXq
 
JTJ
 
 
 
r<   z.jpeg)
extensions)super__init__r   _split_size	_ARCHIVES_url_md5r   r+   stem
_size_rootstr_image_root	_download_check_existsRuntimeErrorr   wnidswnid_to_idxclassesitemsclass_to_idxr   _samples)r9   r+   r,   r-   downloadr.   r/   	__class__s   `      r:   rC   zImagenette.__init__1   s{    	EUVVV$UGgu5EFF#D&2L2L2LMM
#~dj9	49ty//DOO,@@t<== 	_NN##%% 	_]^^^'3D4D'E'E$
D$IIIIdjIII
 
 
 
-1-=-C-C-E-E
 
 
 %T%5t7GT[\\\r<   c                 4    | j                                         S N)rJ   existsr9   s    r:   rN   zImagenette._check_existsO   s    %%'''r<   c                     |                                  rt          d| j         d          t          | j        | j        | j                   d S )NzThe directory z[ already exists. If you want to re-download or re-extract the images, delete the directory.)md5)rN   rO   rJ   r   rG   r+   rH   r[   s    r:   rM   zImagenette._downloadR   sg     	^ ^ ^ ^  
 	%TY	tyIIIIIIr<   r>   c                     | j         |         \  }}t          j        |                              d          }| j        |                     |          }| j        |                     |          }||fS )NRGB)rU   r	   openconvertr.   r/   )r9   r>   pathlabelimages        r:   __getitem__zImagenette.__getitem__[   sn    mC(e
4  ((//>%NN5))E ,))%00Ee|r<   c                 *    t          | j                  S rY   )lenrU   r[   s    r:   __len__zImagenette.__len__g   s    4=!!!r<   )r*   r   FNN)__name__
__module____qualname____doc__rF   r6   r   rK   r   r   r   rC   boolrN   rM   intr   r   re   rh   __classcell__)rW   s   @r:   r   r      sm        ( sww I .E).2,2U#+ N  (,/3] ]CI] ] 	] H%] #8,] 
] ] ] ] ] ]<(t ( ( ( (J J J
s 
uS#X 
 
 
 
" " " " " " " " "r<   r   N)pathlibr   typingr   r   r   r   r   PILr	   folderr   r   utilsr   r   visionr   r   r4   r<   r:   <module>rv      s          8 8 8 8 8 8 8 8 8 8 8 8 8 8       . . . . . . . . ? ? ? ? ? ? ? ? ! ! ! ! ! !]" ]" ]" ]" ]" ]" ]" ]" ]" ]"r<   