From 60e1ff60e8ef2d96727d04dd4994b4eaf378f8bb Mon Sep 17 00:00:00 2001 From: Bin Lu Date: Wed, 25 May 2022 14:50:51 +0800 Subject: [PATCH] remove gpu infer (#5530) * remove gpu inference --- .../train_fleet_infer_python.txt | 2 +- tutorials/mobilenetv3_prod/Step6/train.py | 35 ++++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/tutorials/mobilenetv3_prod/Step6/test_tipc/configs/mobilenet_v3_small/train_fleet_infer_python.txt b/tutorials/mobilenetv3_prod/Step6/test_tipc/configs/mobilenet_v3_small/train_fleet_infer_python.txt index 6f9cbc23..5305df44 100644 --- a/tutorials/mobilenetv3_prod/Step6/test_tipc/configs/mobilenet_v3_small/train_fleet_infer_python.txt +++ b/tutorials/mobilenetv3_prod/Step6/test_tipc/configs/mobilenet_v3_small/train_fleet_infer_python.txt @@ -25,7 +25,7 @@ train_model:./pretrain_models/mobilenet_v3_small_pretrained.pdparams infer_export:tools/export_model.py --model=mobilenet_v3_small ## inference:deploy/inference_python/infer.py ---use-gpu:True|False +--use-gpu:False --batch-size:1 --model-dir:./output/mobilenet_v3_small_infer/ --img-path:./images/demo.jpg diff --git a/tutorials/mobilenetv3_prod/Step6/train.py b/tutorials/mobilenetv3_prod/Step6/train.py index 94f0a6c4..402765ab 100644 --- a/tutorials/mobilenetv3_prod/Step6/train.py +++ b/tutorials/mobilenetv3_prod/Step6/train.py @@ -281,25 +281,26 @@ def main(args): train_one_epoch(model, criterion, optimizer, data_loader, epoch, args.print_freq, args.amp_level, scaler) lr_scheduler.step() - top1 = evaluate( - model, criterion, data_loader_test, amp_level=args.amp_level) - if args.output_dir: - paddle.save(model.state_dict(), - os.path.join(args.output_dir, - 'model_{}.pdparams'.format(epoch))) - paddle.save(optimizer.state_dict(), - os.path.join(args.output_dir, - 'model_{}.pdopt'.format(epoch))) - paddle.save(model.state_dict(), - os.path.join(args.output_dir, 'latest.pdparams')) - paddle.save(optimizer.state_dict(), - os.path.join(args.output_dir, 'latest.pdopt')) - if top1 > best_top1: - best_top1 = top1 + if paddle.distributed.get_rank() == 0: + top1 = evaluate( + model, criterion, data_loader_test, amp_level=args.amp_level) + if args.output_dir: + paddle.save(model.state_dict(), + os.path.join(args.output_dir, + 'model_{}.pdparams'.format(epoch))) + paddle.save(optimizer.state_dict(), + os.path.join(args.output_dir, + 'model_{}.pdopt'.format(epoch))) paddle.save(model.state_dict(), - os.path.join(args.output_dir, 'best.pdparams')) + os.path.join(args.output_dir, 'latest.pdparams')) paddle.save(optimizer.state_dict(), - os.path.join(args.output_dir, 'best.pdopt')) + os.path.join(args.output_dir, 'latest.pdopt')) + if top1 > best_top1: + best_top1 = top1 + paddle.save(model.state_dict(), + os.path.join(args.output_dir, 'best.pdparams')) + paddle.save(optimizer.state_dict(), + os.path.join(args.output_dir, 'best.pdopt')) if args.pact_quant: input_spec = [InputSpec(shape=[None, 3, 224, 224], dtype='float32')] -- GitLab