生成.m文件的python代码中出现的错误
错误代码
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_rcnn',image_tag):
"""
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(prefix = '{}'.format(image_tag),suffix='.mat',dir='/home/bnrc/formatm')
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('/dev/null', '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_tag = '/000015.jpg'
image_filenames = [
script_dirname + '/000015.jpg',
script_dirname + '/cat.jpg'
]
t = time.time()
#boxes = get_windows(image_filenames)
boxes = get_windows(image_filenames,cmd='selective_search_rcnn',image_tag)
print(boxes[:2])
print("Processed {} images in {:.3f} s".format(
len(image_filenames), time.time() - t))
报的错误:

非默认的参数在默认参数之后。image_tag这个参数在cmd之后,但cmd是默认参数的,image_tag不是默认的。
修改代码
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, image_tag,cmd='selective_search_rcnn'):
"""
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(prefix = '{}'.format(image_tag),suffix='.mat',dir='/home/bnrc/formatm')
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('/dev/null', '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_tag = '/000015.jpg'
image_filenames = [
script_dirname + '/000015.jpg',
script_dirname + '/cat.jpg'
]
t = time.time()
#boxes = get_windows(image_filenames)
boxes = get_windows(image_filenames,image_tag)
print(boxes[:2])
print("Processed {} images in {:.3f} s".format(
len(image_filenames), time.time() - t))
之后又报错:

这个把image_tag里的/删除掉就好了
生成.m文件的python代码中出现的错误的更多相关文章
- webservice 服务端例子+客户端例子+CXF整合spring服务端测试+生成wsdl文件 +cxf客户端代码自动生成
首先到CXF官网及spring官网下载相关jar架包,这个不多说.webservice是干嘛用的也不多说. 入门例子 模拟新增一个用户,并返回新增结果,成功还是失败. 大概的目录如上,很简单. Res ...
- Kivy A to Z -- 怎样从python代码中直接訪问Android的Service
在Kivy中,通过pyjnius扩展能够间接调用Java代码,而pyjnius利用的是Java的反射机制.可是在Python对象和Java对象中转来转去总让人感觉到十分别扭.好在android提供了b ...
- Android color(颜色) 在XML文件和java代码中
Android color(颜色) 在XML文件和java代码中,有需要的朋友可以参考下. 1.使用Color类的常量,如: int color = Color.BLUE;//创建一个蓝色 是使用An ...
- pycharm运行Pytest,有没有将Pytest写入Python代码中的区别
初学pytest. 将pytest写进Python代码中 不同运行方式都可正常运行 =======================**********************========= ...
- python代码中判断版本
在python代码中判断python版本: if sys.version_info < (3, 0): lib.make_flows.argtypes = [c_char_p, c_char_p ...
- C语言初学者代码中的常见错误与瑕疵(23)
见:C语言初学者代码中的常见错误与瑕疵(23)
- 一个超复杂的间接递归——C语言初学者代码中的常见错误与瑕疵(6)
问题: 问题出处见 C语言初学者代码中的常见错误与瑕疵(5) . 在该文的最后,曾提到完成的代码还有进一步改进的余地.本文完成了这个改进.所以本文讨论的并不是初学者代码中的常见错误与瑕疵,而是对我自己 ...
- C语言初学者代码中的常见错误与瑕疵(5)
问题: 素数 在世博园某信息通信馆中,游客可利用手机等终端参与互动小游戏,与虚拟人物Kr. Kong 进行猜数比赛. 当屏幕出现一个整数X时,若你能比Kr. Kong更快的发出最接近它的素数答案,你将 ...
- C语言初学者代码中的常见错误与瑕疵(19)
见:C语言初学者代码中的常见错误与瑕疵(19)
随机推荐
- hdu 2147 kiki's game(巴什博弈)
kiki's game HDU - 2147 题意:一个n*m的表格,起始位置为右上角,目标位置为左下角,甲先开始走,走的规则是可以向左,向下或者向左下(对顶的)走一格.谁先走到目标位置谁就胜利.在甲 ...
- [Xcode 实际操作]五、使用表格-(7)UITableView单元格间隔背景色
目录:[Swift]Xcode实际操作 本文将演示如何给表格设置间隔的背景颜色. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit //首先 ...
- html_entity_decode与htmlentities函数
htmlentities() 函数把字符转换为 HTML 实体.html_entity_decode() 函数把 HTML 实体转换为字符.例子:$a = '<div> <p> ...
- 洛谷 P2661 信息传递(并查集 & 最小环)
嗯... 题目链接:https://www.luogu.org/problemnew/show/P2661 这道题和一些比较水的并查集不太一样,这道题的思路就是用并查集来求最小环... 首先,如果我们 ...
- web性能优化--缓存
什么是缓存? 缓存(Web缓存)是指代理服务器和客户端本地磁盘保存的资源副本.当 web 缓存发现请求的资源已经被存储,它会拦截请求,返回该资源的拷贝,而不会去源服务器重新下载. 缓存大致可以分为私 ...
- vuex和localStorage/sessionStorage 区别
1.最重要的区别:vuex存储在内存,localstorage则以文件的方式存储在本地 2.应用场景:vuex用于组件之间的传值,(响应式的),localstorage则主要用于不同页面之间的传值(其 ...
- java insert mysql 中文乱码
jdbc:mysql://192.168.1.77:3306/db360?useUnicode=true&characterEncoding=UTF-8 drop database if ex ...
- 009 Palindrome Number 判断一个正整数是否是回文数
详见:https://leetcode.com/problems/palindrome-number/description/ 实现语言:Java 方法一: class Solution { publ ...
- poj3254(状压dp入门第一道题,很详细)
题目链接:http://poj.org/problem?id=3254 学习博客:https://blog.csdn.net/harrypoirot/article/details/23163485 ...
- Java面向对象_单例设计模式
单例设计模式:保证一个类仅有一个实例,并提供一个访问它的全局访问点 1.构造方法私有化 2.声明一个本类对象 3.给外部提供一个静态方法获取对象实例 两种实现方式:饿汉式和懒汉式 何种情况下使用呢?当 ...