
    Pha                     r    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mZmZ ddlmZ  G d de      Zy	)
    )join)AnyCallableListOptionalTuple)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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 )Omniglotaq  `Omniglot <https://github.com/brendenlake/omniglot>`_ Dataset.

    Args:
        root (string): 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 an 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        | j                        ||       | _        |r j                           j                         st        d      t         j                   j                                _
        t         j                         _        t         fd j                  D        g        _        t         j                        D cg c]5  \  }}t!        t         j                  |      d      D cg c]  }||f c}7 c}}} _        t         j"                  g        _        y c c}w c c}}}w )N)r   r   zHDataset not found or corrupted. You can use download=True to download itc              3      K   | ];  }t        t        j                  |            D cg c]  }t        ||       c} = y c c}w wN)r   r   target_folder).0acselfs      hC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torchvision/datasets/omniglot.py	<genexpr>z$Omniglot.__init__.<locals>.<genexpr>6   s@     bRaQ(40B0BA+F"GH"GQd1aj"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'   zOmniglot.__init__"   s    	dDKK0IXhi$MMO$$&ijj!$))T-D-D-FG"4#5#56&)bRVRaRabdf'

 #,D,<,<"="
"=Y (2$t7I7I92UW]'^_'^eeS\'^_"="
 >AAWAWY[=\# `"
s   *ED=E=Ec                 ,    t        | j                        S r   )lenr1   r#   s    r$   __len__zOmniglot.__len__>   s    4..//    indexc                 6   | j                   |   \  }}t        | j                  | j                  |   |      }t	        j
                  |d      j                  d      }| j                  r| j                  |      }| j                  r| j                  |      }||fS )z
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target character class.
        r)modeL)	r1   r   r   r.   r	   openconvertr   r   )r#   r;   
image_namecharacter_class
image_pathr4   s         r$   __getitem__zOmniglot.__getitem__A   s     '+&A&A%&H#
O$,,d.>.>.OQ[\


:C088=>>NN5)E  "33ODOo%%r:   c                     | j                         }t        t        | j                  |dz         | j                  |         syy)N.zipFT)r+   r   r   r   zips_md5)r#   zip_filenames     r$   r)   zOmniglot._check_integrityU   s:    ..0tDII|f/DEt}}UaGbcr:   c                     | j                         rt        d       y | j                         }|dz   }| j                  dz   |z   }t	        || j
                  || j                  |          y )Nz%Files already downloaded and verifiedrG   /)filenamemd5)r)   printr+   download_url_prefixr   r   rH   )r#   rL   rI   urls       r$   r   zOmniglot.download[   sf      "9:**,&(&&,|;$S$))lPTP]P]^fPghr:   c                 "    | j                   rdS dS )Nr   r   )r   r8   s    r$   r+   zOmniglot._get_target_foldere   s    &*oo"N;NNr:   )TNNF)r   N)__name__
__module____qualname____doc__r(   rO   rH   strboolr   r   r'   intr9   r   r   rE   r)   r   r+   __classcell__)r5   s   @r$   r   r   
   s      F`??H  (,/3]] ] H%	]
 #8,] ] 
]80 0& &sCx &($ iOC Or:   r   N)os.pathr   typingr   r   r   r   r   PILr	   utilsr   r   r   r   visionr   r    r:   r$   <module>r`      s*     7 7  V V !\O} \Or:   