diff --git a/evaluate_classification.m b/evaluate_classification.m index 3a28b4a..f6ab01a 100644 --- a/evaluate_classification.m +++ b/evaluate_classification.m @@ -141,8 +141,8 @@ function evaluate_classification(feat, varargin) [nDescPerShape*nTestShapes 1]); end end -trainFeat = sparse(trainFeat); -testFeat = sparse(testFeat); +trainFeat = sparse(double(trainFeat)); +testFeat = sparse(double(testFeat)); % ------------------------------------------------------------------------- diff --git a/imdb_compute_cnn_features.m b/imdb_compute_cnn_features.m index 0091c17..b5e657c 100644 --- a/imdb_compute_cnn_features.m +++ b/imdb_compute_cnn_features.m @@ -206,6 +206,7 @@ end poolSize = poolObj.NumWorkers; end +parfor_progress(nImgs); parfor (i=1:nImgs, poolSize) % for i=1:nImgs, % if no parallel computing toolbox if exist(fullfile(cacheDir, [num2str(i) '.mat']),'file'), @@ -225,8 +226,10 @@ 'gpuMode', opts.gpuMode); parsave(fullfile(cacheDir, [num2str(i) '.mat']),feat); - fprintf(' %s\n',fullfile(imdb.imageDir,imdb.images.name{(i-1)*nViews+1})); + % fprintf(' %s\n',fullfile(imdb.imageDir,imdb.images.name{(i-1)*nViews+1})); + parfor_progress(); end +parfor_progress(0); % ------------------------------------------------------------------------- % Construct feature descriptors and encoders diff --git a/utils/parfor_progress.m b/utils/parfor_progress.m new file mode 100644 index 0000000..c98fb53 --- /dev/null +++ b/utils/parfor_progress.m @@ -0,0 +1,110 @@ +function percent = parfor_progress(N) +%PARFOR_PROGRESS Progress monitor (progress bar) that works with parfor. +% PARFOR_PROGRESS works by creating a file called parfor_progress.txt in +% your working directory, and then keeping track of the parfor loop's +% progress within that file. This workaround is necessary because parfor +% workers cannot communicate with one another so there is no simple way +% to know which iterations have finished and which haven't. +% +% PARFOR_PROGRESS(N) initializes the progress monitor for a set of N +% upcoming calculations. +% +% PARFOR_PROGRESS updates the progress inside your parfor loop and +% displays an updated progress bar. +% +% PARFOR_PROGRESS(0) deletes parfor_progress.txt and finalizes progress +% bar. +% +% To suppress output from any of these functions, just ask for a return +% variable from the function calls, like PERCENT = PARFOR_PROGRESS which +% returns the percentage of completion. +% +% Example: +% +% N = 100; +% parfor_progress(N); +% parfor i=1:N +% pause(rand); % Replace with real code +% parfor_progress; +% end +% parfor_progress(0); +% +% See also PARFOR. +% +%Copyright (c) 2011, Jeremy Scheff +%All rights reserved. +% +%Redistribution and use in source and binary forms, with or without +%modification, are permitted provided that the following conditions are +%met: +% +% * Redistributions of source code must retain the above copyright +% notice, this list of conditions and the following disclaimer. +% * Redistributions in binary form must reproduce the above copyright +% notice, this list of conditions and the following disclaimer in +% the documentation and/or other materials provided with the distribution +% +%THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +%LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%POSSIBILITY OF SUCH DAMAGE. + +% By Jeremy Scheff - jdscheff@gmail.com - http://www.jeremyscheff.com/ + +error(nargchk(0, 1, nargin, 'struct')); + +if nargin < 1 + N = -1; +end + +percent = 0; +w = 68; % Width of progress bar + +if N > 0 + f = fopen('parfor_progress.txt', 'w'); + if f<0 + error('Do you have write permissions for %s?', pwd); + end + fprintf(f, '%d\n', N); % Save N at the top of progress.txt + fclose(f); + + if nargout == 0 + disp([' 0%[>', repmat(' ', 1, w), ']']); +% fprintf([' 0%%[>', repmat(' ', 1, w), ']']); + end +elseif N == 0 + delete('parfor_progress.txt'); + percent = 100; + + if nargout == 0 + disp([repmat(char(8), 1, (w+9)), char(10), '100%[', repmat('=', 1, w+1), ']']); +% fprintf([repmat('\b', 1, (w+7)), '100%%[', repmat('=', 1, w+1), ']\n']); + end +else + if ~exist('parfor_progress.txt', 'file') + error('parfor_progress.txt not found. Run PARFOR_PROGRESS(N) before PARFOR_PROGRESS to initialize parfor_progress.txt.'); + end + + f = fopen('parfor_progress.txt', 'a'); + fprintf(f, '1\n'); + fclose(f); + + f = fopen('parfor_progress.txt', 'r'); + progress = fscanf(f, '%d'); + fclose(f); + percent = (length(progress)-1)/progress(1)*100; + + if nargout == 0 + perc = sprintf('%3.0f%%', percent); % 4 characters wide, percentage + disp([repmat(char(8), 1, (w+9)), char(10), perc, '[', repmat('=', 1, round(percent*w/100)), '>', repmat(' ', 1, w - round(percent*w/100)), ']']); +% perc = sprintf('%3.0f%%%%', percent); % 4 characters wide, percentage +% fprintf([repmat('\b', 1, (w+7)), perc, '[', repmat('=', 1, round(percent*w/100)), '>', repmat(' ', 1, w - round(percent*w/100)), ']']); + end +end