# Path: data_pipeline/ntu_rgbd.py
# class NTU_RGBD(data.Dataset):
#   """Class for NTU RGBD Dataset"""
#   MEAN_STD = {
#       'rgb': ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
#       'oflow': (0.5, 1. / 255),
#       'depth': (4084.1213735 / (255 * 256), 1008.31271366 / (255 * 256)),
#       'jjd': (0.53968146, 0.32319776),
#       'jjv': (0, 0.35953656),
#       'jld': (0.15982792, 0.12776225)
#   }
# 
#   def __init__(self,
#                root,
#                split,
#                evaluation,
#                modalities,
#                n_samples,
#                n_frames,
#                downsample,
#                transforms=None,
#                subsample=0):
#     """NTU RGBD dataset.
# 
#     Args:
#       root: dataset root
#       split: train to randomly select n_samples samples; test to uniformly
#         select n_samples spanning the whole video
#       evaluation: one of ['cross-subject', 'cross-view']
#       modalities: subset of ['rgb', 'oflow', 'depth', 'jjd', 'jjv', 'jld']
#       n_samples: number of samples from the video
#       n_frames: number of frames per sample
#       downsample: fps /= downsample
#       transforms: transformations to apply to data
#       subsample: number of samples per class. 0 if using full dataset.
#     """
#     modalities = utils.unsqueeze(modalities)
#     transforms = utils.unsqueeze(transforms)
# 
#     # Loader functions
#     loaders = {
#         'rgb': rgb_loader,
#         'oflow': oflow_loader,
#         'depth': depth_loader,
#         'jjd': jjd_loader,
#         'jjv': jjv_loader,
#         'jld': jld_loader
#     }
#     has_skel = any([m in ALL_MODALITIES[3:] for m in modalities])
#     dataset = make_dataset(root, has_skel, evaluation, split, subsample)
# 
#     self.root = root
#     self.split = split
#     self.modalities = modalities
#     self.n_samples = n_samples
#     self.n_frames = n_frames
#     self.downsample = downsample
#     self.transforms = transforms
#     self.loaders = loaders
#     self.dataset = dataset
# 
#   def __getitem__(self, idx):
#     vid_name, label = self.dataset[idx]
#     # -1 because len(oflow) = len(rgb)-1
#     length = len(
#         glob.glob(
#             os.path.join(self.root, rgb_folder_name, vid_name,
#                          '*.' + rgb_pattern.split('.')[1]))) - 1
# 
#     length_ds = length // self.downsample
#     if length_ds < self.n_frames:
#       frame_ids_s = np.arange(0, length_ds, 1)  # arange: exclusive
#       frame_ids_s = np.concatenate(
#           (frame_ids_s,
#            np.array([frame_ids_s[-1]] * (self.n_frames - length_ds))))
#       frame_ids = np.repeat(
#           frame_ids_s[np.newaxis, :], self.n_samples,
#           axis=0).astype(int) * self.downsample
#     else:
#       if self.split == 'train':  # randomly select n_samples samples
#         starts = np.random.randint(0, length_ds - self.n_frames + 1,
#                                    self.n_samples)  # randint: exclusive
#       # uniformly select n_samples spanning the whole video
#       elif self.split == 'val' or self.split == 'test':
#         starts = np.linspace(
#             0, length_ds - self.n_frames, self.n_samples,
#             dtype=int)  # linspace: inclusive
#       else:
#         starts = np.arange(0,
#                            length_ds - self.n_frames + 1)  # arange: exclusive
# 
#       frame_ids = []
#       for start in starts:
#         frame_ids_s = np.arange(start, start + self.n_frames,
#                                 1) * self.downsample  # arange: exclusive
#         frame_ids.append(frame_ids_s)
#       frame_ids = np.stack(frame_ids)
# 
#     # load raw data
#     inputs = []
#     for modality in self.modalities:
#       vid = self.loaders[modality](self.root, vid_name, frame_ids)
#       inputs.append(vid)
# 
#     # transform
#     if self.transforms is not None:
#       for i in range(len(self.transforms)):
#         if self.transforms[i] is not None:
#           inputs[i] = self.transforms[i](inputs[i])
# 
#     return inputs, label
# 
#   def __len__(self):
#     return len(self.dataset)


import os
import third_party.two_stream_pytorch.video_transforms as vtransforms
import torch.utils.data as data
import torchvision.transforms as transforms
from data_pipeline.ntu_rgbd import NTU_RGBD
      xform = transforms.Compose([
          vtransforms.RandomSizedCrop(224),
          vtransforms.RandomHorizontalFlip(),
          vtransforms.ToTensor(),
          vtransforms.Normalize(mean, std)
      ])
    elif opt.split == 'train' and modality == 'oflow':
      # Special handling when flipping optical flow
      xform = transforms.Compose([
          vtransforms.RandomSizedCrop(224, True),
          vtransforms.RandomHorizontalFlip(True),
          vtransforms.ToTensor(),
          vtransforms.Normalize(mean, std)
      ])
    elif opt.split != 'train' and modality in CNN_MODALITIES:
      xform = transforms.Compose([
          vtransforms.Scale(256),
          vtransforms.CenterCrop(224),
          vtransforms.ToTensor(),
          vtransforms.Normalize(mean, std)
      ])
    elif modality in GRU_MODALITIES:
      xform = transforms.Compose([vtransforms.SkelNormalize(mean, std)])
    else:
      raise Exception

    xforms.append(xform)

  if opt.dset == 'ntu-rgbd':
    root = os.path.join(opt.dset_path, opt.dset)

