Preface
This article is mainly used to record the process of using python to do image recognition semantic segmentation training set. Since there are too many bugs to eliminate during this process, I hope that students who want to do this part can avoid taking some detours.
This article is the fourth article on semantic segmentation and street view recognition in python. The content of the program is almost the last part. Several documents related to subsequent operations may be updated in the future.
1. Training using the PaddlePaddle framework
Framework download address
https//github.com/PaddlePaddle/PaddleSeg/blob/release/2.4/README_CN.md
The author's folder is PaddleSeg-release-2.8 and is opened as follows
(1) Under the configs folder are different network model configuration files
(2) Different model deployments are under the deploy folder.
2. Procedure
Place the dataset folder under the paddlepaddle folder
2.1 Configure yml file
Create a new file named my.yml and place it in the PaddleSeg-release-2.8 folder. The code is as follows
batch_size: 4
eaters : 1000
train_dataset:
type: Dataset
dataset_root: dataset
train_path: dataset/train.txt
num_classes: 30
transforms:
- type: Resize
target_size: [512,512]
- type: RandomHorizontalFlip
- type: Normalize
mode: train
val_dataset:
type: Dataset
dataset_root: dataset
val_path: dataset/val.txt
num_classes: 30
transforms:
- type: Resize
target_size: [512,512]
- type: RandomHorizontalFlip
- type: Normalize
mode: val
optimizer:
type: sgd
momentum: 0.9
weight_decay: 4.0e-5
lr_scheduler:
type: PolynomialDecay
learning_rate: 0.01
end_lr: 0
power: 0.9
loss:
types:
- type: CrossEntropyLoss
coef: [1,1,1,1,1]
model:
type: BiSeNetV2
pretrained: Null
illustrate:
(1)batch_size can be changed according to the size of the video memory
(2) How many times does iters iterate?
(3) The paths of train_dataset and val_dataset need to be modified according to the actual file location
(4) The type of model selected here is BisNetV2. You can change other models as needed.
2.2 Run the program
Hold down the shift right button in the PaddleSeg-release-2.8 folder to open the command line input
training code
python ./tools/train.py --config my.yml --do_eval --use_vdl --save_interval 200 --save_dir output
illustrate:
(1) Find the path of train.py. Different versions are different. Here it is under the tools folder;
(2) --save_interval 200 means saving once every 200 iterations
(3) --save_dir output is the saving location of the running results. If there is no output folder, create one manually.
When the script starts running, it indicates that it is normal. You can check the final accuracy indicator to detect the degree of training, which is generally between 60% and 70%. Increasing the amount of training and the number of iterations can greatly improve the accuracy.
Verify accuracy code
python tools/val.py --config my.yml --model_path output/iter_10000/model.pdparams
Call the training set prediction code
python tools/predict.py --config my.yml --model_path output/iter_10000/model.pdparams --image_path dataset/predict --save_dir output/result
It’s over here, wait for the results.