Create and Train a Recognizer
To create and train an object class recognizer, follow these steps. For more information about the actions used in this section, refer to the Media Server Reference.
To create and train a recognizer
-
Start by creating a new recognizer. For example:
curl http://localhost:14000/action=CreateObjectClassRecognizer -F recognizer=vehicles
-
(Optional) Choose the type of recognizer that you want to train. For example:
curl http://localhost:14000/action=SetObjectClassRecognizerTrainingOption -F key=recognizer_type -F value=generation2
-
Add your chosen object classes to the recognizer.
The following example adds a new class named "car" to the "vehicles" recognizer.
curl http://localhost:14000/action=CreateObjectClass -F recognizer=vehicles -F identifier=car
-
Add images to the recognizer that contain example objects for training.
The following example adds two images to the "vehicles" recognizer, and labels them "car42" and "bike19":
curl http://localhost:14000/action=AddObjectClassImages -F recognizer=vehicles -F imagedata=@car42.jpg,bike19.jpg -F imagelabels=car42,bike19
-
Annotate each training image. An annotation identifies a region of a training image that contains an object, and the class that the object belongs to. Media Server can then use that region of the image to train the recognizer. You can add multiple annotations to the same image, if the image contains multiple objects.
The following example adds an annotation to the image "car42", associating a region covering the center 25% of the image with the "car" object class. The region is specified by the
Boxes
parameter, which is a comma-separated list of values in the form(left,top,width,height)
.Left
specifies the distance from the left side of the image to the left side of the region.Top
specifies the distance from the top of the image to the top of the region.Width
andHeight
specify the width and height of the region. The values are in pixels, unless you setRegionsAsPercentage=true
(in which case specifyLeft
andWidth
as a percentage of the image width andTop
andHeight
as a percentage of the image height).curl http://localhost:14000/action=AddObjectClassAnnotations -F recognizer=vehicles -F imagelabel=car42 -F identifiers=car -F boxes=(25,25,50,50) -F regionsaspercentage=true
TIP: To obtain a list of training images that have been added to the recognizer but have not been annotated, use the action
ListUnannotatedObjectClassImages
. -
Choose the number of training iterations to run.
curl http://localhost:14000/action=SetObjectClassRecognizerTrainingOption -F recognizer=vehicles -F key=iterations -F value=2000
-
(Optional) To set aside images to evaluate the performance of the recognizer and find the optimum number of training iterations, enable snapshots by setting the
snapshot_frequency
training option. If you want to change the proportion of images that are set aside, you can set thevalidation_proportion
training option.curl http://localhost:14000/action=SetObjectClassRecognizerTrainingOption -F recognizer=vehicles -F key=snapshot_frequency -F value=500
-
Train Media Server by building the recognizer. For example:
curl http://localhost:14000/action=BuildObjectClassRecognizer -F recognizer=vehicles
This action is asynchronous, so Media Server returns a token. You can use the
QueueInfo
action to check the status of the request.When the
BuildObjectClassRecognizer
action has finished, you can use the recognizer. If you did not enable snapshots, the training process is complete. -
If you enabled snapshots, test the performance of the recognizer and select the snapshot to use.
-
List the snapshots that are available.
curl http://localhost:14000/action=ListObjectClassRecognizers
The response to this action includes an index number for each snapshot.
-
Run the action
TestObjectClassRecognizerSnapshot
for each snapshot that you want to evaluate. The action is asynchronous, so Media Server returns a token. You can use theQueueInfo
action to check the status of your request(s).curl http://localhost:14000/action=TestObjectClassRecognizerSnapshot -F recognizer=vehicles -F snapshotindex=0
-
Review the results with the action
GetObjectClassRecognizerSnapshotStatistics
.curl http://localhost:14000/action=GetObjectClassRecognizerSnapshotStatistics -F recognizer=vehicles
-
If one of the snapshots provides acceptable performance, select the snapshot by running the action
SelectObjectClassRecognizerSnapshot
.curl http://localhost:14000/action=SelectObjectClassRecognizerSnapshot -F recognizer=vehicles -F snapshotindex=3
If none of the snapshots provides acceptable performance, you might need to add additional training data or run more training iterations.
-