错误代码

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代码中出现的错误的更多相关文章

  1. webservice 服务端例子+客户端例子+CXF整合spring服务端测试+生成wsdl文件 +cxf客户端代码自动生成

    首先到CXF官网及spring官网下载相关jar架包,这个不多说.webservice是干嘛用的也不多说. 入门例子 模拟新增一个用户,并返回新增结果,成功还是失败. 大概的目录如上,很简单. Res ...

  2. Kivy A to Z -- 怎样从python代码中直接訪问Android的Service

    在Kivy中,通过pyjnius扩展能够间接调用Java代码,而pyjnius利用的是Java的反射机制.可是在Python对象和Java对象中转来转去总让人感觉到十分别扭.好在android提供了b ...

  3. Android color(颜色) 在XML文件和java代码中

    Android color(颜色) 在XML文件和java代码中,有需要的朋友可以参考下. 1.使用Color类的常量,如: int color = Color.BLUE;//创建一个蓝色 是使用An ...

  4. pycharm运行Pytest,有没有将Pytest写入Python代码中的区别

    初学pytest. 将pytest写进Python代码中 不同运行方式都可正常运行     =======================**********************========= ...

  5. python代码中判断版本

    在python代码中判断python版本: if sys.version_info < (3, 0): lib.make_flows.argtypes = [c_char_p, c_char_p ...

  6. C语言初学者代码中的常见错误与瑕疵(23)

    见:C语言初学者代码中的常见错误与瑕疵(23)

  7. 一个超复杂的间接递归——C语言初学者代码中的常见错误与瑕疵(6)

    问题: 问题出处见 C语言初学者代码中的常见错误与瑕疵(5) . 在该文的最后,曾提到完成的代码还有进一步改进的余地.本文完成了这个改进.所以本文讨论的并不是初学者代码中的常见错误与瑕疵,而是对我自己 ...

  8. C语言初学者代码中的常见错误与瑕疵(5)

    问题: 素数 在世博园某信息通信馆中,游客可利用手机等终端参与互动小游戏,与虚拟人物Kr. Kong 进行猜数比赛. 当屏幕出现一个整数X时,若你能比Kr. Kong更快的发出最接近它的素数答案,你将 ...

  9. C语言初学者代码中的常见错误与瑕疵(19)

    见:C语言初学者代码中的常见错误与瑕疵(19)

随机推荐

  1. 通过jQuery实现AJAX

    通过jQuery实现AJAX > 使用get和getJSON都会有缓存问题,并且使用get方法不能传送较多的数据. 问题: 在IE浏览器中,get请求使用ajax存在缓存问题,会使用上一次请求的 ...

  2. [APIO2019T1]奇怪装置

    考古学家发现古代文明留下了一种奇怪的装置.该装置包含两个屏幕,分别显示两个整数x和y.经过研究,科学家对该装置得出了一个结论:该装置是一个特殊的时钟,它从过去的某个时间点开始测量经过的时刻数t,但该装 ...

  3. oracle odbc连接sqlserver 无法查询字段

    最近因项目需要,需要在oracle数据库里面通过DBLINK方式链接SQLserver数据库(oracle 11G,Sqlserver2016,具体实现参考链接 http://blog.sina.co ...

  4. jsp 文件上传操作

    文件上传 1:完成一个文件上传的功能 index.jsp 注意更换form表单的enctype enctype就是encodetype就是编码类型的意思. multipart/form-data是指表 ...

  5. 理解js继承的6种方式

    想要继承,就必须要提供个父类(继承谁,提供继承的属性) 一.原型链继承 重点:让新实例的原型等于父类的实例. 特点:1.实例可继承的属性有:实例的构造函数的属性,父类构造函数属性,父类原型的属性.(新 ...

  6. Maven_setting.xml

    <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...

  7. Ubuntu14.04下sogou输入法的输入框只显示英文不显示中文的问题

    解决方法:首先强制更新,把依赖文件全部安装 sudo apt-get install -f 如果仍然不管用,删除sogou的配置文件,在~/.config目录下,一般情况下是SogouPY.Sogou ...

  8. ubuntu apache2 https

    1. enable the module ssl by: sudo a2enmod ssl 2.after you have enabled module ssl , you will have to ...

  9. 查看Memcache运行状况

    Memcache Memcache是danga.com的一个开源项目,它是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的Hash表,能够用来存储各种格式的数据. 查看当前的me ...

  10. ssh无需密码登录linux服务器

    使用下例中ssky-keygen和ssh-copy-id,仅需通过3个步骤的简单设置而无需输入密码就能登录远程Linux主机. ssh-keygen 创建公钥和密钥. ssh-copy-id 把本地主 ...