o
    Vh<                     @   sh   d dl Zd dlmZ d dlmZ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)Path)CallableOptionalUnion)download_urlverify_str_arg)VisionDatasetc                       s   e Zd ZdZdZ				ddeeef dee de	d	e
d
ee ddf fddZde	dejfddZde	fddZde
fddZdddZ  ZS )MovingMNISTaE  `MovingMNIST <http://www.cs.toronto.edu/~nitish/unsupervised_video/>`_ Dataset.

    Args:
        root (str or ``pathlib.Path``): 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.
        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.
        transform (callable, optional): A function/transform that takes in a torch Tensor
            and returns a transformed version. E.g, ``transforms.RandomCrop``
    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 ur&t|dd || _
t|ts7tdt| d|  krAdksJn td	| d
|| _|rS|   |  s[tdtttj| j| j}| j
dkrw|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torch
from_numpynpload	transpose	unsqueeze
contiguousdata)selfr   r   r   r   r   r0   r    U/var/www/vscode/kcb/lib/python3.10/site-packages/torchvision/datasets/moving_mnist.pyr      s*   


zMovingMNIST.__init__idxc                 C   s"   | j | }| jdur| |}|S )z
        Args:
            idx (int): Index
        Returns:
            torch.Tensor: Video frames (torch Tensor[T, C, H, W]). The `T` is the number of frames.
        N)r0   r   )r1   r5   r0   r3   r3   r4   __getitem__B   s   


zMovingMNIST.__getitem__c                 C   s
   t | jS N)lenr0   r1   r3   r3   r4   __len__O   s   
zMovingMNIST.__len__c                 C   s   t jt j| j| jS r7   )r   r   existsr   r   r!   r9   r3   r3   r4   r'   R   s   zMovingMNIST._check_existsc                 C   s&   |   rd S t| j| j| jdd d S )N be083ec986bfe91a449d63653c411eb2)urlr   filenamemd5)r'   r   r    r   r!   r9   r3   r3   r4   r   U   s   
zMovingMNIST.download)Nr
   FN)r   N)r   
__module____qualname____doc__r    r   strr   r   r#   boolr   r   r)   Tensorr6   r:   r'   r   __classcell__r3   r3   r2   r4   r	      s0    
$r	   )os.pathr   pathlibr   typingr   r   r   numpyr+   r)   torchvision.datasets.utilsr   r   torchvision.datasets.visionr   r	   r3   r3   r3   r4   <module>   s    