
    h                     v    d dl Zd dlmZ d dl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y)    N)Path)AnyCallableOptionalUnion   )_Image_fromarray   )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 cb545d371d2ce14ec121470795a77432Nroot	transformtarget_transformdownloadreturnc                    t         |   |||       |r| j                          | j                         st	        d      t
        j                  j                  | j                  | j                        }t        j                  |      }|d d d df   dz  j                  d      | _        t        j                  | j                  d      | _        t        j                  |d d dd f         d   | _        y )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          Z/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/torchvision/datasets/semeion.pyr   zSEMEION.__init__    s     	EUVMMO$$&ijjWW\\$))T]]3zz"~ !TcT']S(009	JJtyy,7	jjag/2    indexc                     | j                   |   t        | j                  |         }}t        |d      }| j                  | j	                  |      }| 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	   r   r   )r+   r0   imgtargets       r.   __getitem__zSEMEION.__getitem__7   sp     ii&DKK,>(?V s->>%..%C  ,**62FF{r/   c                 ,    t        | j                        S N)lenr'   )r+   s    r.   __len__zSEMEION.__len__M   s    499~r/   c                     | j                   }t        j                  j                  || j                        }t        || j                        syy)NFT)r   r    r!   r"   r#   r   md5_checksum)r+   r   fpaths      r.   r   zSEMEION._check_integrityP   s9    yyT4==1ud&7&78r/   c                     | j                         ry | j                  }t        | j                  || j                  | j
                         y r9   )r   r   r   urlr#   r=   )r+   r   s     r.   r   zSEMEION.downloadW   s6      "yyTXXtT]]D4E4EFr/   )NNT)r   N)__name__
__module____qualname____doc__r@   r#   r=   r   strr   r   r   boolr   r4   tupler   r7   r;   r   r   __classcell__)r-   s   @r.   r   r      s     ZCH5L
 )-/33CI3 H%3 #8,	3
 3 
3. sCx , $ Gr/   r   )os.pathr    pathlibr   typingr   r   r   r   numpyr$   utilsr	   r   r   visionr   r    r/   r.   <module>rP      s-      1 1  $ 0 !PGm PGr/   