- 帖子
- 3
- 精华
- 0
- 积分
- 18
- 阅读权限
- 10
- 注册时间
- 2019-12-5
- 最后登录
- 2022-5-24
|
从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)
|
|