gpt4 book ai didi

python - 在 MPII 人体姿势数据集上训练 Keras 分类器

转载 作者:行者123 更新时间:2023-11-30 09:28:34 30 4
gpt4 key购买 nike

我正在尝试使用 MPII 人体姿势数据集(找到 here )在 Keras 中训练神经网络。默认情况下,数据集采用 MATLAB 格式,但我使用 scipy.io.loadmat 将其加载到 Numpy 数组中。但是,我无法理解它生成的对象 - 它似乎包含一个名为 'RELEASE' 的键以及作为值的数据集的注释。我的问题是我不知道如何访问数据集并将其拆分为注释。

我非常感谢有关此问题的帮助。

最佳答案

MPII数据annotations.mat文件来自matlab,它是matlab中的一个struct类型,所以如果你想使用scipy.io.loadmat处理它,你应该添加这样的参数:

matph = './mpii_human_pose_v1_u12_1.mat'
mat = sio.loadmat(matph, struct_as_record=False) # add here

让我们打印垫子:

{'RELEASE': array([[<scipy.io.matlab.mio5_params.mat_struct object at 0x7f7b0ba51790>]],
dtype=object), '__version__': '1.0', '__header__': 'MATLAB 5.0 MAT-file, Platform: GLNXA64, Created on: Tue Sep 23 22:09:02 2014', '__globals__': []}

它是一本字典,所以我们得到它的值:

release = mat['RELEASE']

让我们打印版本的一些属性:

print(release, type(release), release.shape)
(array([[<scipy.io.matlab.mio5_params.mat_struct object at 0x7fd407de1790>]],
dtype=object), <type 'numpy.ndarray'>, (1, 1))

release是一个数组,其元素是scipy.io.matlab.mio5_params.mat_struct对象,这里我们可以使用该对象的两个方法:__dict___fieldnames,例如这个:

object1 = release[0,0]
print(object1._fieldnames)
['annolist', 'img_train', 'version', 'single_person', 'act', 'video_list']
annolist = object1.__dict__['annolist']
print(annolist, type(annolist), annolist.shape)
(array([[<scipy.io.matlab.mio5_params.mat_struct object at 0x7fd407de1810>,
<scipy.io.matlab.mio5_params.mat_struct object at 0x7fd407de1850>,
<scipy.io.matlab.mio5_params.mat_struct object at 0x7fd407de1910>,
...,
<scipy.io.matlab.mio5_params.mat_struct object at 0x7fd3db7f1710>,
<scipy.io.matlab.mio5_params.mat_struct object at 0x7fd3db7f1c50>,
<scipy.io.matlab.mio5_params.mat_struct object at 0x7fd3db794490>]],
dtype=object), <type 'numpy.ndarray'>, (1, 24987))

我们得到一个包含 24987 个元素的数组,其中也是 scipy.io.matlab.mio5_params.mat_struct 对象。那么我们就可以继续研究了:

anno1 = annolist[0,0]
print(anno1._fieldnames)
['image', 'annorect', 'frame_sec', 'vididx']
annorect = anno1.__dict__['annorect']
print(annorect, type(annorect), annorect.shape)
(array([[<scipy.io.matlab.mio5_params.mat_struct object at 0x7fd407de19d0>,
<scipy.io.matlab.mio5_params.mat_struct object at 0x7fd407de1710>]],
dtype=object), <type 'numpy.ndarray'>, (1, 2))
anno2 = annorect[0,0]
print(anno2._fieldnames)
['scale', 'objpos']
objpos = anno2.__dict__['objpos']
print(objpos, type(objpos), objpos.shape)
(array([[<scipy.io.matlab.mio5_params.mat_struct object at 0x7fd398204b90>]],
dtype=object), <type 'numpy.ndarray'>, (1, 1))
objpos1 = objpos[0,0]
print(objpos1._fieldnames)
['x', 'y']
y = objpos1.__dict__['y']
print(y, type(y), y.shape)
(array([[210]], dtype=uint8), <type 'numpy.ndarray'>, (1, 1))

关于python - 在 MPII 人体姿势数据集上训练 Keras 分类器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51748087/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com