o
    Ni]                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	  m
Z ddlmZ dZdZd	Zd
ZG dd dejjZejddZG dd dejjZdS )z>UCF-101 dataset from https://www.crcv.ucf.edu/data/UCF101.php.    )absolute_import)division)print_functionN)loggingz?https://storage.googleapis.com/thumos14_files/UCF101_videos.zipzNhttps://www.crcv.ucf.edu/data/UCF101/UCF101TrainTestSplits-RecognitionTask.zipaj  @article{DBLP:journals/corr/abs-1212-0402,
  author    = {Khurram Soomro and
               Amir Roshan Zamir and
               Mubarak Shah},
  title     = {{UCF101:} {A} Dataset of 101 Human Actions Classes From Videos in
               The Wild},
  journal   = {CoRR},
  volume    = {abs/1212.0402},
  year      = {2012},
  url       = {http://arxiv.org/abs/1212.0402},
  archivePrefix = {arXiv},
  eprint    = {1212.0402},
  timestamp = {Mon, 13 Aug 2018 16:47:45 +0200},
  biburl    = {https://dblp.org/rec/bib/journals/corr/abs-1212-0402},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}
zvideo/ucf101_labels.txtc                       s*   e Zd ZdZejjd fdd	Z  ZS )Ucf101Configz="Configuration for UCF101 split and possible video rescaling.Nc                    sZ   t t| jdi | |du |du A rtd|| _|| _|dvr(td||| _dS )a  The parameters specifying how the dataset will be processed.

    The dataset comes with three separate splits. You can specify which split
    you want in `split_number`. If `width` and `height` are set, the videos
    will be rescaled to have those heights and widths (using ffmpeg).

    Args:
      split_number: The split number, one of (1, 2, 3)
      width: An integer with the width or None.
      height: An integer with the height or None.
      **kwargs: Passed on to the constructor of `BuilderConfig`.
    Nz5Either both dimensions should be set, or none of them)         z,Unknown split number {}, should be 1, 2 or 3 )superr   __init__
ValueErrorwidthheightformatsplit_number)selfr   r   r   kwargs	__class__r
   T/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/video/ucf101.pyr   :   s   
zUcf101Config.__init__)NN)	__name__
__module____qualname____doc__tfdscoredisallow_positional_argsr   __classcell__r
   r
   r   r   r   7   s    r   z2.0.0z6New split API (https://tensorflow.org/datasets/splits)c                   @   st   e Zd ZdZedddddededdd	d	deded
dd	d	dededdd	d	dedgZdd Zdd Zdd Z	d	S )Ucf101zUcf101 action recognition dataset.

  Note that in contrast to the labels provided in the original dataset, here the
  labels start at zero, not at one.
  ucf101_1_256z4256x256 UCF with the first action recognition split.   r   )namedescriptionr   r   r   versionucf101_1z)UCF with the action recognition split #1.Nucf101_2z)UCF with the action recognition split #2.r   ucf101_3z)UCF with the action recognition split #3.r	   c                 C   s   | j jd ur| j jd u rtddd| j j| j jf}ng }d | j j| j jdf}tjt}tj	
tj	j||ddtj	j|dd}tjj| d	|d
tdS )Nz-Provide either both height and width or none.z-vfzscale={}x{}r	   jpeg)ffmpeg_extra_argsencoding_format)
names_filevideolabelz)A 101-label video classification dataset.z*https://www.crcv.ucf.edu/data-sets/ucf101/)builderr#   featureshomepagecitation)builder_configr   r   r   r   r   r   get_tfds_path_LABELS_FNAMEr0   FeaturesDictVideo
ClassLabelDatasetInfo	_CITATION)r   r)   video_shapelabels_names_filer0   r
   r
   r   _info   s2   zUcf101._infoc              	   C   sx   d}t td}||}tjjtjj|d |d d|| j	j
ddtjjtjj|d |d d|| j	j
ddgS )	NucfTrainTestlist)videossplitsr?   r@   z{}/trainlist{:02d}.txt)
videos_dir
splits_dir	data_list)r"   
gen_kwargsz{}/testlist{:02d}.txt)UCF_101_URL
SPLITS_URLdownload_and_extractr   r   SplitGeneratorSplitTRAINr   r3   r   TEST)r   
dl_managersplits_folderurls_to_downloaddownloaded_urlsr
   r
   r   _split_generators   s0   
zUcf101._split_generatorsc                 c   s    t j||}tjj|d}| }W d    n1 sw   Y  t|D ]7}|	 
dd }t j
|\}}	|	dd}	t j|d|	}
tjj|
sWtd|
 q(|	|
|dfV  q(d S )	Nr r   HandStandPushupsHandstandPushupsUCF101zExample %s not foundr,   )ospathjointfiogfileGFile	readlinessortedstripsplitreplaceexistsr   error)r   rA   rB   rC   data_list_path_pathdata_list_filelabels_and_pathslabel_and_pathr.   rW   
video_pathr
   r
   r   _generate_examples   s   
zUcf101._generate_examples)
r   r   r   r   r   _VERSIONBUILDER_CONFIGSr=   rP   ri   r
   r
   r
   r   r   W   sL    #r   )r   
__future__r   r   r   rV   abslr   tensorflow.compat.v2compatv2rY   tensorflow_datasets.public_api
public_apir   rE   rF   r:   r5   r   BuilderConfigr   Versionrj   GeneratorBasedBuilderr   r
   r
   r
   r   <module>   s"   