matlab2016 trainACFObjectDetector

原文链接:https://cn.mathworks.com/help/vision/ref/trainacfobjectdetector.html

trainACFObjectDetector

Train ACF object detector

Syntax

detector = trainACFObjectDetector(trainingData)
detector = trainACFObjectDetector(trainingData,Name,Value)

Description

detector = trainACFObjectDetector(trainingData) returns a trained aggregate channel features (ACF) object detector. The function uses positive instances of objects in images given in the trainingData table and automatically collects negative instances from the images during training. To create a ground truth table, use the Image Labeler app.

example

detector = trainACFObjectDetector(trainingData,Name,Value) returns a detector object with additional options specified by one or more Name,Value pair arguments.

Examples

collapse all

Train a Stop Sign Detector Using an ACF Object Detector

Use the trainACFObjectDetector with training images to create an ACF object detector that can detect stop signs. Test the detector with a separate image.

Load the training data.

load('stopSignsAndCars.mat')

Select the ground truth for stop signs. These ground truth is the set of known locations of stop signs in the images.

stopSigns = stopSignsAndCars(:,1:2);

Add the full path to the image files.

stopSigns.imageFilename = fullfile(toolboxdir('vision'),...
    'visiondata',stopSigns.imageFilename);

Train the ACF detector. You can turn off the training progress output by specifying 'Verbose',false as a Name,Value pair.

acfDetector = trainACFObjectDetector(stopSigns,'NumStages',3);
ACF Object Detector Training
The training will take 3 stages. The model size is 34x31.
Sample positive examples(~100% Completed)
Compute approximation coefficients...Completed.
Compute aggregated channel features...Completed.
--------------------------------------------
Stage 1:
Sample negative examples(~100% Completed)
Compute aggregated channel features...Completed.
Train classifier with 42 positive examples and 210 negative examples...Completed.
The trained classifier has 19 weak learners.
--------------------------------------------
Stage 2:
Sample negative examples(~100% Completed)
Found 210 new negative examples for training.
Compute aggregated channel features...Completed.
Train classifier with 42 positive examples and 210 negative examples...Completed.
The trained classifier has 38 weak learners.
--------------------------------------------
Stage 3:
Sample negative examples(~100% Completed)
Found 210 new negative examples for training.
Compute aggregated channel features...Completed.
Train classifier with 42 positive examples and 210 negative examples...Completed.
The trained classifier has 71 weak learners.
--------------------------------------------
ACF object detector training is completed. Elapsed time is 35.539 seconds.

Test the ACF detector on a test image.

img = imread('stopSignTest.jpg');

[bboxes,scores] = detect(acfDetector,img);

Display the detection results and insert the bounding boxes for objects into the image.

for i = 1:length(scores)
   annotation = sprintf('Confidence = %.1f',scores(i));
   img = insertObjectAnnotation(img,'rectangle',bboxes(i,:),annotation);
end

figure
imshow(img)

matlab2016 trainACFObjectDetector

Input Arguments

collapse all

trainingData — Labeled ground truth images
table

Labeled ground truth images, specified as a table with two or more columns. The first column must contain paths and file names to grayscale or truecolor (RGB) images. Although, ACF-based detectors work best with truecolor images. The remaining columns must contain bounding boxes related to the corresponding image. Each column represents a single object class, such as a car, dog, flower, or stop sign.

matlab2016 trainACFObjectDetector

Each bounding box must be in the format [x,y,width,height]. The format specifies the upper-left corner location and the size of the object in the corresponding image. The table variable name defines the object class name. To create the ground truth table, use the Image Labeler app.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'ObjectTrainingSize'[100 100]

collapse all

'ObjectTrainingSize' — Size of training images
'Auto' (default) | [height width] vector

Size of training images, specified as the comma-separated pair consisting of 'ObjectTrainingSize' and either 'Auto' or a [height width] vector. During the training process, all images are resized to this height and width during the training process. Increasing the size can improve detection accuracy, but also increases training and detection times.

When you specify 'Auto', the size is set based on the median width-to-height ratio of the positive instances.

Example: [100,100]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

'NumStages' — Number of training stages
4 (default) | positive integer

Number of training stages for the iterative training process, specified as the comma-separated pair consisting of 'NumStages' and a positive integer. Increasing this number can improve the detector and reduce training errors, at the expense of longer training time.

Data Types: double

'NegativeSamplesFactor' — Negative sample factor
5 (default) | real-valued scalar

Negative sample factor, specified as the comma-separated pair consisting of 'NegativeSamplesFactor' and a real-valued scalar. The number of negative samples to use at each stage is equal to

NegativeSamplesFactor × number of positive samples used at each stage

Data Types: double

'MaxWeakLearners' — Maximum number of weak learners
2048 (default) | positive integer scalar | vector of positive integers

Maximum number of weak learners for the last stage, specified as the comma-separated pair consisting of 'MaxWeakLearners' and a positive integer scalar or vector of positive integers. If the input is a scalar, MaxWeakLearners specifies the maximum number for the last stage. If the input is a vector, MaxWeakLearners specifies the maximum number for each of the stages and must have a length equal to 'NumStages'. These values typically increase throughout the stages. The ACF object detector uses the boosting algorithm to create an ensemble of weaker learners. You can use higher values to improve the detection accuracy, at the expense of reduced detection performance speeds. Recommended values range from 300 to 5000.

Data Types: double

'Verbose' — Display progress information
true (default) | false

Option to display progress information for the training process, specified as the comma-separated pair consisting of 'Verbose' and true or false.

Data Types: logical

Output Arguments

collapse all

detector — Trained ACF-based object detector
acfObjectDetector object

Trained ACF-based object detector, returned as an acfObjectDetector object.