U
    ­Ê¹j  ã                   @   sX   d dl Zd dlmZmZ d dlZd dlZd dlm	Z	m
Z
 d dlmZ G dd„ deƒZdS )é    N)ÚCallableÚOptional)Údownload_urlÚverify_str_arg)ÚVisionDatasetc                       sz   e Zd ZdZdZdeee eeee	 ddœ‡ fdd„Z
eejd	œd
d„Zedœdd„Zedœdd„Zddœdd„Z‡  ZS )ÚMovingMNISTa5  `MovingMNIST <http://www.cs.toronto.edu/~nitish/unsupervised_video/>`_ Dataset.

    Args:
        root (string): Root directory of dataset where ``MovingMNIST/mnist_test_seq.npy`` exists.
        split (string, optional): The dataset split, supports ``None`` (default), ``"train"`` and ``"test"``.
            If ``split=None``, the full data is returned.
        split_ratio (int, optional): The split ratio of number of frames. If ``split="train"``, the first split
            frames ``data[:, :split_ratio]`` is returned. If ``split="test"``, the last split frames ``data[:, split_ratio:]``
            is returned. If ``split=None``, this parameter is ignored and the all frames data is returned.
        transform (callable, optional): A function/transform that takes in an torch Tensor
            and returns a transformed version. E.g, ``transforms.RandomCrop``
        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.
    zGhttp://www.cs.toronto.edu/~nitish/unsupervised_video/mnist_test_seq.npyNé
   F)ÚrootÚsplitÚsplit_ratioÚdownloadÚ	transformÚreturnc                    s&  t ƒ j||d� tj | j| jj¡| _| j	 
d¡d | _|d k	rLt|ddƒ || _
t|tƒsptdt|ƒ› �ƒ‚n&d|  kr„dks–n td	|› d
�ƒ‚|| _|r¨|  ¡  |  ¡ s¸tdƒ‚t t tj | j| j¡¡¡}| j
dkrð|d | j… }n| j
dk�r
|| jd … }| dd¡ d¡ ¡ | _d S )N)r   ú/éÿÿÿÿr
   )ÚtrainÚtestz,`split_ratio` should be an integer, but got é   é   z:`split_ratio` should be `1 <= split_ratio <= 19`, but got z	 instead.z<Dataset not found. You can use download=True to download it.r   r   r   é   )ÚsuperÚ__init__ÚosÚpathÚjoinr	   Ú	__class__Ú__name__Ú_base_folderÚ_URLr
   Ú	_filenamer   Ú
isinstanceÚintÚ	TypeErrorÚtypeÚ
ValueErrorr   r   Ú_check_existsÚRuntimeErrorÚtorchZ
from_numpyÚnpÚloadZ	transposeZ	unsqueezeÚ
contiguousÚdata)Úselfr	   r
   r   r   r   r+   ©r   © ú`/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torchvision/datasets/moving_mnist.pyr      s*    

zMovingMNIST.__init__)Úidxr   c                 C   s"   | j | }| jdk	r|  |¡}|S )z«
        Args:
            index (int): Index
        Returns:
            torch.Tensor: Video frames (torch Tensor[T, C, H, W]). The `T` is the number of frames.
        N)r+   r   )r,   r0   r+   r.   r.   r/   Ú__getitem__A   s    


zMovingMNIST.__getitem__)r   c                 C   s
   t | jƒS ©N)Úlenr+   ©r,   r.   r.   r/   Ú__len__N   s    zMovingMNIST.__len__c                 C   s   t j t j | j| j¡¡S r2   )r   r   Úexistsr   r   r   r4   r.   r.   r/   r%   Q   s    zMovingMNIST._check_existsc                 C   s&   |   ¡ rd S t| j| j| jdd� d S )NZ be083ec986bfe91a449d63653c411eb2)Úurlr	   ÚfilenameÚmd5)r%   r   r   r   r   r4   r.   r.   r/   r   T   s    üzMovingMNIST.download)Nr   FN)r   Ú
__module__Ú__qualname__Ú__doc__r   Ústrr   r!   Úboolr   r   r'   ZTensorr1   r5   r%   r   Ú__classcell__r.   r.   r-   r/   r   
   s$       úù$r   )Úos.pathr   Útypingr   r   Únumpyr(   r'   Ztorchvision.datasets.utilsr   r   Ztorchvision.datasets.visionr   r   r.   r.   r.   r/   Ú<module>   s   