Commit fccfdfa5 authored by dlyrm's avatar dlyrm
Browse files

update code

parent dcc7bf4f
Pipeline #681 canceled with stages
This image diff could not be displayed because it is too large. You can view the blob instead.
[English](DistributedTraining_en.md) | 简体中文
# 分布式训练
## 1. 简介
* 分布式训练指的是将训练任务按照一定方法拆分到多个计算节点进行计算,再按照一定的方法对拆分后计算得到的梯度等信息进行聚合与更新。飞桨分布式训练技术源自百度的业务实践,在自然语言处理、计算机视觉、搜索和推荐等领域经过超大规模业务检验。分布式训练的高性能,是飞桨的核心优势技术之一,PaddleDetection同时支持单机训练与多机训练。更多关于分布式训练的方法与文档可以参考:[分布式训练快速开始教程](https://fleet-x.readthedocs.io/en/latest/paddle_fleet_rst/parameter_server/ps_quick_start.html)
## 2. 使用方法
### 2.1 单机训练
* 以PP-YOLOE-s为例,本地准备好数据之后,使用`paddle.distributed.launch`或者`fleetrun`的接口启动训练任务即可。下面为运行脚本示例。
```bash
fleetrun \
--selected_gpu 0,1,2,3,4,5,6,7 \
tools/train.py -c configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml \
--eval &>logs.txt 2>&1 &
```
### 2.2 多机训练
* 相比单机训练,多机训练时,只需要添加`--ips`的参数,该参数表示需要参与分布式训练的机器的ip列表,不同机器的ip用逗号隔开。下面为运行代码示例。
```shell
ip_list="10.127.6.17,10.127.5.142,10.127.45.13,10.127.44.151"
fleetrun \
--ips=${ip_list} \
--selected_gpu 0,1,2,3,4,5,6,7 \
tools/train.py -c configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml \
--eval &>logs.txt 2>&1 &
```
**注:**
* 不同机器的ip信息需要用逗号隔开,可以通过`ifconfig`或者`ipconfig`查看。
* 不同机器之间需要做免密设置,且可以直接ping通,否则无法完成通信。
* 不同机器之间的代码、数据与运行命令或脚本需要保持一致,且所有的机器上都需要运行设置好的训练命令或者脚本。最终`ip_list`中的第一台机器的第一块设备是trainer0,以此类推。
* 不同机器的起始端口可能不同,建议在启动多机任务前,在不同的机器中设置相同的多机运行起始端口,命令为`export FLAGS_START_PORT=17000`,端口值建议在`10000~20000`之间。
## 3. 性能效果测试
* 在单机和4机8卡V100的机器上,基于[PP-YOLOE-s](../../configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml)进行模型训练,模型的训练耗时情况如下所示。
机器 | 精度 | 耗时
-|-|-
单机8卡 | 42.7% | 39h
4机8卡 | 42.1% | 13h
English | [简体中文](DistributedTraining_cn.md)
## 1. Usage
### 1.1 Single-machine
* Take PP-YOLOE-s as an example, after preparing the data locally, use the interface of `paddle.distributed.launch` or `fleetrun` to start the training task. Below is an example of running the script.
```bash
fleetrun \
--selected_gpu 0,1,2,3,4,5,6,7 \
tools/train.py -c configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml \
--eval &>logs.txt 2>&1 &
```
### 1.2 Multi-machine
* Compared with single-machine training, when training on multiple machines, you only need to add the `--ips` parameter, which indicates the ip list of machines that need to participate in distributed training. The ips of different machines are separated by commas. Below is an example of running code.
```shell
ip_list="10.127.6.17,10.127.5.142,10.127.45.13,10.127.44.151"
fleetrun \
--ips=${ip_list} \
--selected_gpu 0,1,2,3,4,5,6,7 \
tools/train.py -c configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml \
--eval &>logs.txt 2>&1 &
```
**Note:**
* The ip information of different machines needs to be separated by commas, which can be viewed through `ifconfig` or `ipconfig`.
* Password-free settings are required between different machines, and they can be pinged directly, otherwise the communication cannot be completed.
* The code, data, and running commands or scripts between different machines need to be consistent, and the set training commands or scripts need to be run on all machines. The first device of the first machine in the final `ip_list` is trainer0, and so on.
* The starting port of different machines may be different. It is recommended to set the same starting port for multi-machine running in different machines before starting the multi-machine task. The command is `export FLAGS_START_PORT=17000`, and the port value is recommended to be `10000~20000`.
## 2. Performance
* On single-machine and 4-machine 8-card V100 machines, model training is performed based on [PP-YOLOE-s](../../configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml). The model training time is as follows.
Machine | mAP | Time cost
-|-|-
single machine | 42.7% | 39h
4 machines | 42.1% | 13h
# FAQ:第一期
**Q:**SOLOv2训练mAP值宽幅震荡,无上升趋势,检测效果不好,检测置信度超过了1的原因是?
**A:** SOLOv2训练不收敛的话,先更新PaddleDetection到release/2.2或者develop分支尝试。
**Q:** Optimizer中优化器支持哪几种?
**A:** Paddle中支持的优化器[Optimizer](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/optimizer/Overview_cn.html )在PaddleDetection中均支持,需要手动修改下配置文件即可。
**Q:** 在tools/infer.py加入如下函数,得到FLOPs值为-1,请问原因?
**A:** 更新PaddleDetection到release/2.2或者develop分支,`print_flops`设为True即可打印FLOPs。
**Q:** 使用官方的ReID模块时遇到了模块未注册的问题
**A:** 请尝试`pip uninstall paddledet`并重新安装,或者`python setup.py install`
**Q:** 大规模实用目标检测模型有动态图版本吗,或者可以转换为动态图版本吗?
**A:** 大规模实用模型的动态图版本正在整理,我们正在开发更大规模的通用预训练模型,预计在2.3版本中发布。
**Q:** Develop分支下FairMot预测视频问题:预测视频时不会完全运行完毕。比如用一个300frame的视频,代码会保存预测结果的每一帧图片,但只保存到299张就没了,并且也没有预测好的视频文件生成,该如何解决?
**A:** 已经支持自己设置帧率infer视频,请使用develop分支或release/2.2分支,命令如下:
```
CUDA_VISIBLE_DEVICES=0 python tools/infer_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608.pdparams --video_file={your video name}.mp4 --frame_rate=20 --save_videos
```
**Q:** 使用YOLOv3模型如何通过yml文件修改输入图片尺寸?
**A:** 模型预测部署需要用到指定的尺寸时,首先在训练前需要修改`configs/_base_/yolov3_reader.yml`中的`TrainReader``BatchRandomResize``target_size`包含指定的尺寸,训练完成后,在评估或者预测时,需要将`EvalReader``TestReader`中的`Resize``target_size`修改成对应的尺寸,如果是需要模型导出(export_model),则需要将`TestReader`中的`image_shape`修改为对应的图片输入尺寸 。
**Q:** 以前的模型都是用静态图训练的,现在想用动态图训练,但想加载原来静态图的模型作为预训练模型,可以直接用加载静态图保存的模型断点吗?如不行,有其它方法吗?
**A:** 静态图和动态图模型的权重的key做下映射一一对应转过去是可以的,可以参考[这个代码](https://github.com/nemonameless/weights_st2dy )。但是不保证所有静态图的权重的key映射都能对应上,静态图是把背景也训练了,动态图去背景类训的,而且现有动态图模型训出来的一般都比以前静态图更高,资源时间够的情况下建议还是直接训动态图版本。
**Q:** TTFNet训练过程中hm_loss异常
**A:** 如果是单卡的话学习率需要对应降低8倍。另外ttfnet模型因为自身设置的学习率比较大,可能会出现其他数据集训练出现不稳定的情况。建议pretrain_weights加载官方release出的coco数据集上训练好的模型,然后将学习率再调低一些。
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment