selective_search_ijcv_with_python
selective_search_ijcv_with_python copied to clipboard
scipy.io.matlab.miobase.MatReadError: Mat file appears to be empty
matlab:2014a python:2.7 windows
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
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!!
The problem is, that the executing line of the code, that calls matlab script, doesn't wait for it to end. So the file is generated, but not yet finished. The simplest way is to put a timer after the python line, which calls the matlab script.
If you are using mac for this code, may be you can try this answer: https://www.mathworks.com/matlabcentral/answers/303369-mex-cannot-find-a-supported-compiler-in-matlab-r2015b-after-i-upgraded-to-xcode-8-0
Here is my solution: Download the original Matlab code using script: https://github.com/nightrome/matconvnet-calvin/blob/master/matconvnet-calvin/matlab/setup/downloadSelectiveSearch.m
copy the python code plus selective_search.m from current repo.