How to increase the computation time of this code?

3 次查看(过去 30 天)
Hi, I am working on computing some features of an image data set and saving the features for later use. Below is the code:
tic
l = 9907 % size of image data set
% pre-allocating space for variables in the for loop
Icolor = cell(1,l);
Iwave = cell(1,l);
IglrlFeatures = cell(1,l);
for i = 1:l % l = size of image data set = 9907
IDB{1,i} = imread(strcat(path,strcat(num2str(i),'.jpg')));
Icolor{1,i} = colorMoments(IDB{1,i}); % 6-features in each cell
Iwave{1,i} = waveletTransform(IDB{1,i}); % 8-features in each cell
IglrlFeatures{1,i} = textureFeatures(IDB{1,i}); % 44-features in each cell
ICW{1,i} = [Icolor{1,i} Iwave{1,i} IglrlFeatures{1,i}];
end
toc
Here the computation time for each function on single image is:
colorMoments(single_image) = Elapsed time is 0.009689 seconds.
waveletTransform(single_image) = Elapsed time is 0.018069 seconds.
textureFeatures(single_image) = Elapsed time is 0.022902 seconds.
l = data set size = 9907 images
Computational times for different data set sizes (l):
l = 10; Elapsed time is 0.402629 seconds.
l = 100; Elapsed time is 2.233971 seconds.
l = 1000; Elapsed time is 21.178395 seconds.
l = 2000; Elapsed time is 44.510071 seconds.
l = 5000; Elapsed time is 111.393866 seconds.
l = 9907; Elapsed time is 238.924998 seconds. approximately (~4 mins)
I want to decrease this computational time, any suggestions?
Thanks, Gopi
  4 个评论
Gopichandh Danala
Here is the final code that is working:
Icolor = cell(1,l);
Iwave = cell(1,l);
idb = cell(1,l);
tic
parfor i = 1:l
idb{1,i} = imread(strcat(p_address,strcat(num2str(i),'.jpg')));
Icolor{1,i} = colorMoments(idb{1,i}); % 6-features in each cell
Iwave{1,i} = waveletTransform(idb{1,i}); % 8-features in each cell
% IglrlFeatures{1,i} = textureFeatures(IDB{1,i}); % 44-features in each cell
% ICW{1,i} = [Icolor{1,i} Iwave{1,i} IglrlFeatures{1,i}];
icw{1,i} = [Icolor{1,i} Iwave{1,i}];
end
toc
I don't see much difference between this and above code, but maybe my previous error was because of some global variables inside my GUI functions. I think they messed it up.
Performace improvement:
for loop: 92secs
parfor loop: 31secs
Really helpful, But one last question when we start a parallel pool in Matlab2016, it starts 4 workers running what does it mean and does this number reflect performance speed. like if workers are more does it mean faster or increased performance

请先登录,再进行评论。

回答(1 个)

Swaroop Mishra
Swaroop Mishra 2017-2-3
Number of workers by default is equal to the number of cores in your system. You can change it inside Home-Parallel-Manage Cluster Profiles tab of MATLAB Toolstrip.
If you increase the number of workers, based on how parallel your algorithm can work, the performance can vary. There might be a bottleneck on sequential part of the algorithm. You might not be able to improve it.
If you have 4 workers, it does not mean that you will get exactly 4x speed as the sequential code. It means that you will get better computation speed for part of the code that is parallelizable.

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by