Error when running 'Train a Deep Learning Vehicle Detector' program

조회 수: 2 (최근 30일)
Anonymous
Anonymous 2022년 4월 23일
댓글: Jan 2022년 5월 17일
I am trying to run this program with the code supplied here: https://uk.mathworks.com/help/driving/ug/train-a-deep-learning-vehicle-detector.html
I keep getting the following errors:
Invalid transform function defined on datastore.
The cause of the error was:
Undefined function 'preprocessData' for input arguments of type 'cell'.
Error in vehicleDetectionModel>@(data)preprocessData(data,inputSize) (line 60)
preprocessedTrainingData = transform(trainingData, @(data)preprocessData(data,inputSize));
Error in matlab.io.datastore.TransformedDatastore/applyTransforms (line 610)
data = ds.Transforms{ii}(data);
Error in matlab.io.datastore.TransformedDatastore/read (line 222)
[data, info] = ds.applyTransforms(data, info);
Error in matlab.io.Datastore/readall (line 263)
data = read(copyds);
Error in matlab.io.datastore.TransformedDatastore/readall (line 281)
data = readall@matlab.io.Datastore(copyds, varargin{:});
Error in estimateAnchorBoxes>iReadallBoxes (line 270)
boxes = readall(ds);
Error in estimateAnchorBoxes>iCheckBoxesFromDatastore (line 215)
boxes = iReadallBoxes(ds);
Error in estimateAnchorBoxes>iParseInputs (line 168)
boxes = iCheckBoxesFromDatastore(datastore);
Error in estimateAnchorBoxes (line 136)
[boxes, numAnchors, params] = iParseInputs(datastore, numAnchors, varargin{:});
Error in vehicleDetectionModel (line 62)
anchorBoxes = estimateAnchorBoxes(preprocessedTrainingData,numAnchors)
I simply want to run the program and have the Average Precision graph display, like the following without any errors showing:
Am I missing code? Or have I structured my code in the wrong order?
The code I am using:
% clear the workspace
clc; clear;
% load the pretrained detector
doTrainingAndEval = false;
if ~doTrainingAndEval && ~exist('fasterRCNNResNet50EndToEndVehicleExample.mat','file')
disp('Downloading the pretrained detector (118 MB)... please wait');
pretrainedURL = 'https://www.mathworks.com/supportfiles/vision/data/fasterRCNNResNet50EndToEndVehicleExample.mat';
websave('fasterRCNNResNet50EndToEndVehicleExample.mat',pretrainedURL);
end
% load the dataset
unzip vehicleDatasetImages.zip
data = load('vehicleDatasetGroundTruth.mat');
vehicleDataset = data.vehicleDataset;
% split the dataset into training and test sets
rng(0)
shuffledIdx = randperm(height(vehicleDataset));
idx = floor(0.7 * height(vehicleDataset));
trainingDataTbl = vehicleDataset(shuffledIdx(1:idx),:);
testDataTbl = vehicleDataset(shuffledIdx(idx+1:end),:);
% create the datastores for both image and label data
imdsTrain = imageDatastore(trainingDataTbl{:,'imageFilename'});
bldsTrain = boxLabelDatastore(trainingDataTbl(:,'vehicle'));
imdsTest = imageDatastore(testDataTbl{:,'imageFilename'});
bldsTest = boxLabelDatastore(testDataTbl(:,'vehicle'));
% training and test data is combined
trainingData = combine(imdsTrain,bldsTrain);
testData = combine(imdsTest,bldsTest);
% image and corresponding box is displayed
data = read(trainingData);
I = data{1};
bbox = data{2};
annotatedImage = insertShape(I,'Rectangle',bbox);
annotatedImage = imresize(annotatedImage,2);
figure
imshow(annotatedImage)
testData = transform(testData,@(data)preprocessData(data,inputSize));
if doTrainingAndEval
detectionResults = detect(detector,testData,'MinibatchSize',4);
else
% Load pretrained detector for the example.
pretrained = load('fasterRCNNResNet50EndToEndVehicleExample.mat');
detectionResults = pretrained.detectionResults;
end
% Create a faster R-CNN network
% specifiying the input size
inputSize = [224 224 3];
% implement the anchor boxes
preprocessedTrainingData = transform(trainingData, @(data)preprocessData(data,inputSize));
numAnchors = 4;
anchorBoxes = estimateAnchorBoxes(preprocessedTrainingData,numAnchors)
% load a pretrained ResNet-50 model
featureExtractionNetwork = resnet50;
% output the feature maps
featureLayer = 'activation_40_relu';
% define the number of classes to detect
numClasses = width(vehicleDataset)-1;
% create the Faster R-CNN objection detection network
lgraph = fasterRCNNLayers(inputSize,numClasses,anchorBoxes,featureExtractionNetwork,featureLayer);
% preprocess the augmented data for training
trainingData = transform(augmentedTrainingData,@(data)preprocessData(data,inputSize));
% read the data
data = read(trainingData);
% display the data and bounding boxes
I = data{1};
bbox = data{2};
annotatedImage = insertShape(I,'Rectangle',bbox);
annotatedImage = imresize(annotatedImage,2);
figure
imshow(annotatedImage)
% apply preprocessing to the test data
testData = transform(testData,@(data)preprocessData(data,inputSize));
% run the detector on all test images
if doTrainingAndEval
detectionResults = detect(detector,testData,'MinibatchSize',4);
else
% Load pretrained detector for the example.
pretrained = load('fasterRCNNResNet50EndToEndVehicleExample.mat');
detectionResults = pretrained.detectionResults;
end
% Evaluate the object detector using the average precision metric
[ap, recall, precision] = evaluateDetectionPrecision(detectionResults,testData);
% plot the results on a graph
figure
plot(recall,precision)
xlabel('Recall')
ylabel('Precision')
grid on
title(sprintf('Average Precision = %.2f', ap))
I would appreciate if someone could find a solution for how to run this.
  댓글 수: 3
Rik
Rik 2022년 5월 16일
You can easilly change your username in your profile. I have stored a local copy of this page, so any attempt to edit the content itself will be reverted.
Jan
Jan 2022년 5월 17일
@Anonymous: Even if this question is removed, Google and other web archives will still find it in the caches. So deleting will not solve the problem.
Did you read the terms of use before you have used this forum?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2022년 4월 23일
  댓글 수: 1
Anonymous
Anonymous 2022년 4월 23일
Thank you for your reply, I have included the supporting functions and the program is working fine. Thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by