Skip to content

scipy.io.matlab.miobase.MatReadError: Mat file appears to be empty #21

@NHZlX

Description

@NHZlX

matlab:2014a
python:2.7
ubuntu

here is the selective_search.py:
import tempfile
import subprocess
import shlex
import os
import numpy as np
import scipy.io

script_dirname = os.path.abspath(os.path.dirname(file))

def get_windows(image_fnames, cmd='selective_search'):
"""
Run MATLAB Selective Search code on the given image filenames to
generate window proposals.

Parameters

image_filenames: strings
Paths to images to run on.
cmd: string
selective search function to call:
- 'selective_search' for a few quick proposals
- 'selective_seach_rcnn' for R-CNN configuration for more coverage.
"""

Form the MATLAB script command that processes images and write to

temporary results file.

f, output_filename = tempfile.mkstemp(suffix='.mat')
os.close(f)
fnames_cell = '{' + ','.join("'{}'".format(x) for x in image_fnames) + '}'
command = "{}({}, '{}')".format(cmd, fnames_cell, output_filename)
print(command)

Execute command in MATLAB.

mc = "matlab -nojvm -r "try; {}; catch; exit; end; exit"".format(command)
pid = subprocess.Popen(
shlex.split(mc), stdout=open('NUL', 'w'), cwd=script_dirname)
retcode = pid.wait()
if retcode != 0:
raise Exception("Matlab script did not exit successfully!")

Read the results and undo Matlab's 1-based indexing.

all_boxes = list(scipy.io.loadmat(output_filename)['all_boxes'][0])
subtractor = np.array((1, 1, 0, 0))[np.newaxis, :]
all_boxes = [boxes - subtractor for boxes in all_boxes]

Remove temporary file, and return.

os.remove(output_filename)
if len(all_boxes) != len(image_fnames):
raise Exception("Something went wrong computing the windows!")
return all_boxes
if name == 'main':
"""
Run a demo.
"""
import time

image_filenames = [
script_dirname + '\000015.jpg',
script_dirname + '\cat.jpg'
] * 4
t = time.time()
boxes = get_windows(image_filenames)
print(boxes[:2])
print("Processed {} images in {:.3f} s".format(
len(image_filenames), time.time() - t))
when i run python selective_search.py in cmd:
it have problem:
selective_search({'D:\selective_search_ijcv_with_python\selective_search_ijcv_wi
th_python\000015.jpg','D:\selective_search_ijcv_with_python\selective_search_ijc
v_with_python\cat.jpg','D:\selective_search_ijcv_with_python\selective_search_ij
cv_with_python\000015.jpg','D:\selective_search_ijcv_with_python\selective_searc
h_ijcv_with_python\cat.jpg','D:\selective_search_ijcv_with_python\selective_sear
ch_ijcv_with_python\000015.jpg','D:\selective_search_ijcv_with_python\selective_
search_ijcv_with_python\cat.jpg','D:\selective_search_ijcv_with_python\selective
_search_ijcv_with_python\000015.jpg','D:\selective_search_ijcv_with_python\selec
tive_search_ijcv_with_python\cat.jpg'}, 'c:\users\lh7610~1.arc\appdata\local\tem
p\tmpp6f4z8.mat')
Traceback (most recent call last):
File "selective_search.py", line 63, in
boxes = get_windows(image_filenames)
File "selective_search.py", line 42, in get_windows
all_boxes = list(scipy.io.loadmat(output_filename)['all_boxes'][0])
File "D:\python\lib\site-packages\scipy\io\matlab\mio.py", line 135, in loadma
t
MR = mat_reader_factory(file_name, appendmat, **kwargs)
File "D:\python\lib\site-packages\scipy\io\matlab\mio.py", line 59, in mat_rea
der_factory
mjv, mnv = get_matfile_version(byte_stream)
File "D:\python\lib\site-packages\scipy\io\matlab\miobase.py", line 224, in ge
t_matfile_version
raise MatReadError("Mat file appears to be empty")
scipy.io.matlab.miobase.MatReadError: Mat file appears to be empty

1.the path of my picture is right.
2.i check the c:\users\lh7610~1.arc\appdata\local\temp and found no mat file.
3.i think the matlab cannot produce the mat file even though it has right picture path.
4.i have put the path "D:\selective_search_ijcv_with_python\selective_search_ijcv_with_python" in PYTHONPATH , caffe_ROOT and path.
5.when i "python selective_search",i can see matlab commit windows and disappear in a while.
who can help me!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions