class_docstr: Sample frames id.
  NOTE: Use PIL to read image here, has diff with CV2
  Args:
      num_seg(int): number of segments.
      seg_len(int): number of sampled frames in each segment.
      valid_mode(bool): True or False.
  Returns:
      frames_idx: the index of sampled #frames.
class_docstr_tok: ["Sample","frames","id",".","NOTE",":","Use","PIL","to","read","image","here",",","has","diff","with","CV2","Args",":","num_seg","(","int",")",":","number","of","segments",".","seg_len","(","int",")",":","number","of","sampled","frames","in","each","segment",".","valid_mode","(","bool",")",":","True","or","False",".","Returns",":","frames_idx",":","the","index","of","sampled","#","frames","."]
docstr: Args:
      frames_len: length of frames.
  return:
      sampling id.
docstr_tok: ["Args",":","frames_len",":","length","of","frames",".","return",":","sampling","id","."]
code: def __call__(self, results):
      """
      Args:
          frames_len: length of frames.
      return:
          sampling id.
      """
      frames_len = int(results["frames_len"])  # total number of frames
  
      frames_idx = []
      if self.frame_interval is not None:
          assert isinstance(self.frame_interval, int)
          if not self.valid_mode:
              offsets = self._get_train_clips(frames_len)
          else:
              offsets = self._get_test_clips(frames_len)
  
          offsets = (
              offsets[:, None]
              + np.arange(self.seg_len)[None, :] * self.frame_interval
          )
          offsets = np.concatenate(offsets)
  
          offsets = offsets.reshape((-1, self.seg_len))
          offsets = np.mod(offsets, frames_len)
          offsets = np.concatenate(offsets)
  
          if results["format"] == "video":
              frames_idx = offsets
          elif results["format"] == "frame":
              frames_idx = list(offsets + 1)
          else:
              raise NotImplementedError
  
          return self._get(frames_idx, results)
  
      print("self.frame_interval:", self.frame_interval)
  
      if self.linspace_sample:  # default if False
          if "start_idx" in results and "end_idx" in results:
              offsets = np.linspace(
                  results["start_idx"], results["end_idx"], self.num_seg
              )
          else:
              offsets = np.linspace(0, frames_len - 1, self.num_seg)
          offsets = np.clip(offsets, 0, frames_len - 1).astype(np.int64)
          if results["format"] == "video":
              frames_idx = list(offsets)
              frames_idx = [x % frames_len for x in frames_idx]
          elif results["format"] == "frame":
              frames_idx = list(offsets + 1)
          else:
              raise NotImplementedError
          return self._get(frames_idx, results)
  
      average_dur = int(frames_len / self.num_seg)
  
      print("results['format']:", results["format"])
  
      if self.dense_sample:  # For ppTSM, default is False
          if not self.valid_mode:  # train
              sample_pos = max(1, 1 + frames_len - 64)
              t_stride = 64 // self.num_seg
              start_idx = (
                  0
                  if sample_pos == 1
                  else np.random.randint(0, sample_pos - 1)
              )
              offsets = [
                  (idx * t_stride + start_idx) % frames_len + 1
                  for idx in range(self.num_seg)
              ]
              frames_idx = offsets
          else:
              sample_pos = max(1, 1 + frames_len - 64)
              t_stride = 64 // self.num_seg
              start_list = np.linspace(
                  0, sample_pos - 1, num=10, dtype=int
              )
              offsets = []
              for start_idx in start_list.tolist():
                  offsets += [
                      (idx * t_stride + start_idx) % frames_len + 1
                      for idx in range(self.num_seg)
                  ]
              frames_idx = offsets
      else:
          for i in range(self.num_seg):
              idx = 0
              if not self.valid_mode:
                  if average_dur >= self.seg_len:
                      idx = random.randint(
                          0, average_dur - self.seg_len
                      )
                      idx += i * average_dur
                  elif average_dur >= 1:
                      idx += i * average_dur
                  else:
                      idx = i
              else:
                  if average_dur >= self.seg_len:
                      idx = (average_dur - 1) // 2
                      idx += i * average_dur
                  elif average_dur >= 1:
                      idx += i * average_dur
                  else:
                      idx = i
  
              for jj in range(idx, idx + self.seg_len):
                  if results["format"] == "video":
                      frames_idx.append(int(jj % frames_len))
                  elif results["format"] == "frame":
                      frames_idx.append(jj + 1)
  
                  elif results["format"] == "MRI":
                      frames_idx.append(jj)
                  else:
                      raise NotImplementedError
  
      return self._get(frames_idx, results)
  
imports: import cv2
  import numpy
  from PIL import Image
  import paddle
label_desc: Use image node_id 5 for calling the Sampler obj's underlying member method code with example usage: obj.__call__(results) and returns: self, self, self