【问题标题】:Which is the best way to create a tensor of frames to classify videos with Keras CNN-LSTM这是创建帧张量以使用 Keras CNN-LSTM 对视频进行分类的最佳方法
【发布时间】:2019-01-03 14:24:31
【问题描述】:

大家,我面临以下问题。

我有一个用于视频分类的 CNN-LSTM Keras 模型。我正在尝试创建一个张量来存储我使用 OpenCV 获得的帧,正如您在这段 sn-p 代码中看到的那样:

for i in list1:
    #Video Path
    vid = str(path + i) #path to each video from list1 = os.listdir(path)
    #Reading the Video
    cap = cv2.VideoCapture(vid)
    #To Store Frames
    frames = []
        for j in range(15): #i want 15 frames from each video
        ret, frame = cap.read()
        if ret == True:
            print('Class 1 - Success! {0}'.format(count))
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        frame = cv2.resize(frame,(28,28),interpolation=cv2.INTER_AREA)
        frames.append(frame)
X_data.append(frames)

但问题是我对两类视频重复此代码,我的最终 X_data 的形状是 (2, 15, 28, 28)。一旦我在每个文件夹中有 145 个视频,那不应该有超过 2 个样本吗?

我的想法是在此 X_data 中添加另一列,其中包含目标,1 用于视频类 1,0 用于视频类 2,但是对于这种形状,我不知道我必须做什么。 :/

将每个视频的 15 帧存储在张量中以便使用它来训练分类器 (CNN-LSTM) 是最好的方法吗?

请有人帮助我!

感谢关注!

【问题讨论】:

    标签: python opencv keras deep-learning lstm


    【解决方案1】:
        frames = []  <# You reset frames on each video
            loop to construct frames
    X_data.append(frames) <#You add the frames into X_data but frames only
                            has frames from last video in list1
    

    您可能希望将 X_data 移动到循环中或类似的东西

    这些方面的东西会起作用:

    for class,video_list in enumerate([negative_videos, positive_videos]):
        for i in list1:
            #Video Path
            vid = str(path + i) #path to each video from list1 = os.listdir(path)
            #Reading the Video
            cap = cv2.VideoCapture(vid)
            #To Store Frames
            frames = []
            for j in range(15): #i want 15 frames from each video
                ret, frame = cap.read()
                if ret == True:
                    print('Class 1 - Success! {0}'.format(count))
                frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
                frame = cv2.resize(frame,(28,28),interpolation=cv2.INTER_AREA)
                frames.append(frame)
            X_data.append(frames)
            y_data.append(class)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-20
      • 2019-08-20
      • 2019-06-24
      • 2021-07-15
      • 2021-01-25
      • 2018-07-12
      • 1970-01-01
      相关资源
      最近更新 更多