Open topic with navigation

# TrainObject

Trains HPE Media Server to recognize an object in one action.

Running this action is equivalent to running the following actions in the following order:

- NewObject
- AddObjectImages
- SetObjectTrainingOption (optional)
- AddObjectMetadata (optional)
- BuildObject
- NullObjectImageData (optional)

This action is atomic, so that any interruption to the server does not leave the database in an inconsistent state. If you stop the action using the QueueInfo action, or the action returns an error, the database is not modified. If all of the training images fail, HPE Media Server does not add the object to the database.

Type: asynchronous

Parameter | Description | Required
--- | --- | ---
`database` | The name of the database to add the object to. The database must already exist. | Yes
`identifier` | A unique identifier for the object (maximum 254 bytes). If you do not set this parameter, HPE Media Server generates an identifier automatically. | No
`imagedata` | The training images to add. Files must be uploaded as multipart/form-data. For more information about sending data to HPE Media Server, refer to the HPE Media Server Administration Guide. | Set this or `imagepath`
`imagelabels` | A comma-separated list of labels to identify the images that you are adding (maximum 254 bytes for each label). Every image added to the same object must have a unique label, so the number of labels must match the number of images provided using either `imagedata` or `imagepath`. If you do not set this parameter, HPE Media Server generates labels automatically. | No
`imagepath` | A comma-separated list of paths to the training images to add. The paths must be absolute, or relative to the HPE Media Server executable file. | Set this or `imagedata`
`metadata` | A comma-separated list of metadata key-value pairs to add to the object. Separate keys from values using a colon (`:`). To include a comma or colon in a key name or value, you must enclose the key name or value in quotation marks (`"`) and escape any quotation marks that occur within the string with a backslash (`\`). | No
`nullimagedata` | A Boolean value, default `false`, that specifies whether to remove the images from the database after training is complete. Setting this to `true` is equivalent to running the action NullObjectImageData on the object. Be aware that if you remove the images, the training cannot be updated in future. | No
`numparallel` | The maximum number of threads that the action can use (default 1). | No
`trainingoptions` | A comma-separated list of training options to apply to the object. Separate training options from their values using a colon (`:`). For information about the training options that you can set, see SetObjectTrainingOption or refer to the HPE Media Server Administration Guide. | No

## Example

The following example trains HPE Media Server by sending the paths of the training images using the `imagepath` parameter:

    curl http://localhost:14000 -F action=TrainObject
                                -F database=logos
                                -F identifier=hp
                                -F imagepath=hp_logo.jpg
                                -F imagelabels=hp_logo
                                -F "metadata=companyname:HewlettPackard,\"another:value\":\"1,000\""
                                -F trainingoptions=useColor:true,3D:false

Alternatively, you can train HPE Media Server by sending the image data, for example:

    curl http://localhost:14000 -F action=TrainObject
                                -F database=logos
                                -F identifier=hp
                                -F imagedata=@hp_logo.jpg
                                -F imagelabels=hp_logo
                                -F "metadata=companyname:HewlettPackard,\"another:value\":\"1,000\""
                                -F trainingoptions=useColor:true,3D:false

## Response

This action is asynchronous, so HPE Media Server always returns success accompanied by a token:

    <autnresponse>
      <action>TRAINOBJECT</action>
      <response>SUCCESS</response>
      <responsedata>
        <token>MTAuMi4xMDQuNTQ6MTgwMDA6VFJBSU5GQUNFOjE0MjkyNzE0NjAwMDQ1Ni0xMzAyMzQ3MDI2</token>
      </responsedata>
    </autnresponse>

You can use this token with the QueueInfo action to retrieve the status of the action:

    <autnresponse>
      <action>QUEUEINFO</action>
      <response>SUCCESS</response>
      <responsedata>
        <actions>
          <action>
            <status>Finished</status>
            <queued_time>2015-Jun-04 09:53:21</queued_time>
            <time_in_queue>0</time_in_queue>
            <process_start_time>2015-Jun-04 09:53:21</process_start_time>
            <time_processing>0</time_processing>
            <process_end_time>2015-Jun-04 09:53:21</process_end_time>
            <build>
              <image>
                <index>1</index>
                <label>hp_logo</label>
                <status>trained</status>
              </image>
            </build>
            <database>logos</database>
            <identifier>hp</identifier>
            <numimages>1</numimages>
            <numtrained>1</numtrained>
            <token>MTAuMi4xMDQuNTQ6MTgwMDA6VFJBSU5GQUNFOjE0MjkyNzE0NjAwMDQ1Ni0xMzAyMzQ3MDI2</token>
          </action>
        </actions>
      </responsedata>
    </autnresponse>

© 2017 Hewlett Packard Enterprise Development LP | Send documentation feedback to HPE Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a web mail client, and send this email to AutonomyTPFeedback@hpe.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_HP_HTML5_bannerTitle.htm