pixelLabelDatastore read() function gets progressively slower

1 回表示 (過去 30 日間)
Louis Vaickus
Louis Vaickus 2018 年 5 月 1 日
回答済み: Louis Vaickus 2018 年 5 月 4 日
The following code proceeds quickly (200 images/sec) until around the 12,000th read at which point the read time increases by roughly 10% per 200 reads flattening out at about 20 images/sec.
There are 1.4x10^6 images in the directory.
At the initial rate of 200/sec execution would take 2 hours to complete.
At the rate read settles to it would take 20 hours.
pxds = pixelLabelDatastore('directory', classes, LabelIDs);
parfor r = 1:length(pxds.Files);
img_holder{r} = uint8(ones(200,200));
end
counter = 1;
while hasdata(pxds);
img_holder{counter} = uint8(read(pxds));
counter = counter + 1;
end

採用された回答

Louis Vaickus
Louis Vaickus 2018 年 5 月 4 日
I ended up making an imagedatastore of the labelled images and then creating the categorical images and imwrite()'ing them in a parfor loop. It progressed at 500 images per second and did not slow down.
function y = convert_categorical(imds);
parfor r = 1:length(imds.Files);
[img, info] = imds.readimage(r);
[~, filename, ext] = fileparts(info.Filename);
if exist([path filename ext], 'file') == 0;
q = uint8(ones(227,227));
q(img(:,:,1) == 0 & img(:,:,2) == 0 & img(:,:,3) == 255) = 1;
q(img(:,:,1) == 255 & img(:,:,2) == 255 & img(:,:,3) == 255) = 2;
q(img(:,:,1) == 0 & img(:,:,2) == 255 & img(:,:,3) == 0) = 3;
imwrite(q,[path filename ext]);
end
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by