gpt4 book ai didi

matlab - 索引超出训练模型时遇到的矩阵维度

转载 作者:行者123 更新时间:2023-11-30 09:13:32 25 4
gpt4 key购买 nike

我在使用 PASCAL 开发套件和 Felzenszwalb、D. McAllester、D. Ramaman 及其团队开发的判别训练可变形零件模型系统(在 Matlab 中实现)训练模型时遇到问题。

目前,当我尝试使用 10 个正图像和 10 个负图像训练“猫”的 1 分量模型时,出现此输出错误。

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 没有准确指示哪个索引超出了矩阵维度。

我已尝试尽可能地整理代码,如果我在某个地方做错了,请指导我。

有什么建议我应该从哪里开始考虑吗?

好的,我尝试使用显示来检查 pascal_train 使用的变量; 显示(i); disp(尺寸(型号)); 显示(大小(spos)); disp(长度(负)); disp(maxneg);

所以返回的结果是;

 1

1 1

1 1

10

200

最佳答案

只需替换:

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)),

这个脚本中其他地方还有几个类似的句子,你应该全部修改一下。

原因是您的训练样本集很小,因此您列出的“neg”比 maxneg(200)

关于matlab - 索引超出训练模型时遇到的矩阵维度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14493370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com