o
    )i                     @   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                       s   e Zd ZdZdZ				dde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 )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 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torchZ
from_numpynploadZ	transposeZ	unsqueeze
contiguousdata)selfr	   r
   r   r   r   r+   r    p/var/www/html/eduruby.in/lip-sync/lip-sync-env/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:
            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__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   N)r   
__module____qualname____doc__r   strr   r!   boolr   r   r'   ZTensorr1   r5   r%   r   __classcell__r.   r.   r-   r/   r   
   s0    $r   )Zos.pathr   typingr   r   numpyr(   r'   Ztorchvision.datasets.utilsr   r   Ztorchvision.datasets.visionr   r   r.   r.   r.   r/   <module>   s    