
    QЦi                         S SK Jr  S SKJr  S SKJrJrJrJrJ	r	J
r
  S SKJr  SSKJrJrJrJr  SSKJr   " S S	\5      rg
)    )join)Path)AnyCallableListOptionalTupleUnion)Image   )check_integritydownload_and_extract_archivelist_dir
list_files)VisionDatasetc                      ^  \ rS rSrSrSrSrSSS.r    SS	\\	\
4   S
\S\\   S\\   S\SS4U 4S jjjrS\4S jrS\S\\\4   4S jrS\4S jrSS jrS\	4S jrSrU =r$ )Omniglot   aL  `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_evaluationNroot
background	transformtarget_transformdownloadreturnc                   >^  [         T	T ]  [        UT R                  5      X4S9  UT l        U(       a  T R                  5         T R                  5       (       d  [        S5      e[        T R                  T R                  5       5      T l
        [        T R                  5      T l        [        U 4S jT R                   5       / 5      T l        [        T R                  5       VVVs/ s H7  u  pg[!        [        T R                  U5      S5       Vs/ s H  oU4PM     snPM9     snnnT l        [        T R"                  / 5      T l        g s  snf s  snnnf )N)r   r   zHDataset not found or corrupted. You can use download=True to download itc              3      >#    U  H>  n[        [        TR                  U5      5       Vs/ s H  n[        X5      PM     snv   M@     g s  snf 7fN)r   r   target_folder).0acselfs      \/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/datasets/omniglot.py	<genexpr>$Omniglot.__init__.<locals>.<genexpr>7   s=     bRaQ(40B0BA+F"GH"GQd1j"GHRaHs   'AA	Az.png)super__init__r   folderr   r   _check_integrityRuntimeErrorr   _get_target_folderr"   r   
_alphabetssum_characters	enumerater   _character_images_flat_character_images)
r&   r   r   r   r   r   idx	characterimage	__class__s
   `        r'   r+   Omniglot.__init__#   s    	dDKK0Ii$MMO$$&&ijj!$))T-D-D-FG"4#5#56&)bRVRaRabdf'

 #,D,<,<"="
"= (2$t7I7I92UW]'^_'^eS\'^_"="
 >AAWAWY[=\# `"
s   $*EEEEc                 ,    [        U R                  5      $ r!   )lenr5   r&   s    r'   __len__Omniglot.__len__?   s    4..//    indexc                 B   U R                   U   u  p#[        U R                  U R                  U   U5      n[        R
                  " USS9R                  S5      nU R                  (       a  U R                  U5      nU R                  (       a  U R                  U5      nXS4$ )zx
Args:
    index (int): Index

Returns:
    tuple: (image, target) where target is index of the target character class.
r)modeL)	r5   r   r"   r2   r   openconvertr   r   )r&   rA   
image_namecharacter_class
image_pathr8   s         r'   __getitem__Omniglot.__getitem__B   s     '+&A&A%&H#
$,,d.>.>.OQ[\


:C088=>>NN5)E  "33ODO%%r@   c                     U R                  5       n[        [        U R                  US-   5      U R                  U   5      (       d  gg)N.zipFT)r/   r   r   r   zips_md5)r&   zip_filenames     r'   r-   Omniglot._check_integrityV   s=    ..0tDII|f/DEt}}UaGbccr@   c                     U R                  5       (       a  g U R                  5       nUS-   nU R                  S-   U-   n[        X0R                  X R
                  U   S9  g )NrN   /)filenamemd5)r-   r/   download_url_prefixr   r   rO   )r&   rT   rP   urls       r'   r   Omniglot.download\   s[      ""**,&(&&,|;$S))lP]P]^fPghr@   c                 ,    U R                   (       a  S$ S$ )Nr   r   )r   r=   s    r'   r/   Omniglot._get_target_foldere   s    &*oo"N;NNr@   )r0   r4   r2   r5   r   r"   )TNNF)r   N)__name__
__module____qualname____firstlineno____doc__r,   rV   rO   r
   strr   boolr   r   r+   intr>   r	   r   rK   r-   r   r/   __static_attributes____classcell__)r9   s   @r'   r   r      s      F`??H  (,/3]CI] ] H%	]
 #8,] ] 
] ]80 0& &sCx &($ iOC O Or@   r   N)os.pathr   pathlibr   typingr   r   r   r   r	   r
   PILr   utilsr   r   r   r   visionr   r    r@   r'   <module>rl      s-      > >  V V ![O} [Or@   