我得到(在这个案例中,使用共享文件是个好主意):
装载:data = io.loadmat('../Downloads/anno_bbox.mat')
我得到:
^{2}$
我可以指定bbox_test=data['bbox_test']。这个变量有9658条记录,有三个字段,每个字段都有object dtype。在
所以有一个文件名(嵌入在1元素数组中的字符串)In [101]: data['bbox_test'][0,0]['filename']
Out[101]: array(['HICO_test2015_00000001.jpg'], dtype='
size有3个字段,在数组中嵌入了3个数字(2d matlab矩阵):In [102]: data['bbox_test'][0,0]['size']
Out[102]:
array([[(array([[640]], dtype=uint16), array([[427]], dtype=uint16), array([[3]], dtype=uint8))]],
dtype=[('width', 'O'), ('height', 'O'), ('depth', 'O')])
In [112]: data['bbox_test'][0,0]['size'][0,0].item()
Out[112]:
(array([[640]], dtype=uint16),
array([[427]], dtype=uint16),
array([[3]], dtype=uint8))
hoi更复杂:In [103]: data['bbox_test'][0,0]['hoi']
Out[103]:
array([[(array([[246]], dtype=uint8), array([[(array([[320]], dtype=uint16), array([[359]], dtype=uint16), array([[306]], dtype=uint16), array([[349]], dtype=uint16)),...
dtype=[('id', 'O'), ('bboxhuman', 'O'), ('bboxobject', 'O'), ('connection', 'O'), ('invis', 'O')])
In [126]: data['bbox_test'][0,1]['hoi']['id']
Out[126]:
array([[array([[132]], dtype=uint8), array([[140]], dtype=uint8),
array([[144]], dtype=uint8)]], dtype=object)
In [130]: data['bbox_test'][0,1]['hoi']['bboxhuman'][0,0]
Out[130]:
array([[(array([[226]], dtype=uint8), array([[340]], dtype=uint16), array([[18]], dtype=uint8), array([[210]], dtype=uint8))]],
dtype=[('x1', 'O'), ('x2', 'O'), ('y1', 'O'), ('y2', 'O')])
因此,在MATLAB结构中显示的数据都在那里,在数组(通常是2d(1,1)形状)、对象数据类型或多个字段的嵌套结构中。在
返回并加载squeeze_me我得到了一个更简单的:In [133]: data['bbox_test'][1]['hoi']['bboxhuman']
Out[133]:
array([array((226, 340, 18, 210),
dtype=[('x1', 'O'), ('x2', 'O'), ('y1', 'O'), ('y2', 'O')]),
array((230, 356, 19, 212),
dtype=[('x1', 'O'), ('x2', 'O'), ('y1', 'O'), ('y2', 'O')]),
array((234, 342, 13, 202),
dtype=[('x1', 'O'), ('x2', 'O'), ('y1', 'O'), ('y2', 'O')])],
dtype=object)
使用struct_as_record='False',我得到In [136]: data['bbox_test'][1]
Out[136]:
查看此rec的属性,我可以通过属性名访问“fields”:In [137]: rec = data['bbox_test'][1]
In [138]: rec.filename
Out[138]: 'HICO_test2015_00000002.jpg'
In [139]: rec.size
Out[139]:
In [141]: rec.size.width
Out[141]: 640
In [142]: rec.hoi
Out[142]:
array([,
,
],
dtype=object)
In [145]: rec.hoi[1].bboxhuman
Out[145]:
In [146]: rec.hoi[1].bboxhuman.x1
Out[146]: 230
In [147]: vars(rec.hoi[1].bboxhuman)
Out[147]:
{'_fieldnames': ['x1', 'x2', 'y1', 'y2'],
'x1': 230,
'x2': 356,
'y1': 19,
'y2': 212}
等等。在