3
Á3W^ð  ã               @   s`   d dl mZ d dlmZ d dlZd dlZd dlZddlm	Z	 ddl
mZmZ G dd„ de	ƒZdS )	é    )Úprint_function)ÚImageNé   )ÚVisionDataset)Údownload_urlÚcheck_integrityc                   sN   e Zd ZdZdZdZdZd‡ fdd„	Zd	d
„ Zdd„ Z	dd„ Z
dd„ Z‡  ZS )ÚSEMEIONaµ  `SEMEION <http://archive.ics.uci.edu/ml/datasets/semeion+handwritten+digit>`_ Dataset.
    Args:
        root (string): Root directory of dataset where directory
            ``semeion.py`` exists.
        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 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 cb545d371d2ce14ec121470795a77432NTc                s®   t t| ƒj|||d� |r"| jƒ  | jƒ s2td	ƒ‚g | _g | _tj	j
| j| jƒ}tj|ƒ}|d d …d d…f d jdƒ| _tj| jdƒ| _tj|d d …dd …f ƒd | _d S )N)Ú	transformÚtarget_transformzDataset not found or corrupted.z) You can use download=True to download ité   éÿ   Zuint8r   é   zHDataset not found or corrupted. You can use download=True to download itéÿÿÿÿ)r   r   r   )Úsuperr   Ú__init__ÚdownloadÚ_check_integrityÚRuntimeErrorÚdataÚlabelsÚosÚpathÚjoinÚrootÚfilenameÚnpZloadtxtZastypeZreshapeZnonzero)Úselfr   r	   r
   r   Úfpr   )Ú	__class__© úC/tmp/pip-build-7wfi2gtz/torchvision/torchvision/datasets/semeion.pyr      s    
 zSEMEION.__init__c             C   sX   | j | t| j| ƒ }}tj|dd�}| jdk	r<| j|ƒ}| jdk	rP| j|ƒ}||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   ÚindexÚimgÚtargetr   r   r    Ú__getitem__0   s    



zSEMEION.__getitem__c             C   s
   t | jƒS )N)Úlenr   )r   r   r   r    Ú__len__E   s    zSEMEION.__len__c             C   s*   | j }tj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   H   s
    zSEMEION._check_integrityc             C   s2   | j ƒ 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   r   r   r    r   O   s
    zSEMEION.download)NNT)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r,   r   r*   r   r'   r)   r   r   Ú__classcell__r   r   )r   r    r   
   s   r   )Ú
__future__r   ZPILr   r   Úos.pathZnumpyr   Zvisionr   Úutilsr   r   r   r   r   r   r    Ú<module>   s   