class_docstr: A highly efficient and adaptable dataset class for videos.
  Instead of loading every frame of a video,
  loads x RGB frames of a video (sparse temporal sampling) and evenly
  chooses those frames from start to end of the video, returning
  a list of x PIL images or ``FRAMES x CHANNELS x HEIGHT x WIDTH``
  tensors where FRAMES=x if the ``kale.prepdata.video_transform.ImglistToTensor()``
  transform is used.
  
  More specifically, the frame range [START_FRAME, END_FRAME] is divided into NUM_SEGMENTS
  segments and FRAMES_PER_SEGMENT consecutive frames are taken from each segment.
  
  Note:
      A demonstration of using this class can be seen
      in ``PyKale/examples/video_loading``
      https://github.com/pykale/pykale/tree/master/examples/video_loading
  
  Note:
      This dataset broadly corresponds to the frame sampling technique
      introduced in ``Temporal Segment Networks`` at ECCV2016
      https://arxiv.org/abs/1608.00859.
  
  
  Note:
      This class relies on receiving video data in a structure where
      inside a ``ROOT_DATA`` folder, each video lies in its own folder,
      where each video folder contains the frames of the video as
      individual files with a naming convention such as
      img_001.jpg ... img_059.jpg.
      For enumeration and annotations, this class expects to receive
      the path to a .txt file where each video sample has a row with four
      (or more in the case of multi-label, see example README on Github)
      space separated values:
      ``VIDEO_FOLDER_PATH     START_FRAME     END_FRAME     LABEL_INDEX``.
      ``VIDEO_FOLDER_PATH`` is expected to be the path of a video folder
      excluding the ``ROOT_DATA`` prefix. For example, ``ROOT_DATA`` might
      be ``home\data\datasetxyz\videos\``, inside of which a ``VIDEO_FOLDER_PATH``
      might be ``jumping\0052\`` or ``sample1\`` or ``00053\``.
  
  Args:
      root_path: The root path in which video folders lie.
                 this is ROOT_DATA from the description above.
      annotationfile_path: The .txt annotation file containing
                           one row per video sample as described above.
      image_modality: Image modality (RGB or Optical Flow).
      num_segments: The number of segments the video should
                    be divided into to sample frames from.
      frames_per_segment: The number of frames that should
                          be loaded per segment. For each segment's
                          frame-range, a random start index or the
                          center is chosen, from which frames_per_segment
                          consecutive frames are loaded.
      imagefile_template: The image filename template that video frame files
                          have inside of their video folders as described above.
      transform: Transform pipeline that receives a list of PIL images/frames.
      random_shift: Whether the frames from each segment should be taken
                    consecutively starting from the center of the segment, or
                    consecutively starting from a random location inside the
                    segment range.
      test_mode: Whether this is a test dataset. If so, chooses
                 frames from segments with random_shift=False.
