how to use parallel computing with train faster rcnn detector.

2 views (last 30 days)
Hi,
I'm trying to use matlab to train my own data set using train faster rcnn function, but when I tried to enable the parallel computing by applying it in the options :
optionsStage1 = trainingOptions('sgdm', ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-5, ...
'ExecutionEnvironment','parallel',...
'CheckpointPath', 'D:\hope\checkpoint');
% Options for step 2.
optionsStage2 = trainingOptions('sgdm', ...
'MaxEpochs', 10, ...
'ExecutionEnvironment','parallel',...
'InitialLearnRate', 1e-5, ...
'CheckpointPath', 'D:\hope\checkpoint');
% Options for step 3.
optionsStage3 = trainingOptions('sgdm', ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-6, ...
'ExecutionEnvironment','parallel',...
'CheckpointPath', 'D:\hope\checkpoint');
% Options for step 4.
optionsStage4 = trainingOptions('sgdm', ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-6, ...
'ExecutionEnvironment','parallel',...
'CheckpointPath', 'D:\hope\checkpoint');
options = [
optionsStage1
optionsStage2
optionsStage3
optionsStage4
];
I'm getting this error message:
Error using vision.internal.cnn.parseInputsFasterRCNN>iCheckExecutionEnvironment
(line 433)
The value of 'options.ExecutionEnvironment' must be 'auto', 'cpu', or 'gpu'.
'multi-gpu' and 'parallel' are not supported.
could you please help me in this part as soon as possible.

Answers (2)

Walter Roberson
Walter Roberson on 29 Apr 2017
You do not happen to show which MATLAB release you are using, or which call you are making.
ExecutionEnvironment in general is new as of R2016b, and the seriesnetwork classify() and seriesnetwork predict() routine for that permits only auto, gpu, and gpu.
In R2017a, those two functions have the same limitation.
In R2017a, the trainNetwork() command can take a trainingOptions() object that can include multi-gpu and parallel. In R2016a, trainingOptions() did not permit ExecutionEnvironment.
  4 Comments
