Train an object detection model
Train SSD, Faster R-CNN, or R-FCN object detection models with EasyVision on single or multiple GPUs.
Supported models
EasyVision supports these object detection models:
Model |
| FPN support |
Faster R-CNN |
| Yes |
R-FCN |
| No |
SSD |
| With ResNet backbones only |
Supported model-backbone combinations
Model | Backbone | FPN support |
Faster R-CNN |
| Yes |
R-FCN |
| No |
SSD |
| Yes |
SSD |
| No |
SSD |
| No |
Prerequisites
PAI workspace with
easy_vision_extalgorithm accessOSS bucket for training data, checkpoints, and model output
RAM role with OSS access permissions. For ARN format, see I/O parameters in Parameters of PAI-TensorFlow tasks.
Training and test data in TFRecord format, uploaded to OSS
Single GPU training
This example trains an SSD model with resnet_v1_50 backbone on a single GPU.
pai -name easy_vision_ext
-Dbuckets='oss://{bucket_name}.{oss_host}/{path}'
-Darn='acs:ram::*********:role/aliyunodpspaidefaultrole'
-DgpuRequired=100
-Dcmd train
-Dparam_config '
--model_type SSD
--backbone resnet_v1_50
--num_classes 20
--model_dir oss://YOUR_BUCKET_NAME/test/ssd_fpn_resnet50
--train_data oss://pai-vision-data-sh/data/voc0712_tfrecord/voc0712_part_*.tfrecord
--test_data oss://pai-vision-data-sh/data/voc0712_tfrecord/VOC2007_test.tfrecord
--num_test_example 2
--train_batch_size 32
--test_batch_size 1
--image_sizes 300
--lr_type exponential_decay
--initial_learning_rate 0.001
--decay_epochs 20
--staircase true
'Key parameters:
Parameter | Value | Purpose |
|
| Allocates 1 GPU (100 = 1 GPU) |
|
| Single-stage detection model |
|
| Feature extraction network |
|
| PASCAL VOC dataset (20 classes) |
|
| Input image dimensions (SSD only) |
Multi-GPU training
Use -Dcluster to define parameter server and worker configuration for distributed training. When -Dcluster is specified, -DgpuRequired is ignored.
pai -name easy_vision_ext
-Dbuckets='oss://{bucket_name}.{oss_host}/{path}'
-Darn='acs:ram::*********:role/aliyunodpspaidefaultrole'
-Dcmd train
-Dcluster='{
"ps": {
"count" : 1,
"cpu" : 600
},
"worker" : {
"count" : 3,
"cpu" : 800,
"gpu" : 100
}
}'
-Dparam_config '
--model_type SSD
--backbone resnet_v1_50
--num_classes 20
--model_dir oss://YOUR_BUCKET_NAME/test/ssd_fpn_resnet50
--train_data oss://pai-vision-data-sh/data/voc0712_tfrecord/voc0712_part_*.tfrecord
--test_data oss://pai-vision-data-sh/data/voc0712_tfrecord/VOC2007_test.tfrecord
--num_test_example 2
--train_batch_size 32
--test_batch_size 1
--image_sizes 300
--lr_type exponential_decay
--initial_learning_rate 0.001
--decay_epochs 20
--staircase true
'Cluster configuration:
Node type | Field | Value | Description |
Parameter server ( |
|
| Parameter servers |
Parameter server ( |
|
| CPU allocation (600 = 6 cores) |
Worker ( |
|
| Workers for parallel training |
Worker ( |
|
| CPU allocation per worker (800 = 8 cores) |
Worker ( |
|
| GPU allocation per worker (100 = 1 GPU) |
PAI command parameters
Control job configuration with these top-level parameters.
Parameter | Required | Description | Format or example | Default |
| Yes | OSS path for data access |
| N/A |
| Yes | ARN of the RAM role with OSS access permissions. See I/O parameters in Parameters of PAI-TensorFlow tasks. |
| N/A |
| No | Distributed training configuration as JSON. Defines parameter servers and workers with CPU and GPU allocations. | JSON string |
|
| No | GPUs per worker in standalone mode. Each unit of 100 represents one GPU. Set to |
|
|
| Yes | EasyVision task type. Set to |
| N/A |
| Yes | Model training configuration. Uses Python | String | N/A |
Training parameters
param_config accepts training configuration in Python ArgumentParser format:
-Dparam_config = '
--backbone resnet_v1_50
--num_classes 200
--model_dir oss://your/bucket/exp_dir
'String values in param_config must not use quotation marks.
Model parameters
Parameter | Required | Description | Default |
| Yes | Detection model architecture: | N/A |
| Yes | Backbone network for feature extraction: | N/A |
| No | Enables FPN for multi-scale feature extraction. Supported by Faster R-CNN (with ResNet backbones) and SSD (with |
|
| No | Object classes excluding background. PASCAL VOC has 20 classes |
|
| No | L2 regularization coefficient |
|
Anchor parameters
Parameter | Required | Description | Default |
| No | Anchor box sizes in pixels relative to resized input. Behavior varies by model | Varies by model (see below) |
| No | Width-to-height ratios of anchor boxes |
|
anchor_scales behavior by model:
Configuration | Behavior | Default |
SSD | Automatically determined. Do not set | 0.1, 0.2, 0.37, 0.54, 0.71, 0.88, 0.96, or 1.0 times the input image size |
Faster R-CNN with FPN | Set a single base scale for the highest-resolution feature layer. FPN uses five layers, each doubling anchor size. For example, |
|
Faster R-CNN / R-FCN without FPN | Specifies multiple anchor scales directly (such as |
|
Image size parameters
Parameter | Required | Applies to | Description | Default |
| No | SSD only | Height and width to resize input images to |
|
| No | Faster R-CNN, R-FCN | Target shorter side length after resizing. For multi-scale training, specify multiple values. The last value is used for evaluation; others are randomly selected per training iteration |
|
| No | Faster R-CNN, R-FCN | Target longer side length after resizing. For multiple values, the last one is used for evaluation and others for training |
|
Training hyperparameters
Parameter | Required | Description | Default |
| No | Optimization algorithm: |
|
| Yes | Training epochs. One epoch processes the full training dataset once | N/A |
| No | Learning rate schedule: |
|
| No | Initial learning rate |
|
| No | Epoch interval for learning rate adjustment. Behavior depends on |
|
| No | Decay multiplier for learning rate. Equivalent to the |
|
| No | Applies step-wise (staircase) decay instead of continuous decay. Equivalent to the |
|
| No | Exponent for polynomial decay. Equivalent to the |
|
| No | Learning rates for each epoch in | N/A |
| No | Enables learning rate warmup |
|
| No | Epochs over which to linearly warm up learning rate |
|
| Yes | Images per training batch | N/A |
| Yes | Images per evaluation batch | N/A |
Data parameters
Parameter | Required | Description | Default |
| Yes | OSS path to training data in TFRecord format. Supports wildcards such as | N/A |
| Yes | OSS path to evaluation data in TFRecord format | N/A |
| No | Concurrent threads for reading training data |
|
| No | Examples to evaluate during training. Set to |
|
| No | Total training images. Required for custom TFRecord files |
|
| No | Label map file path mapping class IDs to names. Required for custom TFRecord files |
|
Checkpoint and logging parameters
Parameter | Required | Description | Default |
| Yes | OSS path for model checkpoints and training artifacts | N/A |
| No | OSS path to pretrained checkpoint for fine-tuning. Example: |
|
| No | Initialize from pretrained checkpoint |
|
| No | Checkpoint save frequency in epochs. |
|
| No | TensorFlow summary save frequency as fraction of epoch. |
|
| No | Evaluation examples to visualize |
|
Learning rate schedules
lr_type controls learning rate changes during training.
Schedule | Description | Key parameters |
| Decays learning rate by |
|
| Decays learning rate following polynomial curve. |
|
| Adjusts learning rate at specific epochs. Set |
|
| Adjusts learning rate following the cosine curve described in SGDR: Stochastic Gradient Descent with Warm Restarts |
|
Next steps
For detailed PAI-TensorFlow task parameters, see Parameters of PAI-TensorFlow tasks.