Strange error while using torchvision.datasets.UCF101

I am trying to import the ucf101 dataset using

dataset = torchvision.datasets.UCF101(r'my_directory', annotation_path=r'my_directory2', frames_per_clip=16, step_between_clips=1, frame_rate=None, fold=1, train=True, transform=transforms.Compose([transforms.ToTensor()]), _precomputed_metadata=None, num_workers=1, _video_width=64, _video_height=64, _video_min_dimension=0, _audio_samples=0)

But if I perform any kind of operation with ‘dataset’, like dataLoader or len() i get the error

IndexError: list index out of range

Full error message is:


    ---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-16-dc3631481cb3> in <module>
----> 1 data = torch.utils.data.DataLoader(dataset, batch_size=512, shuffle=True)

~\anaconda3\lib\site-packages\torch\utils\data\dataloader.py in __init__(self, dataset, batch_size, shuffle, sampler, batch_sampler, num_workers, collate_fn, pin_memory, drop_last, timeout, worker_init_fn, multiprocessing_context)
    211             else:  # map-style
    212                 if shuffle:
--> 213                     sampler = RandomSampler(dataset)
    214                 else:
    215                     sampler = SequentialSampler(dataset)

~\anaconda3\lib\site-packages\torch\utils\data\sampler.py in __init__(self, data_source, replacement, num_samples)
     90                              "since a random permute will be performed.")
     91 
---> 92         if not isinstance(self.num_samples, int) or self.num_samples <= 0:
     93             raise ValueError("num_samples should be a positive integer "
     94                              "value, but got num_samples={}".format(self.num_samples))

~\anaconda3\lib\site-packages\torch\utils\data\sampler.py in num_samples(self)
     98         # dataset size might change at runtime
     99         if self._num_samples is None:
--> 100             return len(self.data_source)
    101         return self._num_samples
    102 

~\anaconda3\lib\site-packages\torchvision\datasets\ucf101.py in __len__(self)
     96 
     97     def __len__(self):
---> 98         return self.video_clips.num_clips()
     99 
    100     def __getitem__(self, idx):

~\anaconda3\lib\site-packages\torchvision\datasets\video_utils.py in num_clips(self)
    241         Number of subclips that are available in the video list.
    242         """
--> 243         return self.cumulative_sizes[-1]
    244 
    245     def get_clip_location(self, idx):

IndexError: list index out of range

Could you check, what

print(dataset.video_clips, dataset.video_clips_metadata, dataset.indices)

returns?
It seems that no video clips were found using the specified directories.

Thanks for your reply, this is the output:

<torchvision.datasets.video_utils.VideoClips object at 0x0000028F45B39208> 
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

Current values:
NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)

So I fixed the rate_limit problem and I get:

<torchvision.datasets.video_utils.VideoClips object at 0x000001B8B4381EC8> {'video_paths': ['ucf101\\ApplyEyeMakeup\\v_ApplyEyeMakeup_g01_c01.avi', 'ucf101\\ApplyEyeMakeup\\v_ApplyEyeMakeup_g01_c02.avi', 'ucf101\\ApplyEyeMakeup\\v_ApplyEyeMakeup_g01_c03.avi',

till it arrives at the last videos

.... ucf101\\YoYo\\v_YoYo_g25_c04.avi', 'ucf101\\YoYo\\v_YoYo_g25_c05.avi'],

For the metadata I get all the video-to-tensor like this one:

'video_pts': [tensor([  1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,
         15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,
         29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,
         43,  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,
         57,  58,  59,  60,  61,  62,  63,  64,  65,  66,  67,  68,  69,  70,
         71,  72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83,  84,
         85,  86,  87,  88,  89,  90,  91,  92,  93,  94,  95,  96,  97,  98,
         99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
        113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
        127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
        141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
        155, 156, 157, 158, 159, 160, 161, 162, 163, 164]),

and finally

'video_fps': [25.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0.....

The output of dataset.indices is: [ ]

Hi costa98, I have the same problem as you but couldn’t find any solution… did you find the reason for this bug or did you implement a customized Dataset?

I just found the cause, incompatibility in the paths strings between the text files of train_test_splits/ and the file name of the dataset.samples. The txt files have ‘root\action/video_name’ whereas the samples are (‘root\action\video_name’, label)

Problem:

This problem occurs when you run your code on windows because windows paths use backslash ("\") instead of forward slash ("/").

As you see in the code:

So, this line of code reads the file path from label file as “action\video_name” and merge it with “root” path using backslash therefore full path becomes like “root\action/video_name”. Such paths doesn’t match with the video lists at line#97 and returns empty list for indices variable.

Solution:

Two of possible solutions can be:

  1. Replace the forwardslashes “/” in the label files with backslashes “\”.
  2. Override the _select_fold(…) function of class UCF101 and fix the backslashes inside the function.