视频识别的数据集的加载(loadvideo)


    def __getitem__(self, index):
        # loading and preprocessing. TODO move them to transform classes
        buffer = self.loadvideo(self.fnames[index])

        while buffer.shape[0]<self.clip_len+2 :
            index = np.random.randint(self.__len__())
            buffer = self.loadvideo(self.fnames[index])

        if self.mode == 'train' or self.mode == 'training':
            buffer = self.randomflip(buffer)
        buffer = self.crop(buffer, self.clip_len, self.crop_size)
        buffer = self.normalize(buffer)
        buffer = self.to_tensor(buffer)

        return buffer, self.label_array[index]


# create a buffer. Must have dtype float, so it gets converted to a FloatTensor by Pytorch later

buffer = np.empty((frame_count_sample, resize_height, resize_width, 3), np.dtype('float32'))
capture = cv2.VideoCapture(fname)
retaining, frame = capture.read()

猜你喜欢

转载自blog.csdn.net/tony2278/article/details/105633523