【问题标题】:Matlab Distributed Server parfor can't find mex opencv filesMatlab分布式服务器parfor找不到mex opencv文件
【发布时间】:2014-05-15 05:54:36
【问题描述】:

大家!

我正在尝试并行化使用来自 mexopencv(KNearest.m、KNearest_.mexw32)的 mex 文件的算法。

程序是基于vlfeat(vlsift.mex32)+mexopencv(KNearest.m和KNearest_.mexw32)。我对从图片中得到的描述符进行分类。

所有代码都位于文件共享中

\\ LAB-07 \ untitled \ DISTRIB \ (this is the program code) 
\\ LAB-07 \ untitled \ + cv (mexopencv)

当我使用 ma​​tlabpool close 运行程序时,一切正常。

然后我打开 matlabpool(每台 2 核上的 2 台计算机。最终 4 名工人,但现在我只用于测试计算机上的 2 名工人并运行程序) 来自文件共享的路径依赖 -> \LAB-07\untitled\DISTRIB\ , \LAB-07\untitled+cv

在 parfor 循环之前,我在本地机器上训练分类器

classifiers = cv.KNearest
classifiers.train(Descriptors',Labels','MaxK',1)

然后运行 ​​parfor

descr=vlsift(img);
PredictClasses = classifiers.predict(descr');

错误

Error in ==> KNearest>KNearest.find_nearest at 173
Invalid MEX-file '\\LAB-07\untitled\+cv\private\KNearest_.mexw32': 
The specified module could not be found.

KNearest.m 找到,但没有 KNearest_.mexw32。因为 KNearest_.mexw32 位于私人文件夹中,所以我将代码 KNearest.m (它呼吁的所有地方 KNearest_ () 更改为 cv.KNearest_ ()。示例:this.id = сv.KNearest_ ())并放置在一个文件夹中KNearest_.mexw32 KNearest.m。结果,得到同样的错误

matlabpool 在worker上打开文件搜索后立即

pctRunOnAll which ('KNearest.m')
'KNearest.m' not found.
'KNearest.m' not found.
'KNearest.m' not found.

pctRunOnAll which ('KNearest_.mexw32')
'KNearest_.mexw32' not found.
'KNearest_.mexw32' not found.
'KNearest_.mexw32' not found.

在 cd \LAB-07\untitled+cv 之后

 pctRunOnAll which ('KNearest.m')
\\LAB-07\untitled\+cv\KNearest.m
\\LAB-07\untitled\+cv\KNearest.m  % cv.KNearest constructor
\\LAB-07\untitled\+cv\KNearest.m

>> pctRunOnAll which ('KNearest_.mexw32')
\\LAB-07\untitled\+cv\KNearest_.mexw32
\\LAB-07\untitled\+cv\KNearest_.mexw32
\\LAB-07\untitled\+cv\KNearest_.mexw32

我跑了和FileDependecies,但结果一样。

我不知道这是否相关,我在程序执行期间显示分类器 训练之后和parfor之前

classifiers = 

  cv.KNearest handle
  Package: cv

  Properties:
              id: 5
            MaxK: 1
        VarCount: 128
     SampleCount: 9162
    IsRegression: 0

  Methods, Events, Superclasses

在parfor 之前的classifiers.predict 内

classifiers = 

  cv.KNearest handle
  Package: cv

  Properties:
    id: 5

我测试了文件 cvtColor.mexw32。我在一个文件夹中只留下了 2 个文件 cvtColor.mexw32 和 vl_sift

parfor i=1:2
 im1=imread('Copy_of_start40.png');
 im_vl = im2single(rgb2gray(im1));
 desc=vl_sift(im_vl);
 im1 = cvtColor(im1,'RGB2GRAY');
end

同样的错误,并且vl_sift工作,cvtColor没有...

【问题讨论】:

    标签: matlab opencv parallel-processing private parfor


    【解决方案1】:

    如果工作机器可以看到您共享文件系统中的代码,则您根本不需要FileDependenciesPathDependencies。看起来您正在使用 Windows。在我看来,最可能的问题是文件权限。默认情况下,在 Windows 上的作业管理器下运行的 MDCS 工作人员不使用您自己的帐户运行(我认为他们使用“LocalSystem”帐户运行),因此很可能根本无法访问共享文件系统上的文件。您可以尝试确保您的代码是世界可读的。

    否则,您可以使用类似的方法将文件添加到池中

    matlabpool('addfiledependencies', {'\\LAB-07\untitled\+cv'})
    

    请注意,MATLAB 将带有 + 的目录解释为定义“包”,不确定您的情况是否有意这样做。

    编辑

    啊,重新阅读您的原始帖子和下面的 cmets - 我怀疑问题是工作人员看不到您的 MEX 文件所依赖的库。 (这就是“无效的 MEX 文件”消息所指示的内容)。您可以使用http://www.dependencywalker.com/ 来确定您的 MEX 文件的依赖项是什么,并确保它们在工作人员上可用(我认为他们需要在 %PATH% 或当前目录中)。

    【讨论】:

    • 是的,我使用自己的帐户运行 mdcs 服务。难道是 for parfor 循环 mex 文件必须用特殊规则编译? vl_sift.mexw32 已经被开发者编译好了,但是我使用 Visual Studio 2010 编译器编译了 mex opencv。
    • 哦,埃德里克,非常感谢您!我几乎解决了我的问题。请阅读下面的答案,您能帮忙吗?
    【解决方案2】:

    埃德里克谢谢。 parfor 的 PATH 存在问题。用http://www.dependencywalker.com/ 查找丢失的文件并将它们放在文件夹+cv 中。只有这种方法适用于 parfor。

    但是 parfor 中的 predict 给出了错误

    PredictClasses = classifiers.predict(descr');
    
    ??? Error using ==> parallel_function at 598
    Error in ==> KNearest>KNearest.find_nearest at 173
    Unexpected Standard exception from MEX file.
    
    What() is:..\..\..\src\opencv\modules\ml\src\knearest.cpp:365: error: (-2) The search
    tree must be constructed first using train method
    

    我通过每次在 parfor train

    中调用来解决这个问题
    classifiers = cv.KNearest
    classifiers.train(Descriptors',Labels','MaxK',1)
    

    但这是一个丑陋的解决方案:)

    【讨论】:

    • parfor 循环之前的spmd 块内执行train 部分就足够了?这样可以确保每个工作 MATLAB 只执行一次该内容。
    猜你喜欢
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多