设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 6920|回复: 1
打印 上一主题 下一主题

ValueError: 'C:/Users/videos/kick_ball' is not in list

[复制链接]

2

主题

0

好友

18

积分

新手上路

Rank: 1

跳转到指定楼层
楼主
发表于 2019-12-5 20:37:55 |只看该作者 |倒序浏览
从GitHub上download了一个工程,用于生成视频数据生成的,出现这样的错误,不知道为何,kick_ball是一类视频的文件夹
def __getitem__(self, index):
        classes = self.classes
        shape = self.target_shape
        nbframe = self.nbframe
        labels = []
        images = []
        indexes = self.indexes[index*self.batch_sizeindex+1)*self.batch_size]
        transformation = None
        for i in indexes:
            # prepare a transformation if provided
            if self.transformation is not None:
                transformation = self._random_trans
            # video = random.choice(files)
            video = self.files
            classname = video.split(os.sep)[-2]
            # create a label array and set 1 to the right column
            label = np.zeros(len(classes))
            col = classes.index(classname)
            label[col] = 1.
            if video not in self.__frame_cache:
                cap = cv.VideoCapture(video)
                frames = []
                while True:
                    grabbed, frame = cap.read()
                    if not grabbed:
                        # end of video
                        break
                    # resize
                    frame = cv.resize(frame, shape)
                    # use RGB or Grayscale ?
                    if self.nb_channel == 3:
                        frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
                    else:
                        frame = cv.cvtColor(frame, cv.COLOR_RGB2GRAY)
                    # to np
                    frame = img_to_array(
                        frame) * self.rescale
                    # keep frame
                    frames.append(frame)
                # Add 2 frames to drop first and last frame
                jump = len(frames)//(nbframe+2)
                # get only some images
                try:
                    frames = frames[jump::jump][:nbframe]
                except Exception as exception:
                    print(video)
                    raise exception
                # add to frame cache to not read from disk later
                if self.use_frame_cache:
                    self.__frame_cache[video] = frames
            else:
                frames = self.__frame_cache[video]
            # apply transformation
            if transformation is not None:
                frames = [self.transformation.apply_transform(
                    frame, transformation) for frame in frames]
            # add the sequence in batch
            images.append(frames)
            labels.append(label)
        return np.array(images), np.array(labels)

回复

使用道具 举报

174

主题

45

好友

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

沙发
发表于 2019-12-6 14:10:54 |只看该作者
classes.index(classname)
这是一个列表的方法,是查找列表中的元素序号

这行报那个错,意思就是 'C:/Users/videos/kick_ball' 这个字符串不在 classes 这个列表里
至于 classes 里是什么,你可以打印出来看。为什么没有,那我们从现有代码是没法判断的,你自己debug一下提供的参数是不是有缺少
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-4-23 20:58 , Processed in 0.016274 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部