
    khS                         d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	m
Z
mZ d dlmZ ddlmZmZ ddlmZ ddlmZ  G d	 d
e      Zy)    N)Path)AnyCallableDictListOptionalTupleUnion)Tensor   )find_classesmake_dataset)
VideoClips)VisionDatasetc            !       *    e Zd ZdZdZdddZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 d!d	ee	e
f   d
e	dededee   dededee   deee	ef      dededededede	ddf  fdZedee	ef   fd       Zdee	   de	dededee   f
dZdefdZdedeeeef   fd Z xZS )"HMDB51a  
    `HMDB51 <https://serre-lab.clps.brown.edu/resource/hmdb-a-large-human-motion-database/>`_
    dataset.

    HMDB51 is an action recognition video dataset.
    This dataset consider every video as a collection of video clips of fixed size, specified
    by ``frames_per_clip``, where the step in frames between each clip is given by
    ``step_between_clips``.

    To give an example, for 2 videos with 10 and 15 frames respectively, if ``frames_per_clip=5``
    and ``step_between_clips=5``, the dataset size will be (2 + 3) = 5, where the first two
    elements will come from video 1, and the next three elements from video 2.
    Note that we drop clips which do not have exactly ``frames_per_clip`` elements, so not all
    frames in a video might be present.

    Internally, it uses a VideoClips object to handle clip creation.

    Args:
        root (str or ``pathlib.Path``): Root directory of the HMDB51 Dataset.
        annotation_path (str): Path to the folder containing the split files.
        frames_per_clip (int): Number of frames in a clip.
        step_between_clips (int): Number of frames between each clip.
        fold (int, optional): Which fold to use. Should be between 1 and 3.
        train (bool, optional): If ``True``, creates a dataset from the train split,
            otherwise from the ``test`` split.
        transform (callable, optional): A function/transform that takes in a TxHxWxC video
            and returns a transformed version.
        output_format (str, optional): The format of the output video tensors (before transforms).
            Can be either "THWC" (default) or "TCHW".

    Returns:
        tuple: A 3-tuple with the following entries:

            - video (Tensor[T, H, W, C] or Tensor[T, C, H, W]): The `T` video frames
            - audio(Tensor[K, L]): the audio frames, where `K` is the number of channels
              and `L` is the number of points
            - label (int): class of the video clip
    zJhttps://serre-lab.clps.brown.edu/wp-content/uploads/2013/10/hmdb51_org.rarzQhttps://serre-lab.clps.brown.edu/wp-content/uploads/2013/10/test_train_splits.rar 15e67781e70dcfbdce2d7dbb9b3344b5)urlmd5r      Nrootannotation_pathframes_per_clipstep_between_clips
frame_ratefoldtrain	transform_precomputed_metadatanum_workers_video_width_video_height_video_min_dimension_audio_samplesoutput_formatreturnc                    t         |   |       |dvrt        d|       d}t        | j                        \  | _        }t        | j                  ||      | _        | j                  D cg c]  \  }}|	 }}}t        |||||	|
|||||      }|| _	        || _
        || _        | j                  ||||      | _        |j                  | j                        | _        || _        y c c}}w )N)r   r      z$fold should be between 1 and 3, got )avi)r    r!   r"   r#   r$   r%   )super__init__
ValueErrorr   r   classesr   samplesr   full_video_clipsr   r   _select_foldindicessubsetvideo_clipsr   )selfr   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   
extensionsclass_to_idxpath_video_pathsr3   	__class__s                         W/var/www/teggl/fontify/venv/lib/python3.12/site-packages/torchvision/datasets/hmdb51.pyr+   zHMDB51.__init__=   s    $ 	y CD6JKK
%1$))%<"l#II
 .2\\:	qt:: !#%'!5)'
  !,	
((otUS&--dll;"- ;s   -C(c                 .    | j                   j                  S N)r/   metadatar4   s    r;   r>   zHMDB51.metadatas   s    $$---    
video_listannotations_dirc                 :   |r| j                   n| j                  }d| d}t        j                  j	                  ||      }t        j
                  |      }t               }	|D ]b  }
t        |
      5 }|j                         }d d d        D ]7  }|j                         \  }}t        |      }||k(  s'|	j                  |       9 d g }t        |      D ]8  \  }}t        j                  j                  |      |	v s(|j                  |       : |S # 1 sw Y   xY w)Nz*test_splitz.txt)	TRAIN_TAGTEST_TAGosr7   joinglobsetopen	readlinessplitintadd	enumeratebasenameappend)r4   rA   rB   r   r   
target_tagsplit_pattern_namesplit_pattern_pathannotation_pathsselected_filesfilepathfidlineslinevideo_filename
tag_stringtagr1   video_index
video_paths                       r;   r0   zHMDB51._select_foldw   s   ',T^^$--
*4&5WW\\/;MN99%78( 	7Hh (3( 7-1ZZ\*
*o*$"&&~6	7	7 '0'< 	,#Kww
+~={+	, ( (s   0DD	c                 6    | j                   j                         S r=   )r3   	num_clipsr?   s    r;   __len__zHMDB51.__len__   s    ))++r@   idxc                     | j                   j                  |      \  }}}}| j                  |   }| j                  |   \  }}| j                  | j	                  |      }|||fS r=   )r3   get_clipr1   r.   r   )r4   rc   videoaudior8   	video_idxsample_indexclass_indexs           r;   __getitem__zHMDB51.__getitem__   sf    %)%5%5%>%>s%C"ua||I.l3;>>%NN5)Ee[((r@   )r   Nr   TNNr   r   r   r   r   THWC)__name__
__module____qualname____doc__data_urlsplitsrD   rE   r
   strr   rM   r   boolr   r   r   r+   propertyr>   r   r0   rb   r	   r   rk   __classcell__)r:   s   @r;   r   r      s   %N \Hb1F IH #$$((,:>$%#!4#CI4# 4# 	4#
  4# SM4# 4# 4# H%4#  (S#X74# 4# 4# 4# "4# 4#  !4#" 
#4#l .$sCx. . .tCy 3 c Z^ cghkcl ,, ,)s )uVVS-@'A )r@   r   )rH   rF   pathlibr   typingr   r   r   r   r   r	   r
   torchr   folderr   r   video_utilsr   visionr   r    r@   r;   <module>r~      s1     	  D D D  . # !K)] K)r@   