提交 bf0abcf3 编写于 作者: D dengkaipeng

fix yolo backbone

上级 308447ba
dataset/voc*
pretrain_weights/darknet53_pretrained.pdparams
......@@ -99,9 +99,17 @@ YOLOv3 的网络结构由基础特征提取网络、multi-scale特征融合层
| ...
```
### 预训练权重下载
YOLOv3模型训练需下载骨干网络DarkNet53的预训练权重,可通过如下方式下载。
```bash
sh pretrain_weights/download.sh
```
### 模型训练
数据准备完毕后,可使用`main.py`脚本启动训练和评估,如下脚本会自动每epoch交替进行训练和模型评估,并将checkpoint默认保存在`yolo_checkpoint`目录下。
数据和预训练权重下载完成后,可使用`main.py`脚本启动训练和评估,如下脚本会自动每epoch交替进行训练和模型评估,并将checkpoint默认保存在`yolo_checkpoint`目录下。
YOLOv3模型训练总batch_size为64训练,以下以使用4卡Tesla P40每卡batch_size为16训练介绍训练方式。对于静态图和动态图,多卡训练中`--batch_size`为每卡上的batch_size,即总batch_size为`--batch_size`乘以卡数。
......@@ -117,7 +125,7 @@ python main.py --help
使用如下方式进行多卡训练:
```bash
CUDA_VISIBLE_DEVICES=0,1,2,3 python -m paddle.distributed.launch main.py --data=<path/to/dataset> --batch_size=16
CUDA_VISIBLE_DEVICES=0,1,2,3 python -m paddle.distributed.launch main.py --data=<path/to/dataset> --batch_size=16 --pretrain_weights=./pretrain_weights/darknet53_pretrained
```
#### 动态图训练
......@@ -127,7 +135,7 @@ CUDA_VISIBLE_DEVICES=0,1,2,3 python -m paddle.distributed.launch main.py --data=
使用如下方式进行多卡训练:
```bash
CUDA_VISIBLE_DEVICES=0,1,2,3 python main.py -m paddle.distributed.launch --data=<path/to/dataset> --batch_size=16 -d
CUDA_VISIBLE_DEVICES=0,1,2,3 python main.py -m paddle.distributed.launch --data=<path/to/dataset> --batch_size=16 -d --pretrain_weights=./pretrain_weights/darknet53_pretrained
```
......
......@@ -28,6 +28,7 @@ from paddle.io import DataLoader
from hapi.model import Model, Input, set_device
from hapi.distributed import DistributedBatchSampler
from hapi.datasets import COCODataset
from hapi.download import get_weights_path
from hapi.vision.transforms import *
from hapi.vision.models import yolov3_darknet53, YoloLoss
......@@ -124,7 +125,7 @@ def main():
model_mode='eval' if FLAGS.eval_only else 'train',
pretrained=pretrained)
if FLAGS.pretrain_weights is not None:
if FLAGS.pretrain_weights and not FLAGS.eval_only:
model.load(FLAGS.pretrain_weights, skip_mismatch=True, reset_optimizer=True)
optim = make_optimizer(len(batch_sampler), parameter_list=model.parameters())
......@@ -196,7 +197,8 @@ if __name__ == '__main__':
parser.add_argument(
"-j", "--num_workers", default=4, type=int, help="reader worker number")
parser.add_argument(
"-p", "--pretrain_weights", default=None, type=str,
"-p", "--pretrain_weights",
default="./pretrain_weights/darknet53_pretrained", type=str,
help="path to pretrained weights")
parser.add_argument(
"-r", "--resume", default=None, type=str,
......
DIR="$( cd "$(dirname "$0")" ; pwd -P )"
cd "$DIR"
echo "Downloading https://paddlemodels.bj.bcebos.com/hapi/darknet53_pretrained.pdparams"
wget https://paddlemodels.bj.bcebos.com/hapi/darknet53_pretrained.pdparams
......@@ -136,7 +136,7 @@ class LayerWarp(fluid.dygraph.Layer):
DarkNet_cfg = {53: ([1, 2, 8, 8, 4])}
class DarkNet(Model):
class DarkNet(fluid.dygraph.Layer):
"""DarkNet model from
`"YOLOv3: An Incremental Improvement" <https://arxiv.org/abs/1804.02767>`_
......
......@@ -118,7 +118,7 @@ class YOLOv3(Model):
self.nms_posk = 100
self.draw_thresh = 0.5
self.backbone = darknet53(pretrained=(model_mode=='train'))
self.backbone = darknet53(pretrained=False)
self.block_outputs = []
self.yolo_blocks = []
self.route_blocks = []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册