
    ڧg7                         d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlmZ ddlmZmZmZmZ ddlmZ  G d d	e          Zd
S )    join)Path)AnyCallableListOptionalTupleUnion)Image   )check_integritydownload_and_extract_archivelist_dir
list_files)VisionDatasetc                        e Zd ZdZdZdZ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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 )Omniglota  `Omniglot <https://github.com/brendenlake/omniglot>`_ Dataset.

    Args:
        root (str or ``pathlib.Path``): Root directory of dataset where directory
            ``omniglot-py`` exists.
        background (bool, optional): If True, creates dataset from the "background" set, otherwise
            creates from the "evaluation" set. This terminology is defined by the authors.
        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 zip files from the internet and
            puts it in root directory. If the zip files are already downloaded, they are not
            downloaded again.
    zomniglot-pyzDhttps://raw.githubusercontent.com/brendenlake/omniglot/master/python 68d2efa1b9178cc56df9314c21c6e718 6b91aef0f799c5bb55b94e3f2daec811)images_backgroundimages_evaluationTNFroot
background	transformtarget_transformdownloadreturnc                 L    t                                          t          | j                  ||           | _        |r                                                                   st          d          t           j         	                                           _
        t           j
                   _        t           fd j        D             g            _         fdt           j                  D              _        t           j        g            _        d S )N)r   r   zHDataset not found or corrupted. You can use download=True to download itc              3   v   K   | ]2fd t          t          j                            D             V  3dS )c                 0    g | ]}t          |          S  r   ).0cas     Y/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/datasets/omniglot.py
<listcomp>z/Omniglot.__init__.<locals>.<genexpr>.<listcomp>7   s!    HHHQd1ajjHHH    N)r   r   target_folder)r#   r%   selfs    @r&   	<genexpr>z$Omniglot.__init__.<locals>.<genexpr>7   sN      bbQHHHH(40BA+F+F"G"GHHHbbbbbbr(   c           	      v    g | ]4\  }fd t          t          j        |          d          D             5S )c                     g | ]}|fS r"   r"   )r#   imageidxs     r&   r'   z0Omniglot.__init__.<locals>.<listcomp>.<listcomp>:   s    ___eeS\___r(   z.png)r   r   r)   )r#   	characterr/   r*   s     @r&   r'   z%Omniglot.__init__.<locals>.<listcomp>9   s[     "
 "
 "
Y `___z$t7I92U2UW]'^'^___"
 "
 "
r(   )super__init__r   folderr   r   _check_integrityRuntimeErrorr   _get_target_folderr)   r   
_alphabetssum_characters	enumerate_character_images_flat_character_images)r*   r   r   r   r   r   	__class__s   `     r&   r2   zOmniglot.__init__#   s)    	dDK00IXhiii$ 	MMOOO$$&& 	kijjj!$)T-D-D-F-FGG"4#566&)bbbbRVRabbbdf'
 '
"
 "
 "
 "
"+D,<"="="
 "
 "
 >AAWY[=\=\###r(   c                 *    t          | j                  S )N)lenr<   r*   s    r&   __len__zOmniglot.__len__?   s    4.///r(   indexc                 .   | j         |         \  }}t          | j        | j        |         |          }t	          j        |d                              d          }| j        r|                     |          }| j        r|                     |          }||fS )z
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target character class.
        r)modeL)	r<   r   r)   r9   r   openconvertr   r   )r*   rB   
image_namecharacter_class
image_pathr.   s         r&   __getitem__zOmniglot.__getitem__B   s     '+&A%&H#
O$,d.>.OQ[\\

:C00088==> 	*NN5))E  	E"33ODDOo%%r(   c                     |                                  }t          t          | j        |dz             | j        |                   sdS dS )N.zipFT)r6   r   r   r   zips_md5)r*   zip_filenames     r&   r4   zOmniglot._check_integrityV   sH    ..00tDI|f/DEEt}UaGbcc 	5tr(   c                     |                                  rt          d           d S |                                 }|dz   }| j        dz   |z   }t	          || j        || j        |                    d S )Nz%Files already downloaded and verifiedrN   /)filenamemd5)r4   printr6   download_url_prefixr   r   rO   )r*   rS   rP   urls       r&   r   zOmniglot.download\   s      "" 	9:::F**,,&(&,|;$S$)lPTP]^fPghhhhhhr(   c                     | j         rdndS )Nr   r   )r   r@   s    r&   r6   zOmniglot._get_target_folderf   s    &*oN"";NNr(   )TNNF)r   N)__name__
__module____qualname____doc__r3   rV   rO   r   strr   boolr	   r   r2   intrA   r
   r   rL   r4   r   r6   __classcell__)r=   s   @r&   r   r      so          F`?? H  (,/3] ]CI] ] H%	]
 #8,] ] 
] ] ] ] ] ]80 0 0 0 0& &sCx & & & &($    i i i iOC O O O O O O O Or(   r   N)os.pathr   pathlibr   typingr   r   r   r	   r
   r   PILr   utilsr   r   r   r   visionr   r   r"   r(   r&   <module>rg      s                > > > > > > > > > > > > > > > >       V V V V V V V V V V V V ! ! ! ! ! !\O \O \O \O \O} \O \O \O \O \Or(   