Can anyone tell me why I get IndexError: list index out of range?

Can anyone tell me why I get IndexError: list index out of range?

正在尝试复制此存储库:https://github.com/sujiongming/UCF-101_video_classification。当我 运行 CNN_train_UCF101.py 文件时出现以下错误。

Traceback (most recent call last):
  File "CNN_train_UCF101.py", line 18, in <module>
    data = DataSet()
  File "D:\Clones\UCF-101_video_classification-master\UCFdata.py", line 32, in __init__
    self.classes = self.get_classes()
  File "D:\Clones\UCF-101_video_classification-master\UCFdata.py", line 64, in get_classes
    if item[1] not in classes:
IndexError: list index out of range

部分参考代码如下:

def get_data():
        """Load our data from file."""
        with open('./data/data_file.csv', 'r') as fin:
            reader = csv.reader(fin)
            data = list(reader)   
def clean_data(self):
        """Limit samples to greater than the sequence length and fewer
        than N frames. Also limit it to classes we want to use."""
        data_clean = []
        for item in self.data:
            if int(item[3]) >= self.seq_length and int(item[3]) <= self.max_frames \
                    and item[1] in self.classes:
                data_clean.append(item)

        return data_clean

    def get_classes(self):
        """Extract the classes from our data. If we want to limit them,
        only return the classes we need."""
        classes = []
        for item in self.data:
            if item[1] not in classes:
                classes.append(item[1])

        # Sort them.
        classes = sorted(classes)

        # Return.
        if self.class_limit is not None:
            return classes[:self.class_limit]
        else:
            return classes

我更新了问题以阐明 data。 当我做 print (self.data) 我得到这样的东西: ['train', 'UnevenBars', 'v_UnevenBars_g22_c04', '126'], [] 对于数据集中的每个图像。

任何人都可以告诉我我做错了什么。提前致谢。

Window 10
Python 3.7.6

CSV 文件中有一个空行,导致 self.data 末尾的列表为空。

您应该跳过空项目。

for item in self.data:
    if len(item) < 2:
        continue
    if item[1] not in classes:
        classes.append(item[1])