diff --git a/fluid/PaddleCV/yolov3/README.md b/fluid/PaddleCV/yolov3/README.md index 2c78463f3ef4d376472ee7093a57db11872b2343..d8f1ab68be65fdd1c82f1f5784f0f892cf2a48fd 100644 --- a/fluid/PaddleCV/yolov3/README.md +++ b/fluid/PaddleCV/yolov3/README.md @@ -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 diff --git a/fluid/PaddleCV/yolov3/README_cn.md b/fluid/PaddleCV/yolov3/README_cn.md index 35c6f2d99cce5e5d2e5d81a284d92c78659fba48..6a1a2ddb35632a9bfdb03d90ec3bd56f75b82bd7 100644 --- a/fluid/PaddleCV/yolov3/README_cn.md +++ b/fluid/PaddleCV/yolov3/README_cn.md @@ -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 diff --git a/fluid/PaddleCV/yolov3/config/config.py b/fluid/PaddleCV/yolov3/config/config.py index 6d874f699cc04b809408d4581be352a0e131b5dd..83f576436586a89e72792fde9712aeb4ee846cca 100644 --- a/fluid/PaddleCV/yolov3/config/config.py +++ b/fluid/PaddleCV/yolov3/config/config.py @@ -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 diff --git a/fluid/PaddleCV/yolov3/eval.py b/fluid/PaddleCV/yolov3/eval.py index ae5d29b089b36fcc7034fd32ccc40af8cef8b48d..5521a23f45682bdcc62da2978740f0955f0c3790 100644 --- a/fluid/PaddleCV/yolov3/eval.py +++ b/fluid/PaddleCV/yolov3/eval.py @@ -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 diff --git a/fluid/PaddleCV/yolov3/infer.py b/fluid/PaddleCV/yolov3/infer.py index 2556f2c000cae506d2b660751b6a0adbdae64028..78ee0196324bad3d038e8d90e400351f70180303 100644 --- a/fluid/PaddleCV/yolov3/infer.py +++ b/fluid/PaddleCV/yolov3/infer.py @@ -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] diff --git a/fluid/PaddleCV/yolov3/train.py b/fluid/PaddleCV/yolov3/train.py index eb938eee7f6b3abd7cae40b394a9fca17470e17f..46b721252ee3057d466f0f5ea9af691d2b69d489 100644 --- a/fluid/PaddleCV/yolov3/train.py +++ b/fluid/PaddleCV/yolov3/train.py @@ -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) diff --git a/fluid/PaddleCV/yolov3/utility.py b/fluid/PaddleCV/yolov3/utility.py index b911a04e9bf37ee113ecea880a3215f9c3b3d86b..84544e5504f0d53672c3e4facc0451bfa7176aef 100644 --- a/fluid/PaddleCV/yolov3/utility.py +++ b/fluid/PaddleCV/yolov3/utility.py @@ -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.") diff --git a/fluid/PaddleCV/yolov3/weights/download.sh b/fluid/PaddleCV/yolov3/weights/download.sh index 33e9630b6643169e5e96bb35eb2970d6ed1be1d6..797d804b554e6f2a3b05d06e468dc6d3713ce6f8 100644 --- a/fluid/PaddleCV/yolov3/weights/download.sh +++ b/fluid/PaddleCV/yolov3/weights/download.sh @@ -1,5 +1,10 @@ +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