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

1 visualización (últimos 30 días)
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 comentarios
Roy Kadesh
Roy Kadesh el 17 de Mzo. de 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 el 17 de Mzo. de 2021
Intel (R) Core(TM) i7 - 10510U CPU @ 1.80GHz 2.30GHz
RAM 12.0 GB
System type 64 bit
GPU free

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 17 de Mzo. de 2021
Editada: Jan el 17 de Mzo. de 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 comentarios
Jan
Jan el 18 de Mzo. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by