U
    Ð‹ÑhL  ã                   @   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eee	f e
e e
e eddœ‡ fdd	„Zeeeef d
œdd„Zedœdd„Zedœdd„Zd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__© úJ/tmp/user/2202/pip-unpacked-wheel-mjxxo1pc/torchvision/datasets/semeion.pyr      s    
 zSEMEION.__init__)Úindexr   c                 C   sX   | j | t| j| ƒ }}tj|dd�}| jdk	r<|  |¡}| jdk	rP|  |¡}||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__)r   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   s2   |   ¡ rtdƒ d S | j}t| j|| j| jƒ d S )Nz%Files already downloaded and verified)r   Úprintr   r   Úurlr   r1   )r"   r   r&   r&   r'   r   V   s
    zSEMEION.download)NNT)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r3   r   r1   r   Ústrr   r   r   Úboolr   r+   r   r   r.   r0   r   r   Ú__classcell__r&   r&   r$   r'   r      s$      û
úr   )Úos.pathr   Úpathlibr   Útypingr   r   r   r   r   Znumpyr   ZPILr   Úutilsr
   r   Zvisionr   r   r&   r&   r&   r'   Ú<module>   s   