% 图片描述符计算,开启的线程数
core = 6;
p = parpool(core);
% 并行计算的图片数
sum_batch = numel(imginds);
n_batch = sum_batch/2000;
% 第几个批次的图片
N = 1;
end_batch = 2000 * N;
start_batch = 2000 *(N-1)+1;
% 原文计算方法
parfor i=start_batch:end_batch
% totaldesctime、desccount、errorimages
% 上面三个变量在parfor运行中出现问题
%显示生成图像的描述符的进度
imgind = imginds(i);
disp(['Image ',num2str(i),' / ',num2str(numel(imginds))]);
imgfilename = rels.imgfilenames{imgind};
% get all relevant relationships in the current image
if not(isempty(inputrels))
disp('inputrels is not empty!');
% query given relationships
imgrels{i} = DatabaseRelationshipSet;
imgrels{i}.append(inputrels,inputrels.imgrelinds{i});
imgrels{i}.lockimgfilenames = true;
% filter by source and target labels
validmask = true(1,numel(imgrels{i}.id));
if not(isempty(sourcelbl)) || not(isempty(targetlbl))
if not(isempty(sourcelbl))
relind = cellind_mex(imgrels{i}.sourcelabels);
relind = [relind{:}];
imgsrclbls = [imgrels{i}.sourcelabels{:}];
validsrclbl = ismember(imgsrclbls,sourcelbl);
validsrclbl = array2cell_mex(double(validsrclbl),relind,numel(imgrels{i}.sourcelabels));
validsrclbl = cellfun(@(x) not(isempty(x)) && all(x),validsrclbl);
else
validsrclbl = true(1,numel(imgrels{i}.sourcelabels));
end
if not(isempty(targetlbl))
relind = cellind_mex(imgrels{i}.targetlabels);
relind = [relind{:}];
imgtgtlb
Matlab Parfor实测,成功运行
最新推荐文章于 2024-07-22 20:50:21 发布