Train a model for semantic image segmentation
Train a DeepLabV3 semantic segmentation model with EasyVision using TFRecord datasets stored in OSS.
Prerequisites
A MaxCompute project
An Object Storage Service (OSS) bucket with training data uploaded in TFRecord format
A RAM role with OSS access permissions. For more information, see Grant permissions to use Machine Learning Designer.
Procedure
DeepLabV3 is a semantic image segmentation model. For more information, see Encoder-Decoder with Atrous Separable Convolution for Semantic Image Segmentation.
Run PAI commands through the SQL Script component, MaxCompute client, or DataWorks SQL nodes. For more information, see MaxCompute client (odpscmd) or Develop a MaxCompute SQL node.
The following example trains a semantic image segmentation model on a single GPU.
pai -name easy_vision_ext
-Dbuckets='oss://{bucket_name}.{oss_host}/{path}'
-Darn='acs:ram::*********:role/aliyunodpspaidefaultrole'
-DossHost='{oss_host}'
-DgpuRequired=100
-Dcmd train
-Dparam_config '--model_type DeeplabV3 --backbone resnet_v1_50 --backbone_feature_stride 16 --bn_trainable true --num_classes 21 --num_epochs 1 --model_dir oss://YOUR_BUCKET_NAME/test/test_deeplabv3 --train_data oss://YOUR_BUCKET_NAME/data/test/pascal_voc_seg_aug/voc_ev_train.tfrecord --test_data oss://YOUR_BUCKET_NAME/data/test/pascal_voc_seg_aug/voc_ev_train.tfrecord --num_test_example 2 --train_batch_size 6 --test_batch_size 1 --image_crop_size 513 --lr_type polynomial_decay --initial_learning_rate 0.007 --power 0.9'Parameters
Parameter | Required | Description | Format | Default value |
| Yes | OSS bucket URL. Must end with a forward slash (/). | oss://{bucket_name}.{oss_host}/{path} | N/A |
| Yes | ARN of the RAM role with OSS bucket permissions. To get the ARN, log on to the PAI console and go to the Dependent Services page. In the Designer section, find OSS, click View Authorization in the Actions column, and copy the Role Name value. For more information, see Grant permissions to use Machine Learning Designer. | acs:ram::*:role/AliyunODPSPAIDefaultRole | N/A |
| No | OSS bucket domain name. For more information, see Regions and endpoints. | oss-{region}.aliyuncs.com | By default, specified by |
| No | Distributed training configuration. | JSON string | "" |
| No | GPUs per worker. By default, each worker uses one GPU. A value of 200 allocates two GPUs per worker. | 100 | 100 |
| Yes | Job type to run on EasyVision. For training, set to train. | train | N/A |
| Yes | Model training configuration. Uses the same format as Python's ArgumentParser() object. For more information, see param_config. | STRING | N/A |
param_config
The param_config parameter specifies model training parameters in command-line format for Python's argparse module. Example:
-Dparam_config = '--backbone resnet_v1_50 --num_classes 200 --model_dir oss://YOUR_BUCKET_NAME/exp_dir'Do not enclose string parameter values in double quotation marks (") or single quotation marks (').
Architecture
Parameter | Required | Description | Format | Default value |
| Yes | Model type to train. For semantic image segmentation, set to DeeplabV3. | STRING | N/A |
| Yes | Backbone network name. Valid values: | STRING | N/A |
| No | Feature downsampling stride of the backbone network. | INT | 16 |
| No | Whether to train the batch normalization (BN) layer. Set to true if | BOOL | true |
| No | Weight decay coefficient (L2 regularization). | FLOAT | 1e-4 |
| No | OSS path of a pretrained model. If specified, training fine-tunes the pretrained model. | oss://examplebucket/pretrained_models/inception_v4.ckpt | "" |
| No | Whether to use a pretrained model. | BOOL | true |
Data
Parameter | Required | Description | Format | Default value |
| Yes | Number of segmentation classes, including background. | 21 | N/A |
| Yes | OSS path of training data. | oss://path/to/train_*.tfrecord | N/A |
| Yes | OSS path of evaluation data. | oss://path/to/test_*.tfrecord | N/A |
| No | Image size after cropping. | INT | 513 |
| No | Total number of training samples. Required for custom TFRecord files. | INT | 0 |
| No | .pbtxt file that maps label IDs to label names. Required for custom TFRecord files. | STRING | "" |
| No | Concurrent threads for reading training samples. | INT | 4 |
Training
Parameter | Required | Description | Format | Default value |
| Yes | Number of training epochs. A value of 1 processes each training sample once. | INT | N/A |
| Yes | Batch size for training. | INT | N/A |
| Yes | Batch size for evaluation. | INT | N/A |
| No | Number of samples for model evaluation. A value of -1 evaluates on the entire training dataset. | INT | -1 |
| No | Optimizer type. Valid values: | STRING | momentum |
| No | Learning rate adjustment policy. Valid values: | STRING | exponential_decay |
| No | Initial learning rate. | FLOAT | 0.01 |
| No | For | INTEGER list | 20 |
| No | Learning rate decay factor. Equivalent to the decay_factor parameter of | FLOAT | 0.95 |
| No | Whether to decrease the learning rate at discrete intervals. Equivalent to the staircase parameter of | BOOL | true |
| No | Polynomial power. Equivalent to the power parameter of | FLOAT | 0.9 |
| No | Learning rate for each specified epoch. Required when | FLOAT list | N/A |
| No | Whether to warm up the learning rate before training. | BOOL | false |
| No | Number of epochs for learning rate warmup. | FLOAT | 1 |
Output
Parameter | Required | Description | Format | Default value |
| Yes | OSS path for storing the trained model. | oss://path/to/model | N/A |
| No | Number of samples to visualize during model evaluation. | INT | 10 |
| No | Checkpoint save interval in epochs. A value of 1 saves a checkpoint after each epoch. | INT | 1 |
| No | Summary save interval in epochs. A value of 0.01 saves a summary after every 1% of training data. | FLOAT | 0.01 |