test_whole_process.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # This file tests the whole process from training to deployment
  2. # Usage:
  3. # 1. Install PaddlePaddle that supports TenorRT
  4. # 2. `export CUDA_VISIBLE_DEVICES=id`
  5. # 3. `cd ./PaddleSeg/Matting`
  6. #. 4. `bash tests/test_whole_process.sh`
  7. save_root="output/tests"
  8. mkdir -p ${save_root}
  9. video_path="${save_root}/v1.mov"
  10. # Obtain dataset to test
  11. dataset_root="data/PPM-100"
  12. if [ ! -d ${dataset_root} ]; then
  13. mkdir -p data && cd data
  14. wget https://paddleseg.bj.bcebos.com/matting/datasets/PPM-100.zip
  15. unzip PPM-100.zip
  16. rm PPM-100.zip
  17. cd ..
  18. fi
  19. # Obtaion video to test
  20. if [ ! -a ${video_path} ]; then
  21. wget https://paddleseg.bj.bcebos.com/matting/demo/v1.mov
  22. mv v1.mov ${save_root}
  23. fi
  24. # Training
  25. echo "Test training..."
  26. python tools/train.py \
  27. --config configs/quick_start/ppmattingv2-stdc1-human_512.yml \
  28. --learning_rate 0.0001 \
  29. --iters 10 \
  30. --batch_size 1 \
  31. --log_iters 1 \
  32. --use_vdl \
  33. --save_interval 10 \
  34. --do_eval \
  35. --num_workers 1 \
  36. --save_dir ${save_root} \
  37. --opts model.pretrained="https://paddleseg.bj.bcebos.com/matting/models/ppmattingv2-stdc1-human_512.pdparams"
  38. # Evaluation
  39. echo "Test evaluation..."
  40. python tools/val.py \
  41. --config configs/quick_start/ppmattingv2-stdc1-human_512.yml \
  42. --model_path ${save_root}/best_model/model.pdparams \
  43. --metrics sad mse grad conn \
  44. --save_dir ${save_root}/results/evaluation \
  45. --save_results
  46. # Predictions
  47. echo "Test prediction..."
  48. python tools/predict.py \
  49. --config configs/quick_start/ppmattingv2-stdc1-human_512.yml \
  50. --model_path ${save_root}/best_model/model.pdparams \
  51. --image_path demo/human.jpg \
  52. --save_dir ${save_root}/results/prediction \
  53. --fg_estimate True
  54. python tools/predict.py --config configs/quick_start/ppmattingv2-stdc1-human_512.yml --model_path ${save_root}/best_model/model.pdparams --image_path demo/human.jpg --fg_estimate True
  55. # Video prediction
  56. echo "Test video predcition..."
  57. python tools/predict_video.py \
  58. --config configs/quick_start/ppmattingv2-stdc1-human_512.yml \
  59. --model_path ${save_root}/best_model/model.pdparams \
  60. --video_path ${video_path} \
  61. --save_dir ${save_root}/results/video_prediction \
  62. --fg_estimate False
  63. # Background replacement
  64. echo "Test background replacement..."
  65. python tools/bg_replace.py \
  66. --config configs/quick_start/ppmattingv2-stdc1-human_512.yml \
  67. --model_path ${save_root}/best_model/model.pdparams \
  68. --image_path demo/human.jpg \
  69. --background g \
  70. --save_dir ${save_root}/results/background_replacement \
  71. --fg_estimate True
  72. # Video background replacement
  73. echo "Test video background replacement..."
  74. python tools/bg_replace_video.py \
  75. --config configs/quick_start/ppmattingv2-stdc1-human_512.yml \
  76. --model_path ${save_root}/best_model/model.pdparams \
  77. --video_path ${video_path} \
  78. --background 'g' \
  79. --save_dir ${save_root}/results/video_background_replacement \
  80. --fg_estimate False
  81. # Export
  82. echo "Test exportment..."
  83. python tools/export.py \
  84. --config configs/quick_start/ppmattingv2-stdc1-human_512.yml \
  85. --model_path ${save_root}/best_model/model.pdparams \
  86. --save_dir ${save_root}/export \
  87. --input_shape 1 3 512 512
  88. # Deployment
  89. echo "Test deployment"
  90. python deploy/python/infer.py \
  91. --config ${save_root}/export/deploy.yaml \
  92. --image_path demo/human.jpg \
  93. --save_dir ${save_root}/results/deploy \
  94. python deploy/python/infer.py \
  95. --config ${save_root}/export/deploy.yaml \
  96. --video_path ${video_path} \
  97. --save_dir ${save_root}/results/deploy \
  98. --fg_estimate False