-2

I have been trying for days, searching for the proper way to read this file in my python project. Which is an ordinary matlab datastructure file.

https://drive.google.com/open?id=1E1w1eQn6pTcQ1lkhGMJzmB5ugtmaDPht

I am familiar about how to read h5 files which seems to be the case with this .mat file since it doesn't allow scipy.loadmat to read it. So I used h5py.Read().

import h5py
f = h5py.File('./imgIdx.mat','r')
d = f['imgIdx/anno']
print(d[1000])     # accessing an arbitrary object

[<HDF5 object reference>]

Which is an object that I can't deal with This is supposed to be a m x 4 matrix where m >= 0

mahmoud fathy
  • 361
  • 1
  • 7
  • 17

1 Answers1

1

Following hints from the object reference section in the docs: http://docs.h5py.org/en/latest/refs.html

In [348]: d = f['imgIdx/anno']
In [349]: d[1000]
Out[349]: array([<HDF5 object reference>], dtype=object)
In [350]: d[1000].item()
Out[350]: <HDF5 object reference>
In [351]: f[d[1000].item()]
Out[351]: <HDF5 dataset "N4": shape (4, 2), type "<f8">
In [352]: f[d[1000].item()][:]
Out[352]: 
array([[ 87., 447.],
       [158., 160.],
       [446., 586.],
       [325., 283.]])

I also used h5dump in the shell to look at the file and its contents.

hpaulj
  • 221,503
  • 14
  • 230
  • 353