错误代码

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. 洛谷P2484 [SDOI2011]打地鼠

    P2484 [SDOI2011]打地鼠 题目描述 打地鼠是这样的一个游戏:地面上有一些地鼠洞,地鼠们会不时从洞里探出头来很短时间后又缩回洞中.玩家的目标是在地鼠伸出头时,用锤子砸其头部,砸到的地鼠越多 ...

  2. thinkphp5控制器访问转换问题

    假设定义了HelloWorld控制器 url访问地址就是:http://localhost/index.php/index/hello_world,与此同时view目录下的模板文件夹要命名为hello ...

  3. Leetcode初级算法(排序和搜索+数学篇)

    合并两个有序数组 开始的时候将这道题理解错了,发现几个奇怪的测试案例后才明白这道题什么意思.本来的想法就是把nums2全部放到num1里面,然后删除重复元素.排序一下,就有了下面的代码: class ...

  4. FTP原理与配置

    FTP(file transfer protocol)文件传输协议(基于tcp协议).是用来传送文件的协议,使用FTP实现文件传输的同时,还可以保证数据传输的可靠性和高效性.通过学习我们需要掌握以下两 ...

  5. 2017 ACM/ICPC Asia Regional Shenyang Online transaction transaction transaction

    Problem Description Kelukin is a businessman. Every day, he travels around cities to do some busines ...

  6. Django---登录(含随机生成图片验证码)、注册示例讲解

    登录(验证码).注册功能具体代码 # urls.py from django.contrib import admin from django.urls import path from app01 ...

  7. maven插件: shade, assembly

    shade插件的作用: 通过版本的exclution无法解决jar冲突的问题, 解决方案是把依赖的包打到本model的jar中,打包的时候由mvn plugin自动修改代码中的依赖jar包名 relo ...

  8. 练习二十二:python兵乓求比赛顺序练习,关于连个兵乓球队进行比赛

    已知有两支兵乓球队进行比赛,每队各出3人: 甲队有a,b,c三人,乙队有x,y,z三人,已抽签决定比赛名单 问题:有人向队员打听比赛名单.a说他不和X比,c说他不和x,z比,程序找出比赛对手 方法一: ...

  9. 【ACM】取石子 - 博弈论

    取石子(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 一天,TT在寝室闲着无聊,和同寝的人玩起了取石子游戏,而由于条件有限,他/她们是用旺仔小馒头当作石子.游 ...

  10. 牛客网Java刷题知识点之构造函数可以调用一般函数,但是一般函数不可以直接调用构造函数

    不多说,直接上干货! 通过 牛客网Java刷题知识点之构造函数是什么.一般函数和构造函数什么区别呢.构造函数的重载.构造函数的内存图解 我们对构造函数有了一个比较清楚的认识,当我们在创建对象时,我们会 ...