o
    ;)i                     @   st   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	 d	eZdS )
    N)Path)AnyCallableOptionalTupleUnion)Image   )check_integritydownload_url)VisionDatasetc                       s   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dZdedeeef fddZdefddZdefddZdddZ  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.dataZ cb545d371d2ce14ec121470795a77432NTroot	transformtarget_transformdownloadreturnc                    s   t  j|||d |r|   |  stdtj| j| j	}t
|}|d d d df d d| _t
| jd| _t
|d d dd f d | _d S )N)r   r   zHDataset not found or corrupted. You can use download=True to download it      Zuint8)   r   r	   )super__init__r   _check_integrityRuntimeErrorospathjoinr   filenamenpZloadtxtZastypedataZreshapeZnonzerolabels)selfr   r   r   r   fpr    	__class__ W/home/app/PyTorch/.pytorch/lib/python3.10/site-packages/torchvision/datasets/semeion.pyr      s   
 $zSEMEION.__init__indexc                 C   sX   | j | t| j| }}tj|dd}| jdur| |}| jdur(| |}||fS )z
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target class.
        L)modeN)r    intr!   r   Z	fromarrayr   r   )r"   r(   imgtargetr&   r&   r'   __getitem__6   s   



zSEMEION.__getitem__c                 C   s
   t | jS N)lenr    )r"   r&   r&   r'   __len__L   s   
zSEMEION.__len__c                 C   s*   | j }tj|| j}t|| jsdS dS )NFT)r   r   r   r   r   r
   md5_checksum)r"   r   Zfpathr&   r&   r'   r   O   s
   zSEMEION._check_integrityc                 C   s*   |   rd S | j}t| j|| j| j d S r/   )r   r   r   urlr   r2   )r"   r   r&   r&   r'   r   V   s   zSEMEION.download)NNT)r   N)__name__
__module____qualname____doc__r3   r   r2   r   strr   r   r   boolr   r+   r   r   r.   r1   r   r   __classcell__r&   r&   r$   r'   r      s.    
r   )Zos.pathr   pathlibr   typingr   r   r   r   r   numpyr   ZPILr   utilsr
   r   Zvisionr   r   r&   r&   r&   r'   <module>   s    