未验证 提交 38687970 编写于 作者: wc晨曦's avatar wc晨曦 提交者: GitHub

add HRNet export model tutorials (#5502)

上级 78825715
......@@ -98,9 +98,9 @@ python -c "import paddle; print(paddle.__version__)"
- If the coco dataset has been downloaded
The files can be organized according to the above data file organization structure.
### 2.3 Training & Evaluation & Inference
### 2.3 Training & Evaluation & Test
We provides scripts for training, evalution and inference with various features according to different configure.
We provides scripts for training, evalution and test with various features according to different configure.
```bash
# training on single-GPU
......@@ -115,7 +115,7 @@ python -m paddle.distributed.launch --gpus 0,1,2,3,4,5,6,7 tools/train.py -c con
export CUDA_VISIBLE_DEVICES=0
python tools/eval.py -c configs/hrnet_w32_256x192.yml -o weights=https://paddledet.bj.bcebos.com/models/keypoint/hrnet_w32_256x192.pdparams
# Inference
# test
python tools/infer.py -c configs/hrnet_w32_256x192.yml --infer_img=dataset/test_image/hrnet_demo.jpg -o weights=https://paddledet.bj.bcebos.com/models/keypoint/hrnet_w32_256x192.pdparams
# training with distillation
......@@ -133,10 +133,32 @@ python -m paddle.distributed.launch --gpus 0,1,2,3,4,5,6,7 tools/train.py -c con
export CUDA_VISIBLE_DEVICES=0
python tools/eval.py -c configs/lite_hrnet_30_256x192_coco_pact.yml -o weights=https://paddledet.bj.bcebos.com/models/keypoint/lite_hrnet_30_256x192_coco_pact.pdparams
# Inference with PACT quantization
# test with PACT quantization
python tools/infer.py -c configs/lite_hrnet_30_256x192_coco_pact.yml
--infer_img=dataset/test_image/hrnet_demo.jpg -o weights=https://paddledet.bj.bcebos.com/models/keypoint/lite_hrnet_30_256x192_coco_pact.pdparams
```
### 2.4 Export model & Inference
```bash
# export model
python tools/export_model.py -c configs/hrnet_w32_256x192.yml -o weights=https://paddledet.bj.bcebos.com/models/keypoint/hrnet_w32_256x192_coco.pdparams
# inference
python deploy/infer.py --model_dir=output_inference/hrnet_w32_256x192/ --image_file=dataset/test_image/hrnet_demo.jpg
# export model with lite model
python tools/export_model.py -c configs/lite_hrnet_30_256x192_coco.yml -o weights=https://paddledet.bj.bcebos.com/models/keypoint/lite_hrnet_30_256x192_coco.pdparams
# inference with lite model
python deploy/infer.py --model_dir=output_inference/lite_hrnet_30_256x192_coco/ --image_file=dataset/test_image/hrnet_demo.jpg
# export model with PACT quantization
python tools/export_model.py -c configs/lite_hrnet_30_256x192_coco_pact.yml -o weights=https://paddledet.bj.bcebos.com/models/keypoint/lite_hrnet_30_256x192_coco_pact.pdparams
# inference with PACT quantization
python deploy/infer.py --model_dir=output_inference/lite_hrnet_30_256x192_coco_pact/ --image_file=dataset/test_image/hrnet_demo.jpg
```
......
......@@ -16,11 +16,11 @@ import sys
import os.path as osp
import logging
# add python path of PadleDetection to sys.path
parent_path = osp.abspath(osp.join(__file__, *(['..'] * 3)))
parent_path = osp.abspath(osp.join(__file__, *(['..'] * 2)))
if parent_path not in sys.path:
sys.path.append(parent_path)
from ppdet.utils.download import download_dataset
from lib.utils.download import download_dataset
logging.basicConfig(level=logging.INFO)
......
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import sys
# add python path of PadleDetection to sys.path
parent_path = os.path.abspath(os.path.join(__file__, *(['..'] * 2)))
sys.path.insert(0, parent_path)
# ignore warning log
import warnings
warnings.filterwarnings('ignore')
import glob
import paddle
from lib.utils.workspace import load_config, merge_config
from lib.slim import build_slim_model
from lib.core.trainer import Trainer
from lib.utils.check import check_gpu, check_version, check_config
from lib.utils.cli import ArgsParser
from lib.utils.logger import setup_logger
logger = setup_logger('eval')
def parse_args():
parser = ArgsParser()
parser.add_argument(
"--save-inference-dir",
default='output_inference',
type=str,
help="Evaluation directory, default is current directory.")
args = parser.parse_args()
return args
def main():
FLAGS = parse_args()
cfg = load_config(FLAGS.config)
# cfg['output_eval'] = FLAGS.output_eval
merge_config(FLAGS.opt)
if cfg.use_gpu:
paddle.set_device('gpu')
else:
paddle.set_device('cpu')
if 'slim' in cfg:
cfg = build_slim_model(cfg, mode='test')
check_config(cfg)
check_gpu(cfg.use_gpu)
check_version()
# build trainer
trainer = Trainer(cfg, mode='test')
# load weights
trainer.load_weights(cfg.weights)
# export model
trainer.export(output_dir=FLAGS.save_inference_dir)
if __name__ == '__main__':
main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册