Ihsan Bani Melhem
Ihsan Bani Melhem on 30 Apr 2017
Edited: Walter Roberson on 30 Apr 2017
the is the full code
to train a dataset consists of 2000 images for training; where the training data were applied in a table with (path, and bounding boxes) and 800 for testing.
%load the data
data = load('D:\hope\images\a85.mat');
humanDataset =data.a85;
humanDataset(1:4,:);
% Read one of the images.
I = imread(humanDataset.imageFilename{10});
I = insertShape(I, 'Rectangle', humanDataset.obj{10});
I = imresize(I, 3);
figure
imshow(I)
%idx = floor(0.6 * height(humanDataset));
%trainingData = humanDataset(1:idx,:);
%testData = humanDataset(idx:end,:);
trainingData = humanDataset;
inputLayer = imageInputLayer([32 32 3]);
% Define the convolutional layer parameters.
filterSize = [3 3];
numFilters = 32;
% Create the middle layers.
middleLayers = [
convolution2dLayer(filterSize, numFilters, 'Padding', 1)
reluLayer()
convolution2dLayer(filterSize, numFilters, 'Padding', 1)
reluLayer()
maxPooling2dLayer(3, 'Stride',2)
];
finalLayers = [
% Add a fully connected layer with 64 output neurons. The output size
% of this layer will be an array with a length of 64.
fullyConnectedLayer(64)
% Add ReLU nonlinearity.
reluLayer
% Add the last fully connected layer. At this point, the network must
% produce outputs that can be used to measure whether the input image
% belongs to one of the object classes or to the background. This
% measurement is made using the subsequent loss layers.
fullyConnectedLayer(width(humanDataset))
% Add the softmax loss layer and classification layer.
softmaxLayer
classificationLayer
];
layers = [
inputLayer
middleLayers
finalLayers
]
% Options for step 1.
optionsStage1 = trainingOptions('sgdm', ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-5, ...
'ExecutionEnvironment','prallel',...
'CheckpointPath', 'D:\hope\checkpoint');
% Options for step 2.
optionsStage2 = trainingOptions('sgdm', ...
'MaxEpochs', 10, ...
'ExecutionEnvironment','prallel',...
'InitialLearnRate', 1e-5, ...
'CheckpointPath', 'D:\hope\checkpoint');
% Options for step 3.
optionsStage3 = trainingOptions('sgdm', ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-6, ...
'ExecutionEnvironment','prallel',...
'CheckpointPath', 'D:\hope\checkpoint');
% Options for step 4.
optionsStage4 = trainingOptions('sgdm', ...
'MaxEpochs', 10, ...
'InitialLearnRate', 1e-6, ...
'ExecutionEnvironment','prallel',...
'CheckpointPath', 'D:\hope\checkpoint');
options = [
optionsStage1
optionsStage2
optionsStage3
optionsStage4
];
doTrainingAndEval = true;
if doTrainingAndEval
% Set random seed to ensure example training reproducibility.
rng(0);
% Train Faster R-CNN detector. Select a BoxPyramidScale of 1.2 to allow
% for finer resolution for multiscale object detection.
detector = trainFasterRCNNObjectDetector(trainingData, layers, options,'UseParallel',...
'NegativeOverlapRange', [0 0.3], ...
'PositiveOverlapRange', [0.6 1], ...
'BoxPyramidScale', 1.2);
else
% Load pretrained detector for the example.
load('D:\hope\detector\detetor.mat');
end
if doTrainingAndEval
% Run detector on each image in the test set and collect results.
resultsStruct = struct([]);
for i = 1:height(testData)
% Read the image.
I = imread(testData.imageFilename{i});
% Run the detector.
[bboxes, scores, labels] = detect(detector, I);
% Collect the results.
resultsStruct(i).Boxes = bboxes;
resultsStruct(i).Scores = scores;
resultsStruct(i).Labels = labels;
end
% Convert the results into a table.
results = struct2table(resultsStruct);
else
results = data.results;
end
% Extract expected bounding box locations from test data.
expectedResults = testData(:, 2:end);
% Evaluate the object detector using average precision metric.
[ap, recall, precision] = evaluateDetectionPrecision(results, expectedResults);
% Plot precision/recall curve
figure
plot(recall, precision)
xlabel('Recall')
ylabel('Precision')
grid on
title(sprintf('Average Precision = %.1f', ap))
Joss Knight
Joss Knight on 2 May 2017
Edited: Joss Knight on 2 May 2017
The Error says that 'multi-gpu' and 'parallel' are not supported and yet you have tried to set your 'ExecutionEnvironment' to 'parallel'. But it isn't supported. So you can't use it.

Sign in to comment.


Joss Knight
Joss Knight on 2 May 2017
The Error says that 'multi-gpu' and 'parallel' are not supported and yet you have tried to set your 'ExecutionEnvironment' to 'parallel'. But it isn't supported. So you can't use it.
  4 Comments
Raphael Chazelle
Raphael Chazelle on 25 Sep 2017
Then why does it say the following in trainRCNNObjectDetector documentation "This function also supports parallel computing using multiple MATLAB® workers. Enable parallel computing using the Computer Vision System Toolbox Preferences dialog box. To open Computer Vision System Toolbox™ preferences, on the Home tab, in the Environment section, click Preferences. Select Computer Vision System Toolbox." if it doesn't??
And if that wasn't bad enough the documentation for trainFasterRCNNObjectDetector is even more confusing!
"For Faster R-CNN training, the use of a parallel pool of MATLAB workers is highly recommended to reduce training time. trainFasterRCNNObjectDetector automatically creates and uses a parallel pool based on your parallel preference settings. Ensure that the use of the parallel pool is enabled prior to training."
I'm trying to run you in parallel Matlab! But you won't let me!
Raphael Chazelle
Raphael Chazelle on 25 Sep 2017
Also could you please expand when you say "Unfortunately there wasn't time to add support for parallel to that feature." does that mean we WILL get this support in some future release? I looked at the release notes for r2017b and didn't see anything about it. Maybe r2018pre-release?? Here's to hoping! Otherwise gonna have to move away from matlab to T-flow.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!