关于在Python中利用scipy读取mat文件的问题

事情是这样的,我在matlab中有这样一句话

save(filepath,'TPLBP_ss_codeI');

以此将处理好的TPLBP特征存储在mat文件中,一晚上跑出了几万幅图片,然后第二天我打算用python读取一下,再做一些预处理然后存储成npy格式,

import scipy.io as scio  
...
derictors = scio.loadmat(dir_name) #dict
...
np.save("/home/mashuyang/keras_files/data-FPLBP/X_train_FPLBP"+str(split)+".npy",X_train_array)

当然他们都暗藏在循环中,在对很多个mat执行正确之后,出现了以下错误:

Loading Jake_Plummer files ( Index: 539/920)
Loading Katharine_Hepburn files ( Index: 540/920)
Loading Kenenisa_Bekele files ( Index: 541/920)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
 in ()
     21         for video in videos:
     22             dir_name=os.path.join(dir_video+'/',video)
---> 23             derictors = scio.loadmat(dir_name) #dict
     24             features=derictors.keys()
     25             X_train_buff=[]

/usr/local/lib/python3.5/dist-packages/scipy/io/matlab/mio.py in loadmat(file_name, mdict, appendmat, **kwargs)
    140     variable_names = kwargs.pop('variable_names', None)
    141     MR, file_opened = mat_reader_factory(file_name, appendmat, **kwargs)
--> 142     matfile_dict = MR.get_variables(variable_names)
    143     if mdict is not None:
    144         mdict.update(matfile_dict)

/usr/local/lib/python3.5/dist-packages/scipy/io/matlab/mio5.py in get_variables(self, variable_names)
    290                 continue
    291             try:
--> 292                 res = self.read_var_array(hdr, process)
    293             except MatReadError as err:
    294                 warnings.warn(

/usr/local/lib/python3.5/dist-packages/scipy/io/matlab/mio5.py in read_var_array(self, header, process)
    250            `process`.
    251         '''
--> 252         return self._matrix_reader.array_from_header(header, process)
    253 
    254     def get_variables(self, variable_names=None):

mio5_utils.pyx in scipy.io.matlab.mio5_utils.VarReader5.array_from_header()

mio5_utils.pyx in scipy.io.matlab.mio5_utils.VarReader5.array_from_header()

ValueError: Did not fully consume compressed contents of an miCOMPRESSED element. This can indicate that the .mat file is corrupted.

重点就在最后那一句的 “ Did not fully consume compressed contents of an miCOMPRESSED element. This can indicate that the .mat file is corrupted.” 

于是我就查了这个错误,百度里什么都没查到,必应里我找到了这个:

https://stackoverflow.com/questions/42607271/unable-to-read-mat-file-with-scipy?answertab=active#tab-top

这里边的说法是mat文件的版本问题,由于需要运行一晚上才能跑一次,所以现在还没有结果,一天以后再来更新。

 

 

————————————前来抱歉的分割线——————————————

最近找工作就没看这边,说好第二天更新的,抱歉抱歉

 

我记得我是在matlab里用了这个解决的,

save(filename, 'data', '-v6');

就是我的问题还是关于mat的版本问题,默认生成的好像是最高版本,而Python不能读取,而为什么那么多偏偏这个不行,仿佛是因为我的这个出问题的文件格外大一些,希望能帮到看见的人 

你可能感兴趣的:(python,调试,matlab,硕)