1

我使用PASCAL开发工具包与Felzenszwalb,D.McAllester,D.Ramaman及其团队开发的Discriminatively deformable part model system系统训练模型存在问题在Matlab中。索引超过训练模型时遇到的矩阵维数

目前我有这种输出错误,当我试图训练一个1分量模型'猫'使用10个正面和10个负面图像。

Error: 

??? Index exceeds matrix dimensions. 

Error in ==> pascal_train at 48 
models{i} = train(cls, models{i}, spos{i}, neg(1:maxneg), 
0, 0, 4, 3, ... 

Error in ==> pascal at 28 
model = pascal_train(cls, n, note); 

这是pascal_train文件

function model = pascal_train(cls, n, note) 

% model = pascal_train(cls, n, note) 
% Train a model with 2*n components using the PASCAL dataset. 
% note allows you to save a note with the trained model 
% example: note = 'testing FRHOG (FRobnicated HOG) 

% At every "checkpoint" in the training process we reset the 
% RNG's seed to a fixed value so that experimental results are 
% reproducible. 
initrand(); 

if nargin < 3 
    note = ''; 
end 

globals; 
[pos, neg] = pascal_data(cls, true, VOCyear); 
% split data by aspect ratio into n groups 
spos = split(cls, pos, n); 

cachesize = 24000; 
maxneg = 200; 

% train root filters using warped positives & random negatives 
try 
    load([cachedir cls '_lrsplit1']); 
catch 
    initrand(); 
    for i = 1:n 
    % split data into two groups: left vs. right facing instances 
    models{i} = initmodel(cls, spos{i}, note, 'N'); 
    inds = lrsplit(models{i}, spos{i}, i); 
    models{i} = train(cls, models{i}, spos{i}(inds), neg, i, 1, 1, 1, ... 
         cachesize, true, 0.7, false, ['lrsplit1_' num2str(i)]); 
    end 
    save([cachedir cls '_lrsplit1'], 'models'); 
end 

% train root left vs. right facing root filters using latent detections 
% and hard negatives 
try 
    load([cachedir cls '_lrsplit2']); 
catch 
    initrand(); 
    for i = 1:n 
    models{i} = lrmodel(models{i}); 
    models{i} = train(cls, models{i}, spos{i}, neg(1:maxneg), 0, 0, 4, 3, ... 
         cachesize, true, 0.7, false, ['lrsplit2_' num2str(i)]); 
    end 
    save([cachedir cls '_lrsplit2'], 'models'); 
end 

% merge models and train using latent detections & hard negatives 
try 
    load([cachedir cls '_mix']); 
catch 
    initrand(); 
    model = mergemodels(models); 
48: model = train(cls, model, pos, neg(1:maxneg), 0, 0, 1, 5, ... 
       cachesize, true, 0.7, false, 'mix'); 


save([cachedir cls '_mix'], 'model'); 
end 

% add parts and update models using latent detections & hard negatives. 
try 
    load([cachedir cls '_parts']); 
catch 
    initrand(); 
    for i = 1:2:2*n 
    model = model_addparts(model, model.start, i, i, 8, [6 6]); 
    end 
    model = train(cls, model, pos, neg(1:maxneg), 0, 0, 8, 10, ... 
       cachesize, true, 0.7, false, 'parts_1'); 
    model = train(cls, model, pos, neg, 0, 0, 1, 5, ... 
       cachesize, true, 0.7, true, 'parts_2'); 
    save([cachedir cls '_parts'], 'model'); 
end 

save([cachedir cls '_final'], 'model'); 

我强调的,在哪里发生行错误的代码行48

我敢肯定,该系统是在阅读正确和负面的图像训练正确。我不知道这个错误发生在哪里,因为matlab没有精确地指出哪个索引超出了矩阵的尺寸。

我试图尽可能地整理代码,指导我如果我在某处做错了。

任何建议,我应该开始看?

好吧,我试着用display来检查pascal_train中使用的变量; (i); disp(size(models)); disp(size(spos)); disp(length(neg)); disp(maxneg);

所以返回的结果是;

1 

1  1 

1  1 

10 
+0

我删除从你的问题Pascal的标签,因为它是在这里用它专指Pascal编程语言,而不是在matlab中使用Pascal_data。标签的定义将为您提供他们用于表示的意图。在这种情况下,这是误导性的,因为你的问题与Pascal语言无关。 :-) –

+0

好的!我的坏,谢谢!=) – user1968818

回答

0

我没有回答你的问题,但这里是一个建议,可以帮助您调试自己这个问题。

在Matlab菜单中,进入调试 - >停止,如果错误/警告...并选择“总是停止如果错误(dbstop如果错误)”。现在再次运行你的脚本,这次当你遇到错误时,matlab将停在发生错误的那一行,就像你在那里放置一个断点一样。此时,您可以使用整个工作空间,并且可以检查所有变量和矩阵大小,以查看哪个变量会给出您所看到的错误。

+0

嗯,我这样做,是的,我得到整个工作区,与变量...我检查了我的结构,并确保索引不会超出界..所以这是令人费解的,但后来我再次在新手matlab ..我很想张贴图像,但我需要10点=( – user1968818

+0

你可能已经做到了这一点,但如果你没有这样做,因为你的代码在'models {i} = train(cls,模型{i},spos {i},neg(1:maxneg),0,0,4,3,...,检查尺寸(模型),尺寸(spos)并确保它们大于或等于(neg)> = maxneg' –

+0

好吧,我编辑了文章的结果 – user1968818

1

只需更换:

models{i} = train(cls, models{i}, spos{i}, neg(1:maxneg), 

models{i} = train(cls, models{i}, spos{i}, neg(1:min(length(neg),maxneg)), 

还有其他地方几个类似的句子在这个脚本,你应该修改它们。

的原因是,你的训练样本集很小,所以你列出“负”短比maxneg(200)