From aa3266b192bb3c86ab672a2f29611eb3b41225ff Mon Sep 17 00:00:00 2001 From: yukavio Date: Wed, 4 Nov 2020 10:34:12 +0000 Subject: [PATCH] update for enable static --- deploy/slim/prune/export_prune_model.py | 7 +++++++ deploy/slim/prune/pruning_and_finetune.py | 7 ++++++- deploy/slim/prune/sensitivity_anal.py | 7 +++++++ deploy/slim/quantization/export_model.py | 7 ++++++- deploy/slim/quantization/quant.py | 7 ++++++- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/deploy/slim/prune/export_prune_model.py b/deploy/slim/prune/export_prune_model.py index 0603966f..2ffcf1d8 100644 --- a/deploy/slim/prune/export_prune_model.py +++ b/deploy/slim/prune/export_prune_model.py @@ -24,6 +24,7 @@ sys.path.append(os.path.join(__dir__, '..', '..', '..')) sys.path.append(os.path.join(__dir__, '..', '..', '..', 'tools')) import program +import paddle from paddle import fluid from ppocr.utils.utility import initial_logger logger = initial_logger() @@ -32,6 +33,12 @@ from paddleslim.prune import load_model def main(): + # Run code with static graph mode. + try: + paddle.enable_static() + except: + pass + startup_prog, eval_program, place, config, _ = program.preprocess() feeded_var_names, target_vars, fetches_var_name = program.build_export( diff --git a/deploy/slim/prune/pruning_and_finetune.py b/deploy/slim/prune/pruning_and_finetune.py index 24a115b7..b066b736 100644 --- a/deploy/slim/prune/pruning_and_finetune.py +++ b/deploy/slim/prune/pruning_and_finetune.py @@ -50,7 +50,12 @@ skip_list = [ def main(): - paddle.enable_static() + # Run code with static graph mode. + try: + paddle.enable_static() + except: + pass + config = program.load_config(FLAGS.config) program.merge_config(FLAGS.opt) logger.info(config) diff --git a/deploy/slim/prune/sensitivity_anal.py b/deploy/slim/prune/sensitivity_anal.py index b416f09a..1eebd614 100644 --- a/deploy/slim/prune/sensitivity_anal.py +++ b/deploy/slim/prune/sensitivity_anal.py @@ -25,6 +25,7 @@ sys.path.append(os.path.join(__dir__, '..', '..', '..', 'tools')) import json import cv2 +import paddle from paddle import fluid import paddleslim as slim from copy import deepcopy @@ -60,6 +61,12 @@ def eval_function(eval_args, mode='eval'): def main(): + # Run code with static graph mode. + try: + paddle.enable_static() + except: + pass + config = program.load_config(FLAGS.config) program.merge_config(FLAGS.opt) logger.info(config) diff --git a/deploy/slim/quantization/export_model.py b/deploy/slim/quantization/export_model.py index 959c490d..9741f2a2 100644 --- a/deploy/slim/quantization/export_model.py +++ b/deploy/slim/quantization/export_model.py @@ -77,7 +77,12 @@ def main(): # The decay coefficient of moving average, default is 0.9 'moving_rate': 0.9, } - paddle.enable_static() + # Run code with static graph mode. + try: + paddle.enable_static() + except: + pass + startup_prog, eval_program, place, config, alg_type = program.preprocess() feeded_var_names, target_vars, fetches_var_name = program.build_export( diff --git a/deploy/slim/quantization/quant.py b/deploy/slim/quantization/quant.py index 22e22a86..1af76f1e 100755 --- a/deploy/slim/quantization/quant.py +++ b/deploy/slim/quantization/quant.py @@ -85,7 +85,12 @@ def get_optimizer(): def main(): - paddle.enable_static() + # Run code with static graph mode. + try: + paddle.enable_static() + except: + pass + train_build_outputs = program.build( config, train_program, startup_program, mode='train') train_loader = train_build_outputs[0]