scipy.io.matlab IOError: could not read bytes

python2.7

scipy 1.2.2

 

代码:

import scipy
from scipy.io import matlab
mat = matlab.loadmat(filename)

报错:

Traceback (most recent call last):
  File "syn_data/rep_pickle.py", line 57, in 
    frames, labels = load_rep_dataset(mat_file)
  File "syn_data/rep_pickle.py", line 32, in load_rep_dataset
    mat = matlab.loadmat(filename)
  File "/home/user/.local/lib/python2.7/site-packages/scipy/io/matlab/mio.py", line 208, in loadmat
    matfile_dict = MR.get_variables(variable_names)
  File "/home/user/.local/lib/python2.7/site-packages/scipy/io/matlab/mio5.py", line 292, in get_variables
    res = self.read_var_array(hdr, process)
  File "/home/user/.local/lib/python2.7/site-packages/scipy/io/matlab/mio5.py", line 252, in read_var_array
    return self._matrix_reader.array_from_header(header, process)
  File "mio5_utils.pyx", line 675, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header
  File "mio5_utils.pyx", line 721, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header
  File "mio5_utils.pyx", line 894, in scipy.io.matlab.mio5_utils.VarReader5.read_cells
  File "mio5_utils.pyx", line 673, in scipy.io.matlab.mio5_utils.VarReader5.read_mi_matrix
  File "mio5_utils.pyx", line 705, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header
  File "mio5_utils.pyx", line 778, in scipy.io.matlab.mio5_utils.VarReader5.read_real_complex
  File "mio5_utils.pyx", line 450, in scipy.io.matlab.mio5_utils.VarReader5.read_numeric
  File "mio5_utils.pyx", line 355, in scipy.io.matlab.mio5_utils.VarReader5.read_element
  File "streams.pyx", line 195, in scipy.io.matlab.streams.ZlibInputStream.read_string
  File "streams.pyx", line 188, in scipy.io.matlab.streams.ZlibInputStream.read_into
IOError: could not read bytes

原因:.mat文件不完整,可能是由于下载或者上传中断的原因造成的。

解决方法:重新下载或上传出错的.mat文件。

致谢:https://github.com/anishathalye/neural-style/issues/47

你可能感兴趣的:(Python,ML,#,DL-数据预处理)