We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
检测模型转inference模型，'use_gpu': False，但仍然转换失败
你好，在检测模型转inference模型时，已修改det_mv3_db.yml 中'use_gpu': False，但仍然报错，如下所示：
python tools/export_model.py -c configs/det/det_mv3_db.yml -o Global.checkpoints=./ch_lite/det_mv3_db/best_accuracy Global.save_inference_dir=./inference_model/det_db/
2020-05-19 10:29:59,237-INFO: {'Global': {'algorithm': 'DB', 'use_gpu': False, 'epoch_num': 1200, 'log_smooth_window': 20, 'print_batch_step': 2, 'save_model_dir': './output/det_db/', 'save_epoch_step': 200, 'eval_batch_step': 5000, 'train_batch_size_per_card': 16, 'test_batch_size_per_card': 16, 'image_shape': [3, 640, 640], 'reader_yml': './configs/det/det_db_icdar15_reader.yml', 'pretrain_weights': './pretrain_models/MobileNetV3_large_x0_5_pretrained/', 'checkpoints': './ch_lite/det_mv3_db/best_accuracy', 'save_res_path': './output/det_db/predicts_db.txt', 'save_inference_dir': './inference_model/det_db/'}, 'Architecture': {'function': 'ppocr.modeling.architectures.det_model,DetModel'}, 'Backbone': {'function': 'ppocr.modeling.backbones.det_mobilenet_v3,MobileNetV3', 'scale': 0.5, 'model_name': 'large'}, 'Head': {'function': 'ppocr.modeling.heads.det_db_head,DBHead', 'model_name': 'large', 'k': 50, 'inner_channels': 96, 'out_channels': 2}, 'Loss': {'function': 'ppocr.modeling.losses.det_db_loss,DBLoss', 'balance_loss': True, 'main_loss_type': 'DiceLoss', 'alpha': 5, 'beta': 10, 'ohem_ratio': 3}, 'Optimizer': {'function': 'ppocr.optimizer,AdamDecay', 'base_lr': 0.001, 'beta1': 0.9, 'beta2': 0.999}, 'PostProcess': {'function': 'ppocr.postprocess.db_postprocess,DBPostProcess', 'thresh': 0.3, 'box_thresh': 0.7, 'max_candidates': 1000, 'unclip_ratio': 1.5}, 'TrainReader': {'reader_function': 'ppocr.data.det.dataset_traversal,TrainReader', 'process_function': 'ppocr.data.det.db_process,DBProcessTrain', 'num_workers': 8, 'img_set_dir': './train_data/icdar2015/text_localization/', 'label_file_path': './train_data/icdar2015/text_localization/train_icdar2015_label.txt'}, 'EvalReader': {'reader_function': 'ppocr.data.det.dataset_traversal,EvalTestReader', 'process_function': 'ppocr.data.det.db_process,DBProcessTest', 'img_set_dir': './train_data/icdar2015/text_localization/', 'label_file_path': './train_data/icdar2015/text_localization/test_icdar2015_label.txt', 'test_image_shape': [736, 1280]}, 'TestReader': {'reader_function': 'ppocr.data.det.dataset_traversal,EvalTestReader', 'process_function': 'ppocr.data.det.db_process,DBProcessTest', 'single_img_path': None, 'img_set_dir': './train_data/icdar2015/text_localization/', 'label_file_path': './train_data/icdar2015/text_localization/test_icdar2015_label.txt', 'test_image_shape': [736, 1280], 'do_eval': True}}
2020-05-19 10:29:59,238-ERROR: Config use_gpu cannot be set as true while you are using paddlepaddle cpu version !
Please try:
        1. Install paddlepaddle-gpu to run model on GPU
        2. Set use_gpu as false in config file to run model on CPU

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `tools/export_model.py`
Content:
```
1 # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 from __future__ import absolute_import
16 from __future__ import division
17 from __future__ import print_function
18 
19 import os
20 import sys
21 import time
22 import multiprocessing
23 import numpy as np
24 
25 
26 def set_paddle_flags(**kwargs):
27     for key, value in kwargs.items():
28         if os.environ.get(key, None) is None:
29             os.environ[key] = str(value)
30 
31 
32 # NOTE(paddle-dev): All of these flags should be
33 # set before `import paddle`. Otherwise, it would
34 # not take any effect. 
35 set_paddle_flags(
36     FLAGS_eager_delete_tensor_gb=0,  # enable GC to save memory
37 )
38 
39 import program
40 from paddle import fluid
41 from ppocr.utils.utility import initial_logger
42 logger = initial_logger()
43 from ppocr.utils.save_load import init_model
44 from ppocr.utils.character import CharacterOps
45 from ppocr.utils.utility import create_module
46 
47 
48 def main():
49     config = program.load_config(FLAGS.config)
50     program.merge_config(FLAGS.opt)
51     logger.info(config)
52 
53     # check if set use_gpu=True in paddlepaddle cpu version
54     use_gpu = config['Global']['use_gpu']
55     program.check_gpu(True)
56 
57     alg = config['Global']['algorithm']
58     assert alg in ['EAST', 'DB', 'Rosetta', 'CRNN', 'STARNet', 'RARE']
59     if alg in ['Rosetta', 'CRNN', 'STARNet', 'RARE']:
60         config['Global']['char_ops'] = CharacterOps(config['Global'])
61 
62     place = fluid.CUDAPlace(0) if use_gpu else fluid.CPUPlace()
63     startup_prog = fluid.Program()
64     eval_program = fluid.Program()
65 
66     feeded_var_names, target_vars, fetches_var_name = program.build_export(
67         config, eval_program, startup_prog)
68     eval_program = eval_program.clone(for_test=True)
69     exe = fluid.Executor(place)
70     exe.run(startup_prog)
71 
72     init_model(config, eval_program, exe)
73 
74     save_inference_dir = config['Global']['save_inference_dir']
75     if not os.path.exists(save_inference_dir):
76         os.makedirs(save_inference_dir)
77     fluid.io.save_inference_model(
78         dirname=save_inference_dir,
79         feeded_var_names=feeded_var_names,
80         main_program=eval_program,
81         target_vars=target_vars,
82         executor=exe,
83         model_filename='model',
84         params_filename='params')
85     print("inference model saved in {}/model and {}/params".format(
86         save_inference_dir, save_inference_dir))
87     print("save success, output_name_list:", fetches_var_name)
88 
89 
90 if __name__ == '__main__':
91     parser = program.ArgsParser()
92     FLAGS = parser.parse_args()
93     main()
94
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/tools/export_model.py b/tools/export_model.py
--- a/tools/export_model.py
+++ b/tools/export_model.py
@@ -31,7 +31,7 @@
 
 # NOTE(paddle-dev): All of these flags should be
 # set before `import paddle`. Otherwise, it would
-# not take any effect. 
+# not take any effect.
 set_paddle_flags(
     FLAGS_eager_delete_tensor_gb=0,  # enable GC to save memory
 )
@@ -52,7 +52,7 @@
 
     # check if set use_gpu=True in paddlepaddle cpu version
     use_gpu = config['Global']['use_gpu']
-    program.check_gpu(True)
+    program.check_gpu(use_gpu)
 
     alg = config['Global']['algorithm']
     assert alg in ['EAST', 'DB', 'Rosetta', 'CRNN', 'STARNet', 'RARE']

{"golden_diff": "diff --git a/tools/export_model.py b/tools/export_model.py\n--- a/tools/export_model.py\n+++ b/tools/export_model.py\n@@ -31,7 +31,7 @@\n \n # NOTE(paddle-dev): All of these flags should be\n # set before `import paddle`. Otherwise, it would\n-# not take any effect. \n+# not take any effect.\n set_paddle_flags(\n     FLAGS_eager_delete_tensor_gb=0,  # enable GC to save memory\n )\n@@ -52,7 +52,7 @@\n \n     # check if set use_gpu=True in paddlepaddle cpu version\n     use_gpu = config['Global']['use_gpu']\n-    program.check_gpu(True)\n+    program.check_gpu(use_gpu)\n \n     alg = config['Global']['algorithm']\n     assert alg in ['EAST', 'DB', 'Rosetta', 'CRNN', 'STARNet', 'RARE']\n", "issue": "\u68c0\u6d4b\u6a21\u578b\u8f6cinference\u6a21\u578b\uff0c'use_gpu': False\uff0c\u4f46\u4ecd\u7136\u8f6c\u6362\u5931\u8d25\n\u4f60\u597d\uff0c\u5728\u68c0\u6d4b\u6a21\u578b\u8f6cinference\u6a21\u578b\u65f6\uff0c\u5df2\u4fee\u6539det_mv3_db.yml \u4e2d'use_gpu': False\uff0c\u4f46\u4ecd\u7136\u62a5\u9519\uff0c\u5982\u4e0b\u6240\u793a\uff1a\r\npython tools/export_model.py -c configs/det/det_mv3_db.yml -o Global.checkpoints=./ch_lite/det_mv3_db/best_accuracy Global.save_inference_dir=./inference_model/det_db/\r\n2020-05-19 10:29:59,237-INFO: {'Global': {'algorithm': 'DB', 'use_gpu': False, 'epoch_num': 1200, 'log_smooth_window': 20, 'print_batch_step': 2, 'save_model_dir': './output/det_db/', 'save_epoch_step': 200, 'eval_batch_step': 5000, 'train_batch_size_per_card': 16, 'test_batch_size_per_card': 16, 'image_shape': [3, 640, 640], 'reader_yml': './configs/det/det_db_icdar15_reader.yml', 'pretrain_weights': './pretrain_models/MobileNetV3_large_x0_5_pretrained/', 'checkpoints': './ch_lite/det_mv3_db/best_accuracy', 'save_res_path': './output/det_db/predicts_db.txt', 'save_inference_dir': './inference_model/det_db/'}, 'Architecture': {'function': 'ppocr.modeling.architectures.det_model,DetModel'}, 'Backbone': {'function': 'ppocr.modeling.backbones.det_mobilenet_v3,MobileNetV3', 'scale': 0.5, 'model_name': 'large'}, 'Head': {'function': 'ppocr.modeling.heads.det_db_head,DBHead', 'model_name': 'large', 'k': 50, 'inner_channels': 96, 'out_channels': 2}, 'Loss': {'function': 'ppocr.modeling.losses.det_db_loss,DBLoss', 'balance_loss': True, 'main_loss_type': 'DiceLoss', 'alpha': 5, 'beta': 10, 'ohem_ratio': 3}, 'Optimizer': {'function': 'ppocr.optimizer,AdamDecay', 'base_lr': 0.001, 'beta1': 0.9, 'beta2': 0.999}, 'PostProcess': {'function': 'ppocr.postprocess.db_postprocess,DBPostProcess', 'thresh': 0.3, 'box_thresh': 0.7, 'max_candidates': 1000, 'unclip_ratio': 1.5}, 'TrainReader': {'reader_function': 'ppocr.data.det.dataset_traversal,TrainReader', 'process_function': 'ppocr.data.det.db_process,DBProcessTrain', 'num_workers': 8, 'img_set_dir': './train_data/icdar2015/text_localization/', 'label_file_path': './train_data/icdar2015/text_localization/train_icdar2015_label.txt'}, 'EvalReader': {'reader_function': 'ppocr.data.det.dataset_traversal,EvalTestReader', 'process_function': 'ppocr.data.det.db_process,DBProcessTest', 'img_set_dir': './train_data/icdar2015/text_localization/', 'label_file_path': './train_data/icdar2015/text_localization/test_icdar2015_label.txt', 'test_image_shape': [736, 1280]}, 'TestReader': {'reader_function': 'ppocr.data.det.dataset_traversal,EvalTestReader', 'process_function': 'ppocr.data.det.db_process,DBProcessTest', 'single_img_path': None, 'img_set_dir': './train_data/icdar2015/text_localization/', 'label_file_path': './train_data/icdar2015/text_localization/test_icdar2015_label.txt', 'test_image_shape': [736, 1280], 'do_eval': True}}\r\n2020-05-19 10:29:59,238-ERROR: Config use_gpu cannot be set as true while you are using paddlepaddle cpu version !\r\nPlease try:\r\n        1. Install paddlepaddle-gpu to run model on GPU\r\n        2. Set use_gpu as false in config file to run model on CPU\n", "before_files": [{"content": "# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport os\nimport sys\nimport time\nimport multiprocessing\nimport numpy as np\n\n\ndef set_paddle_flags(**kwargs):\n    for key, value in kwargs.items():\n        if os.environ.get(key, None) is None:\n            os.environ[key] = str(value)\n\n\n# NOTE(paddle-dev): All of these flags should be\n# set before `import paddle`. Otherwise, it would\n# not take any effect. \nset_paddle_flags(\n    FLAGS_eager_delete_tensor_gb=0,  # enable GC to save memory\n)\n\nimport program\nfrom paddle import fluid\nfrom ppocr.utils.utility import initial_logger\nlogger = initial_logger()\nfrom ppocr.utils.save_load import init_model\nfrom ppocr.utils.character import CharacterOps\nfrom ppocr.utils.utility import create_module\n\n\ndef main():\n    config = program.load_config(FLAGS.config)\n    program.merge_config(FLAGS.opt)\n    logger.info(config)\n\n    # check if set use_gpu=True in paddlepaddle cpu version\n    use_gpu = config['Global']['use_gpu']\n    program.check_gpu(True)\n\n    alg = config['Global']['algorithm']\n    assert alg in ['EAST', 'DB', 'Rosetta', 'CRNN', 'STARNet', 'RARE']\n    if alg in ['Rosetta', 'CRNN', 'STARNet', 'RARE']:\n        config['Global']['char_ops'] = CharacterOps(config['Global'])\n\n    place = fluid.CUDAPlace(0) if use_gpu else fluid.CPUPlace()\n    startup_prog = fluid.Program()\n    eval_program = fluid.Program()\n\n    feeded_var_names, target_vars, fetches_var_name = program.build_export(\n        config, eval_program, startup_prog)\n    eval_program = eval_program.clone(for_test=True)\n    exe = fluid.Executor(place)\n    exe.run(startup_prog)\n\n    init_model(config, eval_program, exe)\n\n    save_inference_dir = config['Global']['save_inference_dir']\n    if not os.path.exists(save_inference_dir):\n        os.makedirs(save_inference_dir)\n    fluid.io.save_inference_model(\n        dirname=save_inference_dir,\n        feeded_var_names=feeded_var_names,\n        main_program=eval_program,\n        target_vars=target_vars,\n        executor=exe,\n        model_filename='model',\n        params_filename='params')\n    print(\"inference model saved in {}/model and {}/params\".format(\n        save_inference_dir, save_inference_dir))\n    print(\"save success, output_name_list:\", fetches_var_name)\n\n\nif __name__ == '__main__':\n    parser = program.ArgsParser()\n    FLAGS = parser.parse_args()\n    main()\n", "path": "tools/export_model.py"}], "after_files": [{"content": "# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport os\nimport sys\nimport time\nimport multiprocessing\nimport numpy as np\n\n\ndef set_paddle_flags(**kwargs):\n    for key, value in kwargs.items():\n        if os.environ.get(key, None) is None:\n            os.environ[key] = str(value)\n\n\n# NOTE(paddle-dev): All of these flags should be\n# set before `import paddle`. Otherwise, it would\n# not take any effect.\nset_paddle_flags(\n    FLAGS_eager_delete_tensor_gb=0,  # enable GC to save memory\n)\n\nimport program\nfrom paddle import fluid\nfrom ppocr.utils.utility import initial_logger\nlogger = initial_logger()\nfrom ppocr.utils.save_load import init_model\nfrom ppocr.utils.character import CharacterOps\nfrom ppocr.utils.utility import create_module\n\n\ndef main():\n    config = program.load_config(FLAGS.config)\n    program.merge_config(FLAGS.opt)\n    logger.info(config)\n\n    # check if set use_gpu=True in paddlepaddle cpu version\n    use_gpu = config['Global']['use_gpu']\n    program.check_gpu(use_gpu)\n\n    alg = config['Global']['algorithm']\n    assert alg in ['EAST', 'DB', 'Rosetta', 'CRNN', 'STARNet', 'RARE']\n    if alg in ['Rosetta', 'CRNN', 'STARNet', 'RARE']:\n        config['Global']['char_ops'] = CharacterOps(config['Global'])\n\n    place = fluid.CUDAPlace(0) if use_gpu else fluid.CPUPlace()\n    startup_prog = fluid.Program()\n    eval_program = fluid.Program()\n\n    feeded_var_names, target_vars, fetches_var_name = program.build_export(\n        config, eval_program, startup_prog)\n    eval_program = eval_program.clone(for_test=True)\n    exe = fluid.Executor(place)\n    exe.run(startup_prog)\n\n    init_model(config, eval_program, exe)\n\n    save_inference_dir = config['Global']['save_inference_dir']\n    if not os.path.exists(save_inference_dir):\n        os.makedirs(save_inference_dir)\n    fluid.io.save_inference_model(\n        dirname=save_inference_dir,\n        feeded_var_names=feeded_var_names,\n        main_program=eval_program,\n        target_vars=target_vars,\n        executor=exe,\n        model_filename='model',\n        params_filename='params')\n    print(\"inference model saved in {}/model and {}/params\".format(\n        save_inference_dir, save_inference_dir))\n    print(\"save success, output_name_list:\", fetches_var_name)\n\n\nif __name__ == '__main__':\n    parser = program.ArgsParser()\n    FLAGS = parser.parse_args()\n    main()\n", "path": "tools/export_model.py"}]}