提交 b4bdcc5e 编写于 作者: D dengkaipeng

refine args.

上级 c25000a2
......@@ -52,7 +52,7 @@ After data preparation, one can start the training step by:
python train.py \
--model_save_dir=output/ \
--pretrained_model=${path_to_pretrain_model}
--pretrain=${path_to_pretrain_model}
--data_dir=${path_to_data}
- Set ```export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7``` to specifiy 8 GPU to train.
......@@ -62,10 +62,10 @@ After data preparation, one can start the training step by:
**download the pre-trained model:** This sample provides Resnet-50 pre-trained model which is converted from Caffe. The model fuses the parameters in batch normalization layer. One can download pre-trained model as:
sh ./weights/download_pretrain_weights.sh
sh ./weights/download.sh
Set `pretrained_model` to load pre-trained model. In addition, this parameter is used to load trained model when finetuning as well.
Please make sure that pretrained_model is downloaded and loaded correctly, otherwise, the loss may be NAN during training.
Set `pretrain` to load pre-trained model. In addition, this parameter is used to load trained model when finetuning as well.
Please make sure that pre-trained model is downloaded and loaded correctly, otherwise, the loss may be NAN during training.
**Install the [cocoapi](https://github.com/cocodataset/cocoapi):**
......@@ -111,25 +111,25 @@ Evaluation is to evaluate the performance of a trained model. This sample provid
python eval.py \
--dataset=coco2017 \
--pretrained_model=${path_to_pretrain_model} \
--weights=${path_to_weights} \
- Set ```export CUDA_VISIBLE_DEVICES=0``` to specifiy one GPU to eval.
Evalutaion result is shown as below:
```text
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.370
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.581
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.401
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.236
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.403
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.480
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.297
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.450
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.466
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.309
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.500
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.586
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.377
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.598
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.408
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.244
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.408
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.489
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.308
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.481
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.504
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.351
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.534
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.632
```
......@@ -139,7 +139,7 @@ Inference is used to get prediction score or image features based on trained mod
python infer.py \
--dataset=coco2017 \
--pretrained_model=${path_to_pretrain_model} \
--weights=${path_to_weights} \
--image_path=data/COCO17/val2017/ \
--image_name=000000000139.jpg \
--draw_threshold=0.5
......
......@@ -54,7 +54,7 @@ YOLOv3 的网络结构由基础特征提取网络、multi-scale特征融合层
python train.py \
--model_save_dir=output/ \
--pretrained_model=${path_to_pretrain_model}
--pretrain=${path_to_pretrain_model}
--data_dir=${path_to_data}
- 通过设置export CUDA\_VISIBLE\_DEVICES=0,1,2,3,4,5,6,7指定8卡GPU训练。
......@@ -66,7 +66,7 @@ YOLOv3 的网络结构由基础特征提取网络、multi-scale特征融合层
sh ./weights/download_pretrained_weight.sh
通过初始化`pretrained_model` 加载预训练模型。同时在参数微调时也采用该设置加载已训练模型。
通过初始化`pretrain` 加载预训练模型。同时在参数微调时也采用该设置加载已训练模型。
请在训练前确认预训练模型下载与加载正确,否则训练过程中损失可能会出现NAN。
**安装[cocoapi](https://github.com/cocodataset/cocoapi):**
......@@ -112,25 +112,25 @@ Train Loss
python eval.py \
--dataset=coco2017 \
--pretrained_model=${path_to_pretrain_model} \
--weights=${path_to_weights} \
- 通过设置export CUDA\_VISIBLE\_DEVICES=0指定单卡GPU评估。
模型评估结果:
```text
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.370
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.581
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.401
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.236
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.403
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.480
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.297
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.450
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.466
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.309
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.500
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.586
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.377
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.598
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.408
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.244
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.408
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.489
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.308
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.481
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.504
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.351
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.534
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.632
```
......@@ -141,7 +141,7 @@ Train Loss
python infer.py \
--dataset=coco2017 \
--pretrained_model=${path_to_pretrain_model} \
--weights=${path_to_weights} \
--image_path=data/COCO17/val2017/ \
--image_name=000000000139.jpg \
--draw_threshold=0.5
......
......@@ -51,7 +51,7 @@ _C.nms_topk = 400
_C.nms_posk = 100
# score threshold for draw box in debug mode
_C.conf_thresh = 0.5
_C.draw_thresh = 0.5
#
......@@ -72,10 +72,10 @@ _C.pixel_stds = [0.229, 0.224, 0.225]
_C.learning_rate = 0.001
# maximum number of iterations
_C.max_iter = 500000
_C.max_iter = 500200
# warm up to learning rate
_C.warm_up_iter = 1000
_C.warm_up_iter = 4000
_C.warm_up_factor = 0.
# lr steps_with_decay
......
......@@ -48,10 +48,10 @@ def eval():
place = fluid.CUDAPlace(0) if cfg.use_gpu else fluid.CPUPlace()
exe = fluid.Executor(place)
# yapf: disable
if cfg.pretrained_model:
if cfg.weights:
def if_exist(var):
return os.path.exists(os.path.join(cfg.pretrained_model, var.name))
fluid.io.load_vars(exe, cfg.pretrained_model, predicate=if_exist)
return os.path.exists(os.path.join(cfg.weights, var.name))
fluid.io.load_vars(exe, cfg.weights, predicate=if_exist)
# yapf: enable
input_size = model.get_input_size()
test_reader = reader.test(input_size, 1)
......@@ -63,8 +63,6 @@ def eval():
def get_pred_result(boxes, scores, labels, im_id):
result = []
for box, score, label in zip(boxes, scores, labels):
if score < 0.05:
continue
x1, y1, x2, y2 = box
w = x2 - x1 + 1
h = y2 - y1 + 1
......
......@@ -28,10 +28,10 @@ def infer():
place = fluid.CUDAPlace(0) if cfg.use_gpu else fluid.CPUPlace()
exe = fluid.Executor(place)
# yapf: disable
if cfg.pretrained_model:
if cfg.weights:
def if_exist(var):
return os.path.exists(os.path.join(cfg.pretrained_model, var.name))
fluid.io.load_vars(exe, cfg.pretrained_model, predicate=if_exist)
return os.path.exists(os.path.join(cfg.weights, var.name))
fluid.io.load_vars(exe, cfg.weights, predicate=if_exist)
# yapf: enable
feeder = fluid.DataFeeder(place=place, feed_list=model.feeds())
fetch_list = [outputs]
......
......@@ -80,10 +80,10 @@ def train():
base_exe = fluid.Executor(place)
base_exe.run(fluid.default_startup_program())
if cfg.pretrain_base:
if cfg.pretrain:
def if_exist(var):
return os.path.exists(os.path.join(cfg.pretrain_base, var.name))
fluid.io.load_vars(base_exe, cfg.pretrain_base, predicate=if_exist)
return os.path.exists(os.path.join(cfg.pretrain, var.name))
fluid.io.load_vars(base_exe, cfg.pretrain, predicate=if_exist)
if cfg.parallel:
exe = fluid.ParallelExecutor( use_cuda=bool(cfg.use_gpu), loss_name=loss.name)
......
......@@ -98,8 +98,8 @@ def parse_args():
add_arg('use_gpu', bool, True, "Whether use GPU.")
add_arg('model_cfg_path', str, 'config/yolov3.cfg', "YOLO model config file path.")
add_arg('model_save_dir', str, 'checkpoints', "The path to save model.")
add_arg('pretrain_base', str, 'weights/darknet53', "The init model weights path.")
add_arg('pretrained_model', str, 'weights/mxnet', "The pretrained model path.")
add_arg('pretrain', str, 'weights/darknet53', "The pretrain model path.")
add_arg('weights', str, 'weights/yolov3', "The weights path.")
add_arg('dataset', str, 'coco2017', "Dataset: coco2014, coco2017.")
add_arg('class_num', int, 80, "Class number.")
add_arg('data_dir', str, 'dataset/coco', "The data root path.")
......@@ -116,7 +116,7 @@ def parse_args():
add_arg('random_shape', bool, True, "Resize to random shape for train reader.")
add_arg('label_smooth', bool, True, "Use label smooth in class label.")
add_arg('no_mixup_iter', int, 40000, "Disable mixup in last N iter.")
add_arg('valid_thresh', float, 0.01, "Valid confidence score for NMS.")
add_arg('valid_thresh', float, 0.005, "Valid confidence score for NMS.")
add_arg('nms_thresh', float, 0.45, "NMS threshold.")
add_arg('nms_topk', int, 400, "The number of boxes to perform NMS.")
add_arg('nms_posk', int, 100, "The number of boxes of NMS output.")
......
DIR="$(dirname "$PWD -P")"
cd "$DIR"
# Download the pretrain weights.
echo "Downloading..."
wget https://paddlemodels.bj.bcebos.com/yolo/darknet53.tar.gz
wget https://paddlemodels.bj.bcebos.com/yolo/yolov3.tar.gz
echo "Extracting..."
tar -xf darknet53.tar.gz
tar -xf yolov3.tar.gz
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册