diff --git a/deploy/slim/prune/README.md b/deploy/slim/prune/README.md index 20d8c1e928cbc20c4bd891656e39f9d2bee0dc68..9dc53f2cc6bb65925247f7ddc5887b54c5f7e0e5 100644 --- a/deploy/slim/prune/README.md +++ b/deploy/slim/prune/README.md @@ -30,7 +30,7 @@ python setup.py install ``` ### 2. 获取预训练模型 -模型裁剪需要加载事先训练好的模型,PaddleOCR也提供了一系列模型[../../../doc/doc_ch/models_list.md],开发者可根据需要自行选择模型或使用自己的模型。 +模型裁剪需要加载事先训练好的模型,PaddleOCR也提供了一系列(模型)[../../../doc/doc_ch/models_list.md],开发者可根据需要自行选择模型或使用自己的模型。 ### 3. 敏感度分析训练 diff --git a/deploy/slim/prune/export_prune_model.py b/deploy/slim/prune/export_prune_model.py index 0603966f8eeb9a59fa8c4494bf47de9cdaf53774..2ffcf1d8fa5a8847a720fde3e500d03c8117314d 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 77ba604ad40a6f219a16d63fbdae6cd8946bdec2..b066b73682f649c58104a93eb46f99a4d610ad2d 100644 --- a/deploy/slim/prune/pruning_and_finetune.py +++ b/deploy/slim/prune/pruning_and_finetune.py @@ -19,6 +19,7 @@ from __future__ import print_function import os import sys import numpy as np +import paddle __dir__ = os.path.dirname(__file__) sys.path.append(__dir__) sys.path.append(os.path.join(__dir__, '..', '..', '..')) @@ -49,6 +50,12 @@ skip_list = [ 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/prune/sensitivity_anal.py b/deploy/slim/prune/sensitivity_anal.py index b416f09a3a17527eccbd131917ca257b39bc7884..1eebd61408a0890957e2fdf9761eb938fb53d476 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 5f4d91a8eea2d4f63334be571620aa0e1c00fabd..9741f2a2a9a5e42b8c757efbc5b095586f4eb55c 100644 --- a/deploy/slim/quantization/export_model.py +++ b/deploy/slim/quantization/export_model.py @@ -39,6 +39,7 @@ set_paddle_flags( ) import program +import paddle from paddle import fluid from ppocr.utils.utility import initial_logger logger = initial_logger() @@ -76,6 +77,11 @@ def main(): # The decay coefficient of moving average, default is 0.9 'moving_rate': 0.9, } + # Run code with static graph mode. + try: + paddle.enable_static() + except: + pass startup_prog, eval_program, place, config, alg_type = program.preprocess() diff --git a/deploy/slim/quantization/quant.py b/deploy/slim/quantization/quant.py index e75e84be86867274368b6a0427b3d02d2524e020..1af76f1ed8a154f389265294656e8deaa941b052 100755 --- a/deploy/slim/quantization/quant.py +++ b/deploy/slim/quantization/quant.py @@ -85,6 +85,12 @@ def get_optimizer(): def main(): + # 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]