
    ڧgL                         d dl Zd dlmZ d dlmZmZmZmZm	Z	 d dl
Zd dlmZ ddlmZmZ ddlmZ  G d d	e          ZdS )
    N)Path)AnyCallableOptionalTupleUnion)Image   )check_integritydownload_url)VisionDatasetc                        e Zd ZdZdZdZdZ	 	 	 ddeee	f         de
e         d	e
e         d
eddf
 fdZdedeeef         fdZdefdZdefdZddZ xZS )SEMEIONa  `SEMEION <http://archive.ics.uci.edu/ml/datasets/semeion+handwritten+digit>`_ Dataset.

    Args:
        root (str or ``pathlib.Path``): Root directory of dataset where directory
            ``semeion.py`` exists.
        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 from the internet and
            puts it in root directory. If dataset is already downloaded, it is not
            downloaded again.

    zMhttp://archive.ics.uci.edu/ml/machine-learning-databases/semeion/semeion.datazsemeion.data cb545d371d2ce14ec121470795a77432NTroot	transformtarget_transformdownloadreturnc                 $   t                                          |||           |r|                                  |                                 st	          d          t
          j                            | j        | j	                  }t          j        |          }|d d d df         dz                      d          | _        t          j        | j        d          | _        t          j        |d d dd f                   d         | _        d S )N)r   r   zHDataset not found or corrupted. You can use download=True to download it      uint8)   r   r
   )super__init__r   _check_integrityRuntimeErrorospathjoinr   filenamenploadtxtastypedatareshapenonzerolabels)selfr   r   r   r   fpr'   	__class__s          X/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/datasets/semeion.pyr   zSEMEION.__init__   s     	EUVVV 	MMOOO$$&& 	kijjjW\\$)T]33z"~~ !!!TcT']S(0099	Jty,77	jaaag//2    indexc                     | j         |         t          | j        |                   }}t          j        |d          }| j        |                     |          }| j        |                     |          }||fS )z
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target class.
        L)mode)r'   intr*   r	   	fromarrayr   r   )r+   r0   imgtargets       r.   __getitem__zSEMEION.__getitem__6   sx     i&DK,>(?(?V oc,,,>%..%%C ,**622FF{r/   c                 *    t          | j                  S )N)lenr'   )r+   s    r.   __len__zSEMEION.__len__L   s    49~~r/   c                     | j         }t          j                            || j                  }t          || j                  sdS dS )NFT)r   r    r!   r"   r#   r   md5_checksum)r+   r   fpaths      r.   r   zSEMEION._check_integrityO   s?    yT4=11ud&788 	5tr/   c                     |                                  rt          d           d S | j        }t          | j        || j        | j                   d S )Nz%Files already downloaded and verified)r   printr   r   urlr#   r=   )r+   r   s     r.   r   zSEMEION.downloadV   sR      "" 	9:::FyTXtT]D4EFFFFFr/   )NNT)r   N)__name__
__module____qualname____doc__rA   r#   r=   r   strr   r   r   boolr   r4   r   r   r8   r;   r   r   __classcell__)r-   s   @r.   r   r      s(         ZCH5L
 )-/33 3CI3 H%3 #8,	3
 3 
3 3 3 3 3 3. sCx    ,    $    G G G G G G G Gr/   r   )os.pathr    pathlibr   typingr   r   r   r   r   numpyr$   PILr	   utilsr   r   visionr   r    r/   r.   <module>rQ      s           8 8 8 8 8 8 8 8 8 8 8 8 8 8           0 0 0 0 0 0 0 0 ! ! ! ! ! !PG PG PG PG PGm PG PG PG PG PGr/   