Error using tall/groupsummary, Grouping vaiable cannot be specified as a function handle. Action recognition with inflated 3D

3 Ansichten (letzte 30 Tage)
Hello!
I am working through Activity Recognition from Video and Optical Flow Data Using Deep Learning.
The code is all follows, sith support function at the end.
% Download the HMDB51 Data file Using a supporting function
downloadFolder = fullfile(tempdir, "hmdb51");
downloadHMDB51(downloadFolder);
% Check if the file is in the correct place
allClasses = checkForHMDB51Folder(downloadFolder);
% The data set contains approximately 2GB of video data. In order to reduce
% training, we can set useAllData to false or if you want to use all of the
% Data then set useAllData to true
useAllData = false;
if useAllData == true
classes = allClasses;
else
classes = ["kiss", "laugh", "pick", "pour", "pushup"];
end
dataFolder = fullfile(downloadFolder, "hmdb511_org");
% Now, the data has to be spilt into two different folders, one for
% training and one for validation. 80% of the data will
[labels,files] = folders2labels(fullfile(dataFolder,classes),...
"IncludeSubfolders",true,...
"FileExtensions",'.avi');
indices = splitlabels(labels,0.8,'randomized');
% train_array = indices{1};
% test_array = indices{2};
%
% trainFilenames = files(train_array);
% testFilenames = files(test_array);
trainFilenames = files(indices{1});
testFilenames = files(indices{2});
% Normailze the data
inputStatsFilename = 'inputStatistics.mat';
if ~exist(inputStatsFilename, 'file')
disp("Reading all the training data for input statistics...")
inputStats = inputStatistics(dataFolder);
else
d = load(inputStatsFilename);
inputStats = d.inputStats;
end
% Support functions
function inputStats = inputStatistics(dataFolder)
ds = createDatastore(dataFolder);
ds.ReadFcn = @getMinMax;
tic;
tt = tall(ds);
varnames = {'rgbMax','rgbMin','oflowMax','oflowMin'};
stats1 = groupsummary(tt,[], {'max','min'}, varnames); %ERROR OCCURS HERE (2)
stats = gather(stats1);
inputStats.Filename = gather(tt.Filename);
inputStats.NumFrames = gather(tt.NumFrames);
inputStats.rgbMax = stats.max_rgbMax;
inputStats.rgbMin = stats.min_rgbMin;
inputStats.oflowMax = stats.max_oflowMax;
inputStats.oflowMin = stats.min_oflowMin;
save('inputStatistics.mat','inputStats');
toc;
end
function data = getMinMax(filename)
reader = VideoReader(filename);
opticFlow = opticalFlowFarneback;
data = [];
while hasFrame(reader)
frame = readFrame(reader);
[rgb,oflow] = findMinMax(frame,opticFlow);
data = assignMinMax(data, rgb, oflow);
end
totalFrames = floor(reader.Duration * reader.FrameRate);
totalFrames = min(totalFrames, reader.NumFrames);
[labelName, filename] = getLabelFilename(filename);
data.Filename = fullfile(labelName, filename);
data.NumFrames = totalFrames;
data = struct2table(data,'AsArray',true);
end
function [labelName, filename] = getLabelFilename(filename)
fileNameSplit = split(filename,'/');
labelName = fileNameSplit{end-1};
filename = fileNameSplit{end};
end
function data = assignMinMax(data, rgb, oflow)
if isempty(data)
data.rgbMax = rgb.Max;
data.rgbMin = rgb.Min;
data.oflowMax = oflow.Max;
data.oflowMin = oflow.Min;
return;
end
data.rgbMax = max(data.rgbMax, rgb.Max);
data.rgbMin = min(data.rgbMin, rgb.Min);
data.oflowMax = max(data.oflowMax, oflow.Max);
data.oflowMin = min(data.oflowMin, oflow.Min);
end
function [rgbMinMax,oflowMinMax] = findMinMax(rgb, opticFlow)
rgbMinMax.Max = max(rgb,[],[1,2]);
rgbMinMax.Min = min(rgb,[],[1,2]);
gray = rgb2gray(rgb);
flow = estimateFlow(opticFlow,gray);
oflow = cat(3,flow.Vx,flow.Vy,flow.Magnitude);
oflowMinMax.Max = max(oflow,[],[1,2]);
oflowMinMax.Min = min(oflow,[],[1,2]);
end
function ds = createDatastore(folder)
ds = fileDatastore(folder,...
'IncludeSubfolders', true,...
'FileExtensions', '.avi',...
'UniformRead',false,...
'ReadFcn', @getMinMax, ... % ERROR OCCURS HERE, if the line above 'Uniformread' is chnmaged to true. (1)
'PreviewFcn',@getMinMax);
disp("NumFiles: " + numel(ds.Files));
end
There are more support functions, but i am not having any issues with them as they relate to downlaondg the files and making sure they are in place.
Error (1) (SHown in code up above)
Error (2) (Shown in code above)
The error that appears here is as follows: Error using tall/groupsummary
Grouping variable cannot be specified as a function handle.
I am not sure how to fix it. If anyone can please help i would greatly appreciate it.

Antworten (1)

Garmit Pant
Garmit Pant am 6 Nov. 2023
Hello Abraham
I understand that you are trying to implement Activity Recognition in Video by following the given MATLAB Example
As per my investigation, the errors encountered on using the functions ‘fileDataStore’ and ‘groupsummary’ can have the following reasons:
  1. The function ‘groupsummary’ only accepts tall matrices/tables for the first input argument. On passing an argument that is tall but not tabular, the ‘groupvars’ argument is recognized as a function handle and the function ‘groupsummarydoesn’t accept function handles for the argument ‘groupvars’.
  2. In function ‘fileDataStore’, when the value of ‘UniformRead’ is set as ‘false’, the function ‘tall’ returns a tall cell array. This can be triggering the error above since the output of following line is a tall cell array.
tt = tall(ds)
For further understanding, you can refer to the following MATLAB Documentation:
  1. https://www.mathworks.com/help/matlab/ref/matlab.io.datastore.filedatastore.html - Check the input arguments section.
  2. https://www.mathworks.com/help/matlab/ref/tall.tall.html - Documentation for function ‘tall’.
I hope this helps!
Best Regards
Garmit
  1 Kommentar
Abraham
Abraham am 6 Nov. 2023
Hello!
Thank you for getting back to me!
When i change "UniformRead" to true, I get the following Error
"Error using fileDatastore
Error using PreviewFcn @getMinMax for file: ".... "
Array indices must be positive integers or logical values. "

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by