Out of Memory, The size of the indicated variable or array appears to be changing with each loop iteration. Undefined function or variable 'Feat1'.

3 vues (au cours des 30 derniers jours)
clear all
clc
Feat1=[];
Feat2=[];
PF = 'D:\Project\DB1\train\' % Parent Folder
SFL = dir(PF) % List the sub folders
[mp, np] = size(SFL); % compute size = number of subfolders & files & . & ..
csf=0; % counter of JUST subfolders found in PF
for i=3:mp
%% keep only folders:
k = strfind(SFL(i).name,'.');
if isempty(strfind(SFL(i).name,'.'))
csf = csf +1; % one sub folder found
SFN = SFL(i).name ;% extract his name
tifList = ls(sprintf('%s%s%s%s',PF,SFN,'\','*.tif')); % list all jpg files
[ms, ns] = size(tifList); % ms = number of image files found
%% Processing for each tif file:
for j=1:ms
featureVector=[];
Feat=[];
tifFileName = tifList(j,:); % extract name of tif file
%for currentImage1 = 1:ms
IM=imread([PF SFN '\' tifFileName]);
%hold on;
I = imresize(IM,[200,50]);
featureVector = hog_feature_vector(I);
Feat = featureVector';
Feat1 = [Feat1 Feat];
end
PF_SFN_imgName = sprintf('%s%s%s',PF,SFN,'\',tifFileName)
%imshow(PF_SFN_imgName)
%pause(1)
end
end
save('featurs_T','Feat1');
PF = 'D:\Project\DB\test\'; % Parent Folder
SFL = dir(PF) ;% List the sub folders
[mp1, np] = size(SFL); % compute size = number of subfolders & files & . & ..
csf1=0; % counter of JUST subfolders found in PF
for i=3:mp1
%% keep only folders:
k = strfind(SFL(i).name,'.');
if isempty(strfind(SFL(i).name,'.'))
csf1 = csf1 +1; % one sub folder found
SFN = SFL(i).name ;% extract his name
tifList = ls(sprintf('%s%s%s%s',PF,SFN,'\','*.tif')); % list all jpg files
[ms1, ns] = size(tifList); % ms = number of image files found
%% Processing for each tif file:
for s=1:ms1
featureVector1=[]
FeatTest=[]
tifFileName = tifList(s,:) % extract name of tif file
%for currentImage1 = 1:ms
IMT =imread([PF SFN '\' tifFileName])
IT = imresize(IMT,[200,50]);
featureVector1 = hog_feature_vector(IT);
FeatTest = featureVector1';
Feat2 = [Feat2 FeatTest];
%hold on;
end
PF_SFN_imgName = sprintf('%s%s%s',PF,SFN,'\',tifFileName)
%
%imshow(PF_SFN_imgName)
%pause(1)
end
end
save('featurs_S','Feat2');
%----------------------
  2 commentaires
Roy Kadesh
Roy Kadesh le 17 Mar 2021
How do you prevent this from growing out of control (and taking a lot of time due to dynamic expansion)?
Feat1 = [Feat1 Feat];
sun rise
sun rise le 17 Mar 2021
Intel (R) Core(TM) i7 - 10510U CPU @ 1.80GHz 2.30GHz
RAM 12.0 GB
System type 64 bit
GPU free

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 17 Mar 2021
Modifié(e) : Jan le 17 Mar 2021
You cannot get multiple errors, because Matlab stops at the first error already. So please post a full copy of the complete message. Then the readers do not have to guess, what the problem is.
A simplification of your code:
Folder = 'D:\Project\DB1\train\';
FileList = dir(fullfile(Folder, '**', '*.tif'));
Feature = cell(1, numel(FileList)); % Pre-allocation
for iFile = 1:numel(FileList)
File = fullfile(FileList(iFile).folder, FileList(iFile).name);
Img = imread(File);
Img = imresize(Img, [200, 50]);
Feature{iFile} = hog_feature_vector(Img).'; % [EDITED] Transpose added
end
% Maybe:
Feat1 = cat(1, Feature{:}); % Or cat(2, ...) ?!
save('featurs_T.mat', 'Feat1');
Parsing the output of LS is far too complicated. There is no guarantee, that "." and ".." are the 1st two outputs of the DIR command.
  7 commentaires
sun rise
sun rise le 18 Mar 2021
IFN/ENT dataset, 26459 files
featurs vectors are 19404
Jan
Jan le 18 Mar 2021
Then Feat2 needs 4.11 GB of RAM. This must be available in a contiguous block.
Storing such a huge data set in one block is not useful. What about storing the data in a binary file?
FID = fopen(FileName, 'w');
if FID == -1, error('Cannot open file for writing: %s', FileName); end
for k = 1:numel(Feature2)
fwrite(FID, Feature2{k}, 'double');
end
fclose(FID)
Maybe it is a good idea to store some data on the top of the file, e.g. the dimensions of the array.
But if you want to load the data, you still need 4.11GB of free RAM.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Downloads dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by