# Path: data_pipeline/ntu_rgbd.py
# class NTU_RGBD(data.Dataset):
#   """Class for NTU RGBD Dataset"""
#   MEAN_STD = {
#       'rgb': ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
#       'oflow': (0.5, 1. / 255),
#       'depth': (4084.1213735 / (255 * 256), 1008.31271366 / (255 * 256)),
#       'jjd': (0.53968146, 0.32319776),
#       'jjv': (0, 0.35953656),
#       'jld': (0.15982792, 0.12776225)
#   }
# 
#   def __init__(self,
#                root,
#                split,
#                evaluation,
#                modalities,
#                n_samples,
#                n_frames,
#                downsample,
#                transforms=None,
#                subsample=0):
#     """NTU RGBD dataset.
# 
#     Args:
#       root: dataset root
#       split: train to randomly select n_samples samples; test to uniformly
#         select n_samples spanning the whole video
#       evaluation: one of ['cross-subject', 'cross-view']
#       modalities: subset of ['rgb', 'oflow', 'depth', 'jjd', 'jjv', 'jld']
#       n_samples: number of samples from the video
#       n_frames: number of frames per sample
#       downsample: fps /= downsample
#       transforms: transformations to apply to data
#       subsample: number of samples per class. 0 if using full dataset.
#     """
#     modalities = utils.unsqueeze(modalities)
#     transforms = utils.unsqueeze(transforms)
# 
#     # Loader functions
#     loaders = {
#         'rgb': rgb_loader,
#         'oflow': oflow_loader,
#         'depth': depth_loader,
#         'jjd': jjd_loader,
#         'jjv': jjv_loader,
#         'jld': jld_loader
#     }
#     has_skel = any([m in ALL_MODALITIES[3:] for m in modalities])
#     dataset = make_dataset(root, has_skel, evaluation, split, subsample)
# 
#     self.root = root
#     self.split = split
#     self.modalities = modalities
#     self.n_samples = n_samples
#     self.n_frames = n_frames
#     self.downsample = downsample
#     self.transforms = transforms
#     self.loaders = loaders
#     self.dataset = dataset
# 
#   def __getitem__(self, idx):
#     vid_name, label = self.dataset[idx]
#     # -1 because len(oflow) = len(rgb)-1
#     length = len(
#         glob.glob(
#             os.path.join(self.root, rgb_folder_name, vid_name,
#                          '*.' + rgb_pattern.split('.')[1]))) - 1
# 
#     length_ds = length // self.downsample
#     if length_ds < self.n_frames:
#       frame_ids_s = np.arange(0, length_ds, 1)  # arange: exclusive
#       frame_ids_s = np.concatenate(
#           (frame_ids_s,
#            np.array([frame_ids_s[-1]] * (self.n_frames - length_ds))))
#       frame_ids = np.repeat(
#           frame_ids_s[np.newaxis, :], self.n_samples,
#           axis=0).astype(int) * self.downsample
#     else:
#       if self.split == 'train':  # randomly select n_samples samples
#         starts = np.random.randint(0, length_ds - self.n_frames + 1,
#                                    self.n_samples)  # randint: exclusive
#       # uniformly select n_samples spanning the whole video
#       elif self.split == 'val' or self.split == 'test':
#         starts = np.linspace(
#             0, length_ds - self.n_frames, self.n_samples,
#             dtype=int)  # linspace: inclusive
#       else:
#         starts = np.arange(0,
#                            length_ds - self.n_frames + 1)  # arange: exclusive
# 
#       frame_ids = []
#       for start in starts:
#         frame_ids_s = np.arange(start, start + self.n_frames,
#                                 1) * self.downsample  # arange: exclusive
#         frame_ids.append(frame_ids_s)
#       frame_ids = np.stack(frame_ids)
# 
#     # load raw data
#     inputs = []
#     for modality in self.modalities:
#       vid = self.loaders[modality](self.root, vid_name, frame_ids)
#       inputs.append(vid)
# 
#     # transform
#     if self.transforms is not None:
#       for i in range(len(self.transforms)):
#         if self.transforms[i] is not None:
#           inputs[i] = self.transforms[i](inputs[i])
# 
#     return inputs, label
# 
#   def __len__(self):
#     return len(self.dataset)


# Path: classification/get_dataloader.py
import os
import third_party.two_stream_pytorch.video_transforms as vtransforms
import torch.utils.data as data
import torchvision.transforms as transforms
from data_pipeline.ntu_rgbd import NTU_RGBD

      xform = transforms.Compose([
          vtransforms.RandomSizedCrop(224),
          vtransforms.RandomHorizontalFlip(),
          vtransforms.ToTensor(),
          vtransforms.Normalize(mean, std)
      ])
    elif opt.split == 'train' and modality == 'oflow':
      # Special handling when flipping optical flow
      xform = transforms.Compose([
          vtransforms.RandomSizedCrop(224, True),
          vtransforms.RandomHorizontalFlip(True),
          vtransforms.ToTensor(),
          vtransforms.Normalize(mean, std)
      ])
    elif opt.split != 'train' and modality in CNN_MODALITIES:
      xform = transforms.Compose([
          vtransforms.Scale(256),
          vtransforms.CenterCrop(224),
          vtransforms.ToTensor(),
          vtransforms.Normalize(mean, std)
      ])
    elif modality in GRU_MODALITIES:
      xform = transforms.Compose([vtransforms.SkelNormalize(mean, std)])
    else:
      raise Exception

    xforms.append(xform)

  if opt.dset == 'ntu-rgbd':
    root = os.path.join(opt.dset_path, opt.dset)

    dset = NTU_RGBD(root, opt.split, 'cross-subject', opt.modalities,