1

我有代码段

display('Descriptor Extraction...');

DESCRIPTORS = {};
descriptor_for_each_class = {};
num_classes = length(imgs_dir);
IMAGES = {};
for i = 1:num_classes
    class_name = classes{i};
    fprintf('Feature Extraction for CLASS %s\n',class_name);
    full_path = fullfile(imgs_path,class_name);

    class_dir = dir(full_path);
    image_names = {class_dir(3:length(class_dir)).name};
    num_imgs = length(image_names);

    descriptors = {};
    parfor j = 1:num_imgs
        image_name = image_names{j};
        %fprintf('Feature Extraction for IMAGE %d/%d\n',j,num_imgs);
        img_path = fullfile(full_path,image_name);
        I = imread(img_path(:,:));
        I = standarizeImage(I);
        I = rgb2gray(I) ;
        IMAGES{i,j}.I = I;
        IMAGES{i,j}.class_name = class_name;
        IMAGES{i,j}.name = image_name;
        [f, d] = vl_dsift(I, 'size', binSize) ;
        descriptors{j}=d;
    end
    DESCRIPTORS = [DESCRIPTORS descriptors];
end

当 parfor 部分完成一个时期时,在第二个时期开始时,Matlab 给出以下错误:

Error using parallel_function (line 589)
Assertion failed.

Error in feat_extraction (line 34)
    parfor j = 1:num_imgs  

我找不到代码上的错误。有什么想法吗?

4

1 回答 1

2

我通过更改 parfor 部分来解决问题,如下所示

descriptors = {};
    images = {};
    parfor j = 1:num_imgs
        image_name = image_names{j};
        %fprintf('Feature Extraction for IMAGE %d/%d\n',j,num_imgs);
        img_path = fullfile(full_path,image_name);
        I = imread(img_path(:,:));
        images{j}.I = I;
        images{j}.class_name = class_name;
        images{j}.image_name = image_name;
        I = standarizeImage(I);
        I = rgb2gray(I) ;
        %IMAGES{i,j}.name = image_name;
        [f, d] = vl_dsift(I, 'size', binSize) ;
        descriptors{j}=d;
    end
    ALL_DATA{i}=images;
    DESCRIPTORS = [DESCRIPTORS descriptors];
end
于 2013-03-05T14:44:07.913 回答