生成.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)
随机推荐
- 【Kafka】《Kafka权威指南》入门
发布与订阅消息系统 在正式讨论Apache Kafka (以下简称Kafka)之前,先来了解发布与订阅消息系统的概念, 并认识这个系统的重要性.数据(消息)的发送者(发布者)不会直接把消息发送给接收 ...
- Windows平台Anaconda使用笔记
1.官网下载anaconda安装. 2.将命令行工具路径加入系统环境变量 C:\ProgramData\Anaconda3\ScriptsC:\ProgramData\Anaconda3\Librar ...
- PHP 获取acm近期比赛
<?php // author: Moore Jiang. ini_set('display_errors',1); //错误信息 ini_set('display_startup_errors ...
- Codeforces Round #129 (Div. 2) B
Description The Little Elephant loves sortings. He has an array a consisting of n integers. Let's nu ...
- 15-----float(浮动)
浮动 浮动是css里面布局最多的一个属性,也是很重要的一个属性. float:表示浮动的意思.它有四个值. none: 表示不浮动,默认 left: 表示左浮动 right:表示右浮动 看一个例子: ...
- PartTime__学习辅助软件_20161025
1.http://www.680.com/ruanjian/412629.html 1.1.http://www.gysjxjy.com/ 密码:我的名字的拼音(全小写) 使用的身份证信息:http: ...
- Soft skill
不要害怕让别人看到自己的无知 作为高级程序员的一个好处是,当别人问一些我不懂的问题时,我可以很淡然地告诉他们: 这个东西我也不懂,因为以前没有遇到过,不过我可以看一下,然后再告诉你. 当我还是一个初级 ...
- C 碎片二 数据类型
一.概述 C 语言包含的数据类型如下图所示: 二.各种数据类型介绍 2.1 整型 整形包括短整型.整形和长整形. 2.1.1 短整形 short a=1; 2.1.2 整形 一般占4个字节(32位), ...
- mybatis批量插入插入数据、批量条件查询
ps:参考文章连接:https://www.cnblogs.com/admol/articles/4248159.html 关于个人的使用经验:先把数据放到bean中,多个的话就全放入list集合,如 ...
- 使用AOP监控用户操作并插入数据库
引入依赖 <!--spring切面aop依赖--> <dependency> <groupId>org.springframework.boot</group ...