class_docstr_tok: ["A","highly","efficient","and","adaptable","dataset","class","for","videos",".","Instead","of","loading","every","frame","of","a","video",",","loads","x","RGB","frames","of","a","video","(","sparse","temporal","sampling",")","and","evenly","chooses","those","frames","from","start","to","end","of","the","video",",","returning","a","list","of","x","PIL","images","or","``","FRAMES","x","CHANNELS","x","HEIGHT","x","WIDTH","``","tensors","where","FRAMES=x","if","the","``","kale.prepdata.video_transform.ImglistToTensor","(",")","``","transform","is","used",".","More","specifically",",","the","frame","range","[","START_FRAME",",","END_FRAME","]","is","divided","into","NUM_SEGMENTS","segments","and","FRAMES_PER_SEGMENT","consecutive","frames","are","taken","from","each","segment",".","Note",":","A","demonstration","of","using","this","class","can","be","seen","in","``","PyKale\/examples\/video_loading","``","https",":","\/\/github.com\/pykale\/pykale\/tree\/master\/examples\/video_loading","Note",":","This","dataset","broadly","corresponds","to","the","frame","sampling","technique","introduced","in","``","Temporal","Segment","Networks","``","at","ECCV2016","https",":","\/\/arxiv.org\/abs\/1608.00859",".","Note",":","This","class","relies","on","receiving","video","data","in","a","structure","where","inside","a","``","ROOT_DATA","``","folder",",","each","video","lies","in","its","own","folder",",","where","each","video","folder","contains","the","frames","of","the","video","as","individual","files","with","a","naming","convention","such","as","img_001.jpg","...","img_059.jpg",".","For","enumeration","and","annotations",",","this","class","expects","to","receive","the","path","to","a",".txt","file","where","each","video","sample","has","a","row","with","four","(","or","more","in","the","case","of","multi-label",",","see","example","README","on","Github",")","space","separated","values",":","``","VIDEO_FOLDER_PATH","START_FRAME","END_FRAME","LABEL_INDEX","``",".","``","VIDEO_FOLDER_PATH","``","is","expected","to","be","the","path","of","a","video","folder","excluding","the","``","ROOT_DATA","``","prefix",".","For","example",",","``","ROOT_DATA","``","might","be","``","home\\data\\datasetxyz\\videos\\","``",",","inside","of","which","a","``","VIDEO_FOLDER_PATH","``","might","be","``","jumping\\0052\\","``","or","``","sample1\\","``","or","``","00053\\","``",".","Args",":","root_path",":","The","root","path","in","which","video","folders","lie",".","this","is","ROOT_DATA","from","the","description","above",".","annotationfile_path",":","The",".txt","annotation","file","containing","one","row","per","video","sample","as","described","above",".","image_modality",":","Image","modality","(","RGB","or","Optical","Flow",")",".","num_segments",":","The","number","of","segments","the","video","should","be","divided","into","to","sample","frames","from",".","frames_per_segment",":","The","number","of","frames","that","should","be","loaded","per","segment",".","For","each","segment's","frame-range",",","a","random","start","index","or","the","center","is","chosen",",","from","which","frames_per_segment","consecutive","frames","are","loaded",".","imagefile_template",":","The","image","filename","template","that","video","frame","files","have","inside","of","their","video","folders","as","described","above",".","transform",":","Transform","pipeline","that","receives","a","list","of","PIL","images\/frames",".","random_shift",":","Whether","the","frames","from","each","segment","should","be","taken","consecutively","starting","from","the","center","of","the","segment",",","or","consecutively","starting","from","a","random","location","inside","the","segment","range",".","test_mode",":","Whether","this","is","a","test","dataset",".","If","so",",","chooses","frames","from","segments","with","random_shift=False","."]
docstr: For video with id index, loads self.NUM_SEGMENTS * self.FRAMES_PER_SEGMENT
  frames from evenly chosen locations.
  
  Args:
      index: Video sample index.
  Returns:
      a list of PIL images or the result
      of applying self.transform on this list if
      self.transform is not None.
docstr_tok: ["For","video","with","id","index",",","loads","self.NUM_SEGMENTS","*","self.FRAMES_PER_SEGMENT","frames","from","evenly","chosen","locations",".","Args",":","index",":","Video","sample","index",".","Returns",":","a","list","of","PIL","images","or","the","result","of","applying","self.transform","on","this","list","if","self.transform","is","not","None","."]
code: def __getitem__(self, index):
      """
      For video with id index, loads self.NUM_SEGMENTS * self.FRAMES_PER_SEGMENT
      frames from evenly chosen locations.
  
      Args:
          index: Video sample index.
      Returns:
          a list of PIL images or the result
          of applying self.transform on this list if
          self.transform is not None.
      """
  
      record = self.video_list[index]
  
      if record.num_frames < self.frames_per_segment:
          raise RuntimeError(
              "Path:{}, start:{}, end:{}.\n Video_length is {}, which should be larger than "
              "frame_per_segment {}.".format(
                  record.path,
                  record.start_frame,
                  record.end_frame,
                  record.num_frames,
                  self.frames_per_segment,
              )
          )
      elif record.num_frames < self.num_segments:
          raise RuntimeError(
              "Path:{}, start:{}, end:{}.\n Video_length is {}, which should be larger than "
              "num_segments {}.".format(
                  record.path,
                  record.start_frame,
                  record.end_frame,
                  record.num_frames,
                  self.num_segments,
              )
          )
      elif (
          record.num_frames
          < self.num_segments * self.frames_per_segment
      ):
          if (
              self.num_segments
              > record.num_frames - self.frames_per_segment + 1
          ):
              raise RuntimeError(
                  "Path:{}, start:{}, end:{}.\n Video_length is {}, num_segments is {} and "
                  "frame_per_segment is {}. Please make num_segments<frame_length-frames_per_segment "
                  "to avoid getting too many same segments.".format(
                      record.path,
                      record.start_frame,
                      record.end_frame,
                      record.num_frames,
                      self.num_segments,
                      self.frames_per_segment,
                  )
              )
  
      if not self.test_mode:
          segment_indices = (
              self._get_random_indices(record)
              if self.random_shift
              else self._get_symmetric_indices(record)
          )
      else:
          segment_indices = self._get_symmetric_indices(record)
  
      return self._get(record, segment_indices)
  
imports: import math
  import os
  import os.path
  import random
  from pathlib import Path
  import numpy
  import torch
  from PIL import Image
label_desc: Use image node_id 6 for calling the VideoFrameDataset obj's underlying member method code with example usage: obj.__getitem__(index) and returns: self