Error in "predict" in the "Gesture Recognition using Videos and Deep Learning" example

1 visualizzazione (ultimi 30 giorni)
I am trying to run the example of "Gesture Recognition using Videos and Deep Learning" in Matlab.
However, when the code reaches to the line below
dlYPred = predict(slowFastClassifier,dlVideo);
Matlab returns the error below:
Error using predict
No valid system or dataset was specified.
Does anyone have any sugesttion how to resolve the issue?
  4 Commenti
Walter Roberson
Walter Roberson il 17 Set 2022
The example worked for me on R2022a on MacOS Catalina. It took a bit of time to run.
SM il 19 Set 2022
Thanks for your resposne.
Have you used ".mlx" file to run it or you created a ".m" file and reproduced the example?
Becauase, when I used the live script (.mlx) it runs with no problem. However, when I copy the codes into a ".m" file, and try to reprocude the same, results, I face such error. I have checket the syntax, and functions to be correct.
I cannot figure out what mistake I made?
Here is the code that I try to run:
I downloaded the files and put then in the path, and all functions are in the code directory.
%%% Expample Link:
For this code the slowFastVideoClassifier add-on must be installed
%% Getting the classes
pretrainedDataFile =strcat(downloadFolder,'/slowFastPretrained_fourClasses.mat');
pretrained = load(pretrainedDataFile);
slowFastClassifier =;
classes = slowFastClassifier.Classes
doTraining = false;
groundTruthFolder = fullfile(downloadFolder,"groundTruthFolder");
if ~isfolder(groundTruthFolder)
groundTruthFolder = fullfile(downloadFolder,"groundTruthFolder");
trainingFolder = fullfile(downloadFolder,"videoScenes");
numFrames = 16;
frameSize = [112,112];
numChannels = 3;
isDataForTraining = true;
dsTrain = createFileDatastore(trainingFolder,numFrames,numChannels,classes,isDataForTraining);
baseNetwork = "resnet50-3d";
inputSize = [frameSize,numChannels,numFrames];
slowFast = slowFastVideoClassifier(baseNetwork,string(classes),InputSize=inputSize);
slowFast.ModelName = "Gesture Recognizer Using Deep Learning";
dsTrain = transform(dsTrain,@augmentVideo);
preprocessInfo.Statistics = slowFast.InputNormalizationStatistics;
preprocessInfo.InputSize = inputSize;
preprocessInfo.SizingOption = "resize";
dsTrain = transform(dsTrain,@(data)preprocessVideoClips(data,preprocessInfo));
params.Classes = classes;
params.MiniBatchSize = 5;
params.NumIterations = 600;
params.CosineNumIterations = [100 200 300];
params.SaveBestAfterIteration = 400;
params.MinLearningRate = 1e-4;
params.MaxLearningRate = 1e-3;
params.Momentum = 0.9;
params.Velocity = [];
params.L2Regularization = 0.0005;
params.ProgressPlot = false;
params.Verbose = true;
params.DispatchInBackground = true;
params.NumWorkers = 12;
%% Train Video Classifieor
params.ModelFilename = "slowFastPretrained_fourClasses.mat";
if doTraining
epoch = 1;
bestLoss = realmax;
accTrain = [];
lossTrain = [];
iteration = 1;
start = tic;
trainTime = start;
shuffled = shuffleTrainDs(dsTrain);
% Number of outputs is two: One for RGB frames, and one for ground truth labels.
numOutputs = 2;
mbq = createMiniBatchQueue(shuffled, numOutputs, params);
% Use the initializeTrainingProgressPlot and initializeVerboseOutput
% supporting functions, listed at the end of the example, to initialize
% the training progress plot and verbose output to display the training
% loss, training accuracy, and validation accuracy.
plotters = initializeTrainingProgressPlot(params);
while iteration <= params.NumIterations
% Iterate through the data set.
[dlX1,dlY] = next(mbq);
% Evaluate the model gradients and loss using dlfeval.
[gradients,loss,acc,state] = ...
% Accumulate the loss and accuracies.
lossTrain = [lossTrain, loss];
accTrain = [accTrain, acc];
% Update the network state.
slowFast.State = state;
% Update the gradients and parameters for the video classifier
% using the SGDM optimizer.
[slowFast,params.Velocity,learnRate] = ...
if ~hasdata(mbq) || iteration == params.NumIterations
% Current epoch is complete. Do validation and update progress.
trainTime = toc(trainTime);
accTrain = mean(accTrain);
lossTrain = mean(lossTrain);
% Update the training progress.
% Save the trained video classifier and the parameters, that gave
% the best training loss so far. Use the saveData supporting function,
% listed at the end of this example.
bestLoss = saveData(slowFast,bestLoss,iteration,lossTrain,params);
if ~hasdata(mbq) && iteration < params.NumIterations
% Current epoch is complete. Initialize the training loss, accuracy
% values, and minibatchqueue for the next epoch.
accTrain = [];
lossTrain = [];
epoch = epoch + 1;
trainTime = tic;
shuffled = shuffleTrainDs(dsTrain);
mbq = createMiniBatchQueue(shuffled, numOutputs, params);
iteration = iteration + 1;
% Display a message when training is complete.
disp("Model saved to: " + params.ModelFilename);
%% Evaluate the trained data
isDataForTraining = false;
dsEval = createFileDatastore(trainingFolder,numFrames,numChannels,classes,isDataForTraining);
dsEval = transform(dsEval,@(data)preprocessVideoClips(data,preprocessInfo));
if doTraining
transferLearned = load(params.ModelFilename);
slowFastClassifier =;
numOutputs = 2;
mbq = createMiniBatchQueue(dsEval,numOutputs,params);
numClasses = numel(params.Classes);
cmat = sparse(numClasses,numClasses);
while hasdata(mbq)
[dlVideo,dlY] = next(mbq);
% Computer the predictions of the trained SlowFast
% video classifier.
dlYPred = predict(slowFastClassifier,dlVideo);
dlYPred = squeezeIfNeeded(dlYPred,dlY);
% Aggregate the confusion matrix by using the maximum
% values of the prediction scores and the ground truth labels.
[~,YTest] = max(dlY,[],1);
[~,YPred] = max(dlYPred,[],1);
cmat = aggregateConfusionMetric(cmat,YTest,YPred);
evalClipAccuracy = sum(diag(cmat))./sum(cmat,"all")
chart = confusionchart(cmat,classes);

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 19 Set 2022
Your code has
slowFastClassifier =;
but the actual code (in both the posted example and the mlx file) is
slowFastClassifier =;
Because of that, you were trying to run predict() on a struct(), which was getting you a predict() function defined by the System Identification Toolbox instead of the predict() method appropriate for the slowFastVideoClassifier object.

Più risposte (0)




Community Treasure Hunt

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

Start Hunting!

Translated by