我目前正在做一个项目,试图创建一个能够对视频中的动作进行分类的机器学习模型。我已经创建了一个脚本,它能够检测视频中的人,并根据身体部位的运动生成数据。这将生成一个具有以下输入形状的4D数组:
(n帧,n人,n身体部位,每个身体部位3个坐标)
仅1个视频(2人),时长3秒,以60fps/s拍摄的输入形状将如下所示:(180,2,25,3)
每个视频的4D数组被保存为numpy文件,所以如果我处理400个视频,我将得到400个numpy文件。
下一步是创建一个keras或tensorflow RNN-LSTM模型,它能够在400个numpy文件上进行训练,并且能够处理每个视频的4D数组,但我真的不知道如何让它工作。我已经寻找了一些解决方案,但我唯一能做的就是Keras只能使用3D数组。
我真的很感谢你的帮助和看法,我可以解决这个问题,希望有一个示例代码。
尊敬的国王,
发布于 2019-05-07 17:53:31
我假设您使用的是numpy.array。可以通过np.resahpe()将4d阵列重塑为3d阵列。文档可以在here上找到。
示例:
import numpy as np
# create a sample 4d array data of shape (10, 2, 25, 3)
data = np.arange(10*2*25*3).reshape((10, 2, 25, 3))
# condense the 4d array to 3d array by explicitly stating the shape.
data_reshaped = data.reshape((10, 2, 75))
# or you can use -1 to ask numpy infer the dimension
data_reshaped2 = data.reshape((10, 2, -1))
# you can also reshape your data into 2d of shape (10, 150)
data_reshaped3 = data.reshape((10, -1))然后,您可以按照在线教程构建您的模型。示例教程可以是this。
注意:您提到"Keras只能使用3D数组“。我认为其中一个维度是为batch_size保留的。因此,我建议您应该将4d数组转换为2d数组。
https://stackoverflow.com/questions/56019327
复制相似问题