未验证 提交 508a3afb 编写于 作者: G Guanghua Yu 提交者: GitHub

fix distributed train in detection act (#1210)

上级 d0d43915
...@@ -96,14 +96,19 @@ tar -xf ppyoloe_crn_l_300e_coco.tar ...@@ -96,14 +96,19 @@ tar -xf ppyoloe_crn_l_300e_coco.tar
#### 3.4 自动压缩并产出模型 #### 3.4 自动压缩并产出模型
蒸馏量化自动压缩示例通过run.py脚本启动,会使用接口```paddleslim.auto_compression.AutoCompression```对模型进行自动压缩。配置config文件中模型路径、蒸馏、量化、和训练等部分的参数,配置完成后便可对模型进行量化和蒸馏。具体运行命令为: 蒸馏量化自动压缩示例通过run.py脚本启动,会使用接口```paddleslim.auto_compression.AutoCompression```对模型进行自动压缩。配置config文件中模型路径、蒸馏、量化、和训练等部分的参数,配置完成后便可对模型进行量化和蒸馏。具体运行命令为:
- 单卡训练:
``` ```
# 单卡
export CUDA_VISIBLE_DEVICES=0 export CUDA_VISIBLE_DEVICES=0
# 多卡
# export CUDA_VISIBLE_DEVICES=0,1,2,3
python run.py --config_path=./configs/ppyoloe_l_qat_dis.yaml --save_dir='./output/' python run.py --config_path=./configs/ppyoloe_l_qat_dis.yaml --save_dir='./output/'
``` ```
- 多卡训练:
```
CUDA_VISIBLE_DEVICES=0,1,2,3 python -m paddle.distributed.launch --log_dir=log --gpus 0,1,2,3 run.py \
--config_path=./configs/ppyoloe_l_qat_dis.yaml --save_dir='./output/'
```
#### 3.5 测试模型精度 #### 3.5 测试模型精度
使用eval.py脚本得到模型的mAP: 使用eval.py脚本得到模型的mAP:
......
...@@ -124,10 +124,16 @@ def main(): ...@@ -124,10 +124,16 @@ def main():
return_list=True) return_list=True)
train_loader = reader_wrapper(train_loader, global_config['input_list']) train_loader = reader_wrapper(train_loader, global_config['input_list'])
if 'Evaluation' in global_config.keys() and global_config[
'Evaluation'] and paddle.distributed.get_rank() == 0:
eval_func = eval_function
dataset = reader_cfg['EvalDataset'] dataset = reader_cfg['EvalDataset']
global val_loader global val_loader
val_loader = create('EvalReader')(reader_cfg['EvalDataset'], _eval_batch_sampler = paddle.io.BatchSampler(
dataset, batch_size=reader_cfg['EvalReader']['batch_size'])
val_loader = create('EvalReader')(dataset,
reader_cfg['worker_num'], reader_cfg['worker_num'],
batch_sampler=_eval_batch_sampler,
return_list=True) return_list=True)
metric = None metric = None
if reader_cfg['metric'] == 'COCO': if reader_cfg['metric'] == 'COCO':
...@@ -143,9 +149,6 @@ def main(): ...@@ -143,9 +149,6 @@ def main():
else: else:
raise ValueError("metric currently only supports COCO and VOC.") raise ValueError("metric currently only supports COCO and VOC.")
global_config['metric'] = metric global_config['metric'] = metric
if 'Evaluation' in global_config.keys() and global_config['Evaluation']:
eval_func = eval_function
else: else:
eval_func = None eval_func = None
......
...@@ -92,14 +92,19 @@ cp -r pd_model/inference_model/ yolov5_inference_model ...@@ -92,14 +92,19 @@ cp -r pd_model/inference_model/ yolov5_inference_model
#### 3.4 自动压缩并产出模型 #### 3.4 自动压缩并产出模型
蒸馏量化自动压缩示例通过run.py脚本启动,会使用接口```paddleslim.auto_compression.AutoCompression```对模型进行自动压缩。配置config文件中模型路径、蒸馏、量化、和训练等部分的参数,配置完成后便可对模型进行量化和蒸馏。具体运行命令为: 蒸馏量化自动压缩示例通过run.py脚本启动,会使用接口```paddleslim.auto_compression.AutoCompression```对模型进行自动压缩。配置config文件中模型路径、蒸馏、量化、和训练等部分的参数,配置完成后便可对模型进行量化和蒸馏。具体运行命令为:
- 单卡训练:
``` ```
# 单卡
export CUDA_VISIBLE_DEVICES=0 export CUDA_VISIBLE_DEVICES=0
# 多卡
# export CUDA_VISIBLE_DEVICES=0,1,2,3
python run.py --config_path=./configs/yolov5s_qat_dis.yaml --save_dir='./output/' python run.py --config_path=./configs/yolov5s_qat_dis.yaml --save_dir='./output/'
``` ```
- 多卡训练:
```
CUDA_VISIBLE_DEVICES=0,1,2,3 python -m paddle.distributed.launch --log_dir=log --gpus 0,1,2,3 run.py \
--config_path=./configs/yolov5s_qat_dis.yaml --save_dir='./output/'
```
#### 3.5 测试模型精度 #### 3.5 测试模型精度
使用eval.py脚本得到模型的mAP: 使用eval.py脚本得到模型的mAP:
......
...@@ -138,10 +138,16 @@ def main(): ...@@ -138,10 +138,16 @@ def main():
return_list=True) return_list=True)
train_loader = reader_wrapper(train_loader, global_config['input_list']) train_loader = reader_wrapper(train_loader, global_config['input_list'])
if 'Evaluation' in global_config.keys() and global_config[
'Evaluation'] and paddle.distributed.get_rank() == 0:
eval_func = eval_function
dataset = reader_cfg['EvalDataset'] dataset = reader_cfg['EvalDataset']
global val_loader global val_loader
val_loader = create('EvalReader')(reader_cfg['EvalDataset'], _eval_batch_sampler = paddle.io.BatchSampler(
dataset, batch_size=reader_cfg['EvalReader']['batch_size'])
val_loader = create('EvalReader')(dataset,
reader_cfg['worker_num'], reader_cfg['worker_num'],
batch_sampler=_eval_batch_sampler,
return_list=True) return_list=True)
metric = None metric = None
if reader_cfg['metric'] == 'COCO': if reader_cfg['metric'] == 'COCO':
...@@ -157,9 +163,6 @@ def main(): ...@@ -157,9 +163,6 @@ def main():
else: else:
raise ValueError("metric currently only supports COCO and VOC.") raise ValueError("metric currently only supports COCO and VOC.")
global_config['metric'] = metric global_config['metric'] = metric
if 'Evaluation' in global_config.keys() and global_config['Evaluation']:
eval_func = eval_function
else: else:
eval_func = None eval_func = None
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册