We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
deeplabv3+在python3.6下报错
deeplabv3+在ubuntu14 cuda8 cudnn7 python3.6下有个报错，报错内容如下：
Traceback (most recent call last):
  File "./train.py", line 148, in <module>
    load_model()
  File "./train.py", line 54, in load_model
    exe, dirname=args.init_weights_path, main_program=tp)
  File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/io.py", line 487, in load_params
    filename=filename)
  File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/io.py", line 395, in load_vars
    filename=filename)
  File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/io.py", line 436, in load_vars
    executor.run(load_prog)
  File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/executor.py", line 472, in run
    self.executor.run(program.desc, scope, 0, True, True)
paddle.fluid.core.EnforceNotMet: Cannot open file deeplabv3plus_xception65_initialize.params/xception_65/entry_flow/conv1/weights for load op at [/home/Paddle/paddle/fluid/operators/load_op.cc:39]


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `fluid/PaddleCV/deeplabv3+/train.py`
Content:
```
1 from __future__ import absolute_import
2 from __future__ import division
3 from __future__ import print_function
4 import os
5 os.environ['FLAGS_fraction_of_gpu_memory_to_use'] = '0.98'
6 
7 import paddle
8 import paddle.fluid as fluid
9 import numpy as np
10 import argparse
11 from reader import CityscapeDataset
12 import reader
13 import models
14 import time
15 
16 
17 def add_argument(name, type, default, help):
18     parser.add_argument('--' + name, default=default, type=type, help=help)
19 
20 
21 def add_arguments():
22     add_argument('batch_size', int, 2,
23                  "The number of images in each batch during training.")
24     add_argument('train_crop_size', int, 769,
25                  "'Image crop size during training.")
26     add_argument('base_lr', float, 0.0001,
27                  "The base learning rate for model training.")
28     add_argument('total_step', int, 90000, "Number of the training step.")
29     add_argument('init_weights_path', str, None,
30                  "Path of the initial weights in paddlepaddle format.")
31     add_argument('save_weights_path', str, None,
32                  "Path of the saved weights during training.")
33     add_argument('dataset_path', str, None, "Cityscape dataset path.")
34     add_argument('parallel', bool, False, "using ParallelExecutor.")
35     add_argument('use_gpu', bool, True, "Whether use GPU or CPU.")
36     add_argument('num_classes', int, 19, "Number of classes.")
37     parser.add_argument('--enable_ce', action='store_true', help='If set, run the task with continuous evaluation logs.')
38 
39 
40 def load_model():
41     myvars = [
42         x for x in tp.list_vars()
43         if isinstance(x, fluid.framework.Parameter) and x.name.find('logit') ==
44         -1
45     ]
46     if args.init_weights_path.endswith('/'):
47         if args.num_classes == 19:
48             fluid.io.load_params(
49                 exe, dirname=args.init_weights_path, main_program=tp)
50         else:
51             fluid.io.load_vars(exe, dirname=args.init_weights_path, vars=myvars)
52     else:
53         if args.num_classes == 19:
54             fluid.io.load_params(
55                 exe, dirname=args.init_weights_path, main_program=tp)
56         else:
57             fluid.io.load_vars(
58                 exe, dirname="", filename=args.init_weights_path, vars=myvars)
59 
60 
61 def save_model():
62     if args.save_weights_path.endswith('/'):
63         fluid.io.save_params(
64             exe, dirname=args.save_weights_path, main_program=tp)
65     else:
66         fluid.io.save_params(
67             exe, dirname="", filename=args.save_weights_path, main_program=tp)
68 
69 
70 def loss(logit, label):
71     label_nignore = (label < num_classes).astype('float32')
72     label = fluid.layers.elementwise_min(
73         label,
74         fluid.layers.assign(np.array(
75             [num_classes - 1], dtype=np.int32)))
76     logit = fluid.layers.transpose(logit, [0, 2, 3, 1])
77     logit = fluid.layers.reshape(logit, [-1, num_classes])
78     label = fluid.layers.reshape(label, [-1, 1])
79     label = fluid.layers.cast(label, 'int64')
80     label_nignore = fluid.layers.reshape(label_nignore, [-1, 1])
81     loss = fluid.layers.softmax_with_cross_entropy(logit, label)
82     loss = loss * label_nignore
83     no_grad_set.add(label_nignore.name)
84     no_grad_set.add(label.name)
85     return loss, label_nignore
86 
87 
88 def get_cards(args):
89     if args.enable_ce:
90         cards = os.environ.get('CUDA_VISIBLE_DEVICES')
91         num = len(cards.split(","))
92         return num
93     else:
94         return args.num_devices
95 
96 CityscapeDataset = reader.CityscapeDataset
97 parser = argparse.ArgumentParser()
98 
99 add_arguments()
100 
101 args = parser.parse_args()
102 
103 models.clean()
104 models.bn_momentum = 0.9997
105 models.dropout_keep_prop = 0.9
106 models.label_number = args.num_classes
107 deeplabv3p = models.deeplabv3p
108 
109 sp = fluid.Program()
110 tp = fluid.Program()
111 
112 # only for ce
113 if args.enable_ce:
114     SEED = 102
115     sp.random_seed = SEED
116     tp.random_seed = SEED
117 
118 crop_size = args.train_crop_size
119 batch_size = args.batch_size
120 image_shape = [crop_size, crop_size]
121 reader.default_config['crop_size'] = crop_size
122 reader.default_config['shuffle'] = True
123 num_classes = args.num_classes
124 weight_decay = 0.00004
125 
126 base_lr = args.base_lr
127 total_step = args.total_step
128 
129 no_grad_set = set()
130 
131 with fluid.program_guard(tp, sp):
132     img = fluid.layers.data(
133         name='img', shape=[3] + image_shape, dtype='float32')
134     label = fluid.layers.data(name='label', shape=image_shape, dtype='int32')
135     logit = deeplabv3p(img)
136     pred = fluid.layers.argmax(logit, axis=1).astype('int32')
137     loss, mask = loss(logit, label)
138     lr = fluid.layers.polynomial_decay(
139         base_lr, total_step, end_learning_rate=0, power=0.9)
140     area = fluid.layers.elementwise_max(
141         fluid.layers.reduce_mean(mask),
142         fluid.layers.assign(np.array(
143             [0.1], dtype=np.float32)))
144     loss_mean = fluid.layers.reduce_mean(loss) / area
145 
146     opt = fluid.optimizer.Momentum(
147         lr,
148         momentum=0.9,
149         regularization=fluid.regularizer.L2DecayRegularizer(
150             regularization_coeff=weight_decay), )
151     retv = opt.minimize(loss_mean, startup_program=sp, no_grad_set=no_grad_set)
152 
153 fluid.memory_optimize(
154     tp, print_log=False, skip_opt_set=set([pred.name, loss_mean.name]), level=1)
155 
156 place = fluid.CPUPlace()
157 if args.use_gpu:
158     place = fluid.CUDAPlace(0)
159 exe = fluid.Executor(place)
160 exe.run(sp)
161 
162 if args.init_weights_path:
163     print("load from:", args.init_weights_path)
164     load_model()
165 
166 dataset = CityscapeDataset(args.dataset_path, 'train')
167 
168 if args.parallel:
169     exe_p = fluid.ParallelExecutor(
170         use_cuda=True, loss_name=loss_mean.name, main_program=tp)
171 
172 batches = dataset.get_batch_generator(batch_size, total_step)
173 
174 total_time = 0.0
175 epoch_idx = 0
176 train_loss = 0
177 
178 for i, imgs, labels, names in batches:
179     epoch_idx += 1
180     begin_time = time.time()
181     prev_start_time = time.time()
182     if args.parallel:
183         retv = exe_p.run(fetch_list=[pred.name, loss_mean.name],
184                          feed={'img': imgs,
185                                'label': labels})
186     else:
187         retv = exe.run(tp,
188                        feed={'img': imgs,
189                              'label': labels},
190                        fetch_list=[pred, loss_mean])
191     end_time = time.time()
192     total_time += end_time - begin_time
193     if i % 100 == 0:
194         print("Model is saved to", args.save_weights_path)
195         save_model()
196     print("step {:d}, loss: {:.6f}, step_time_cost: {:.3f}".format(
197         i, np.mean(retv[1]), end_time - prev_start_time))
198 
199     # only for ce
200     train_loss = np.mean(retv[1])
201 
202 if args.enable_ce:
203     gpu_num = get_cards(args)
204     print("kpis\teach_pass_duration_card%s\t%s" %
205             (gpu_num, total_time / epoch_idx))
206     print("kpis\ttrain_loss_card%s\t%s" %
207             (gpu_num, train_loss))
208 
209 print("Training done. Model is saved to", args.save_weights_path)
210 save_model()
211
```
--- 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/fluid/PaddleCV/deeplabv3+/train.py b/fluid/PaddleCV/deeplabv3+/train.py
--- a/fluid/PaddleCV/deeplabv3+/train.py
+++ b/fluid/PaddleCV/deeplabv3+/train.py
@@ -34,7 +34,10 @@
     add_argument('parallel', bool, False, "using ParallelExecutor.")
     add_argument('use_gpu', bool, True, "Whether use GPU or CPU.")
     add_argument('num_classes', int, 19, "Number of classes.")
-    parser.add_argument('--enable_ce', action='store_true', help='If set, run the task with continuous evaluation logs.')
+    parser.add_argument(
+        '--enable_ce',
+        action='store_true',
+        help='If set, run the task with continuous evaluation logs.')
 
 
 def load_model():
@@ -52,7 +55,10 @@
     else:
         if args.num_classes == 19:
             fluid.io.load_params(
-                exe, dirname=args.init_weights_path, main_program=tp)
+                exe,
+                dirname="",
+                filename=args.init_weights_path,
+                main_program=tp)
         else:
             fluid.io.load_vars(
                 exe, dirname="", filename=args.init_weights_path, vars=myvars)
@@ -93,6 +99,7 @@
     else:
         return args.num_devices
 
+
 CityscapeDataset = reader.CityscapeDataset
 parser = argparse.ArgumentParser()
 
@@ -202,9 +209,8 @@
 if args.enable_ce:
     gpu_num = get_cards(args)
     print("kpis\teach_pass_duration_card%s\t%s" %
-            (gpu_num, total_time / epoch_idx))
-    print("kpis\ttrain_loss_card%s\t%s" %
-            (gpu_num, train_loss))
+          (gpu_num, total_time / epoch_idx))
+    print("kpis\ttrain_loss_card%s\t%s" % (gpu_num, train_loss))
 
 print("Training done. Model is saved to", args.save_weights_path)
 save_model()

{"golden_diff": "diff --git a/fluid/PaddleCV/deeplabv3+/train.py b/fluid/PaddleCV/deeplabv3+/train.py\n--- a/fluid/PaddleCV/deeplabv3+/train.py\n+++ b/fluid/PaddleCV/deeplabv3+/train.py\n@@ -34,7 +34,10 @@\n     add_argument('parallel', bool, False, \"using ParallelExecutor.\")\n     add_argument('use_gpu', bool, True, \"Whether use GPU or CPU.\")\n     add_argument('num_classes', int, 19, \"Number of classes.\")\n-    parser.add_argument('--enable_ce', action='store_true', help='If set, run the task with continuous evaluation logs.')\n+    parser.add_argument(\n+        '--enable_ce',\n+        action='store_true',\n+        help='If set, run the task with continuous evaluation logs.')\n \n \n def load_model():\n@@ -52,7 +55,10 @@\n     else:\n         if args.num_classes == 19:\n             fluid.io.load_params(\n-                exe, dirname=args.init_weights_path, main_program=tp)\n+                exe,\n+                dirname=\"\",\n+                filename=args.init_weights_path,\n+                main_program=tp)\n         else:\n             fluid.io.load_vars(\n                 exe, dirname=\"\", filename=args.init_weights_path, vars=myvars)\n@@ -93,6 +99,7 @@\n     else:\n         return args.num_devices\n \n+\n CityscapeDataset = reader.CityscapeDataset\n parser = argparse.ArgumentParser()\n \n@@ -202,9 +209,8 @@\n if args.enable_ce:\n     gpu_num = get_cards(args)\n     print(\"kpis\\teach_pass_duration_card%s\\t%s\" %\n-            (gpu_num, total_time / epoch_idx))\n-    print(\"kpis\\ttrain_loss_card%s\\t%s\" %\n-            (gpu_num, train_loss))\n+          (gpu_num, total_time / epoch_idx))\n+    print(\"kpis\\ttrain_loss_card%s\\t%s\" % (gpu_num, train_loss))\n \n print(\"Training done. Model is saved to\", args.save_weights_path)\n save_model()\n", "issue": "deeplabv3+\u5728python3.6\u4e0b\u62a5\u9519\ndeeplabv3+\u5728ubuntu14 cuda8 cudnn7 python3.6\u4e0b\u6709\u4e2a\u62a5\u9519\uff0c\u62a5\u9519\u5185\u5bb9\u5982\u4e0b\uff1a\r\nTraceback (most recent call last):\r\n  File \"./train.py\", line 148, in <module>\r\n    load_model()\r\n  File \"./train.py\", line 54, in load_model\r\n    exe, dirname=args.init_weights_path, main_program=tp)\r\n  File \"/usr/local/lib/python3.6/dist-packages/paddle/fluid/io.py\", line 487, in load_params\r\n    filename=filename)\r\n  File \"/usr/local/lib/python3.6/dist-packages/paddle/fluid/io.py\", line 395, in load_vars\r\n    filename=filename)\r\n  File \"/usr/local/lib/python3.6/dist-packages/paddle/fluid/io.py\", line 436, in load_vars\r\n    executor.run(load_prog)\r\n  File \"/usr/local/lib/python3.6/dist-packages/paddle/fluid/executor.py\", line 472, in run\r\n    self.executor.run(program.desc, scope, 0, True, True)\r\npaddle.fluid.core.EnforceNotMet: Cannot open file deeplabv3plus_xception65_initialize.params/xception_65/entry_flow/conv1/weights for load op at [/home/Paddle/paddle/fluid/operators/load_op.cc:39]\r\n\n", "before_files": [{"content": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nimport os\nos.environ['FLAGS_fraction_of_gpu_memory_to_use'] = '0.98'\n\nimport paddle\nimport paddle.fluid as fluid\nimport numpy as np\nimport argparse\nfrom reader import CityscapeDataset\nimport reader\nimport models\nimport time\n\n\ndef add_argument(name, type, default, help):\n    parser.add_argument('--' + name, default=default, type=type, help=help)\n\n\ndef add_arguments():\n    add_argument('batch_size', int, 2,\n                 \"The number of images in each batch during training.\")\n    add_argument('train_crop_size', int, 769,\n                 \"'Image crop size during training.\")\n    add_argument('base_lr', float, 0.0001,\n                 \"The base learning rate for model training.\")\n    add_argument('total_step', int, 90000, \"Number of the training step.\")\n    add_argument('init_weights_path', str, None,\n                 \"Path of the initial weights in paddlepaddle format.\")\n    add_argument('save_weights_path', str, None,\n                 \"Path of the saved weights during training.\")\n    add_argument('dataset_path', str, None, \"Cityscape dataset path.\")\n    add_argument('parallel', bool, False, \"using ParallelExecutor.\")\n    add_argument('use_gpu', bool, True, \"Whether use GPU or CPU.\")\n    add_argument('num_classes', int, 19, \"Number of classes.\")\n    parser.add_argument('--enable_ce', action='store_true', help='If set, run the task with continuous evaluation logs.')\n\n\ndef load_model():\n    myvars = [\n        x for x in tp.list_vars()\n        if isinstance(x, fluid.framework.Parameter) and x.name.find('logit') ==\n        -1\n    ]\n    if args.init_weights_path.endswith('/'):\n        if args.num_classes == 19:\n            fluid.io.load_params(\n                exe, dirname=args.init_weights_path, main_program=tp)\n        else:\n            fluid.io.load_vars(exe, dirname=args.init_weights_path, vars=myvars)\n    else:\n        if args.num_classes == 19:\n            fluid.io.load_params(\n                exe, dirname=args.init_weights_path, main_program=tp)\n        else:\n            fluid.io.load_vars(\n                exe, dirname=\"\", filename=args.init_weights_path, vars=myvars)\n\n\ndef save_model():\n    if args.save_weights_path.endswith('/'):\n        fluid.io.save_params(\n            exe, dirname=args.save_weights_path, main_program=tp)\n    else:\n        fluid.io.save_params(\n            exe, dirname=\"\", filename=args.save_weights_path, main_program=tp)\n\n\ndef loss(logit, label):\n    label_nignore = (label < num_classes).astype('float32')\n    label = fluid.layers.elementwise_min(\n        label,\n        fluid.layers.assign(np.array(\n            [num_classes - 1], dtype=np.int32)))\n    logit = fluid.layers.transpose(logit, [0, 2, 3, 1])\n    logit = fluid.layers.reshape(logit, [-1, num_classes])\n    label = fluid.layers.reshape(label, [-1, 1])\n    label = fluid.layers.cast(label, 'int64')\n    label_nignore = fluid.layers.reshape(label_nignore, [-1, 1])\n    loss = fluid.layers.softmax_with_cross_entropy(logit, label)\n    loss = loss * label_nignore\n    no_grad_set.add(label_nignore.name)\n    no_grad_set.add(label.name)\n    return loss, label_nignore\n\n\ndef get_cards(args):\n    if args.enable_ce:\n        cards = os.environ.get('CUDA_VISIBLE_DEVICES')\n        num = len(cards.split(\",\"))\n        return num\n    else:\n        return args.num_devices\n\nCityscapeDataset = reader.CityscapeDataset\nparser = argparse.ArgumentParser()\n\nadd_arguments()\n\nargs = parser.parse_args()\n\nmodels.clean()\nmodels.bn_momentum = 0.9997\nmodels.dropout_keep_prop = 0.9\nmodels.label_number = args.num_classes\ndeeplabv3p = models.deeplabv3p\n\nsp = fluid.Program()\ntp = fluid.Program()\n\n# only for ce\nif args.enable_ce:\n    SEED = 102\n    sp.random_seed = SEED\n    tp.random_seed = SEED\n\ncrop_size = args.train_crop_size\nbatch_size = args.batch_size\nimage_shape = [crop_size, crop_size]\nreader.default_config['crop_size'] = crop_size\nreader.default_config['shuffle'] = True\nnum_classes = args.num_classes\nweight_decay = 0.00004\n\nbase_lr = args.base_lr\ntotal_step = args.total_step\n\nno_grad_set = set()\n\nwith fluid.program_guard(tp, sp):\n    img = fluid.layers.data(\n        name='img', shape=[3] + image_shape, dtype='float32')\n    label = fluid.layers.data(name='label', shape=image_shape, dtype='int32')\n    logit = deeplabv3p(img)\n    pred = fluid.layers.argmax(logit, axis=1).astype('int32')\n    loss, mask = loss(logit, label)\n    lr = fluid.layers.polynomial_decay(\n        base_lr, total_step, end_learning_rate=0, power=0.9)\n    area = fluid.layers.elementwise_max(\n        fluid.layers.reduce_mean(mask),\n        fluid.layers.assign(np.array(\n            [0.1], dtype=np.float32)))\n    loss_mean = fluid.layers.reduce_mean(loss) / area\n\n    opt = fluid.optimizer.Momentum(\n        lr,\n        momentum=0.9,\n        regularization=fluid.regularizer.L2DecayRegularizer(\n            regularization_coeff=weight_decay), )\n    retv = opt.minimize(loss_mean, startup_program=sp, no_grad_set=no_grad_set)\n\nfluid.memory_optimize(\n    tp, print_log=False, skip_opt_set=set([pred.name, loss_mean.name]), level=1)\n\nplace = fluid.CPUPlace()\nif args.use_gpu:\n    place = fluid.CUDAPlace(0)\nexe = fluid.Executor(place)\nexe.run(sp)\n\nif args.init_weights_path:\n    print(\"load from:\", args.init_weights_path)\n    load_model()\n\ndataset = CityscapeDataset(args.dataset_path, 'train')\n\nif args.parallel:\n    exe_p = fluid.ParallelExecutor(\n        use_cuda=True, loss_name=loss_mean.name, main_program=tp)\n\nbatches = dataset.get_batch_generator(batch_size, total_step)\n\ntotal_time = 0.0\nepoch_idx = 0\ntrain_loss = 0\n\nfor i, imgs, labels, names in batches:\n    epoch_idx += 1\n    begin_time = time.time()\n    prev_start_time = time.time()\n    if args.parallel:\n        retv = exe_p.run(fetch_list=[pred.name, loss_mean.name],\n                         feed={'img': imgs,\n                               'label': labels})\n    else:\n        retv = exe.run(tp,\n                       feed={'img': imgs,\n                             'label': labels},\n                       fetch_list=[pred, loss_mean])\n    end_time = time.time()\n    total_time += end_time - begin_time\n    if i % 100 == 0:\n        print(\"Model is saved to\", args.save_weights_path)\n        save_model()\n    print(\"step {:d}, loss: {:.6f}, step_time_cost: {:.3f}\".format(\n        i, np.mean(retv[1]), end_time - prev_start_time))\n\n    # only for ce\n    train_loss = np.mean(retv[1])\n\nif args.enable_ce:\n    gpu_num = get_cards(args)\n    print(\"kpis\\teach_pass_duration_card%s\\t%s\" %\n            (gpu_num, total_time / epoch_idx))\n    print(\"kpis\\ttrain_loss_card%s\\t%s\" %\n            (gpu_num, train_loss))\n\nprint(\"Training done. Model is saved to\", args.save_weights_path)\nsave_model()\n", "path": "fluid/PaddleCV/deeplabv3+/train.py"}], "after_files": [{"content": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nimport os\nos.environ['FLAGS_fraction_of_gpu_memory_to_use'] = '0.98'\n\nimport paddle\nimport paddle.fluid as fluid\nimport numpy as np\nimport argparse\nfrom reader import CityscapeDataset\nimport reader\nimport models\nimport time\n\n\ndef add_argument(name, type, default, help):\n    parser.add_argument('--' + name, default=default, type=type, help=help)\n\n\ndef add_arguments():\n    add_argument('batch_size', int, 2,\n                 \"The number of images in each batch during training.\")\n    add_argument('train_crop_size', int, 769,\n                 \"'Image crop size during training.\")\n    add_argument('base_lr', float, 0.0001,\n                 \"The base learning rate for model training.\")\n    add_argument('total_step', int, 90000, \"Number of the training step.\")\n    add_argument('init_weights_path', str, None,\n                 \"Path of the initial weights in paddlepaddle format.\")\n    add_argument('save_weights_path', str, None,\n                 \"Path of the saved weights during training.\")\n    add_argument('dataset_path', str, None, \"Cityscape dataset path.\")\n    add_argument('parallel', bool, False, \"using ParallelExecutor.\")\n    add_argument('use_gpu', bool, True, \"Whether use GPU or CPU.\")\n    add_argument('num_classes', int, 19, \"Number of classes.\")\n    parser.add_argument(\n        '--enable_ce',\n        action='store_true',\n        help='If set, run the task with continuous evaluation logs.')\n\n\ndef load_model():\n    myvars = [\n        x for x in tp.list_vars()\n        if isinstance(x, fluid.framework.Parameter) and x.name.find('logit') ==\n        -1\n    ]\n    if args.init_weights_path.endswith('/'):\n        if args.num_classes == 19:\n            fluid.io.load_params(\n                exe, dirname=args.init_weights_path, main_program=tp)\n        else:\n            fluid.io.load_vars(exe, dirname=args.init_weights_path, vars=myvars)\n    else:\n        if args.num_classes == 19:\n            fluid.io.load_params(\n                exe,\n                dirname=\"\",\n                filename=args.init_weights_path,\n                main_program=tp)\n        else:\n            fluid.io.load_vars(\n                exe, dirname=\"\", filename=args.init_weights_path, vars=myvars)\n\n\ndef save_model():\n    if args.save_weights_path.endswith('/'):\n        fluid.io.save_params(\n            exe, dirname=args.save_weights_path, main_program=tp)\n    else:\n        fluid.io.save_params(\n            exe, dirname=\"\", filename=args.save_weights_path, main_program=tp)\n\n\ndef loss(logit, label):\n    label_nignore = (label < num_classes).astype('float32')\n    label = fluid.layers.elementwise_min(\n        label,\n        fluid.layers.assign(np.array(\n            [num_classes - 1], dtype=np.int32)))\n    logit = fluid.layers.transpose(logit, [0, 2, 3, 1])\n    logit = fluid.layers.reshape(logit, [-1, num_classes])\n    label = fluid.layers.reshape(label, [-1, 1])\n    label = fluid.layers.cast(label, 'int64')\n    label_nignore = fluid.layers.reshape(label_nignore, [-1, 1])\n    loss = fluid.layers.softmax_with_cross_entropy(logit, label)\n    loss = loss * label_nignore\n    no_grad_set.add(label_nignore.name)\n    no_grad_set.add(label.name)\n    return loss, label_nignore\n\n\ndef get_cards(args):\n    if args.enable_ce:\n        cards = os.environ.get('CUDA_VISIBLE_DEVICES')\n        num = len(cards.split(\",\"))\n        return num\n    else:\n        return args.num_devices\n\n\nCityscapeDataset = reader.CityscapeDataset\nparser = argparse.ArgumentParser()\n\nadd_arguments()\n\nargs = parser.parse_args()\n\nmodels.clean()\nmodels.bn_momentum = 0.9997\nmodels.dropout_keep_prop = 0.9\nmodels.label_number = args.num_classes\ndeeplabv3p = models.deeplabv3p\n\nsp = fluid.Program()\ntp = fluid.Program()\n\n# only for ce\nif args.enable_ce:\n    SEED = 102\n    sp.random_seed = SEED\n    tp.random_seed = SEED\n\ncrop_size = args.train_crop_size\nbatch_size = args.batch_size\nimage_shape = [crop_size, crop_size]\nreader.default_config['crop_size'] = crop_size\nreader.default_config['shuffle'] = True\nnum_classes = args.num_classes\nweight_decay = 0.00004\n\nbase_lr = args.base_lr\ntotal_step = args.total_step\n\nno_grad_set = set()\n\nwith fluid.program_guard(tp, sp):\n    img = fluid.layers.data(\n        name='img', shape=[3] + image_shape, dtype='float32')\n    label = fluid.layers.data(name='label', shape=image_shape, dtype='int32')\n    logit = deeplabv3p(img)\n    pred = fluid.layers.argmax(logit, axis=1).astype('int32')\n    loss, mask = loss(logit, label)\n    lr = fluid.layers.polynomial_decay(\n        base_lr, total_step, end_learning_rate=0, power=0.9)\n    area = fluid.layers.elementwise_max(\n        fluid.layers.reduce_mean(mask),\n        fluid.layers.assign(np.array(\n            [0.1], dtype=np.float32)))\n    loss_mean = fluid.layers.reduce_mean(loss) / area\n\n    opt = fluid.optimizer.Momentum(\n        lr,\n        momentum=0.9,\n        regularization=fluid.regularizer.L2DecayRegularizer(\n            regularization_coeff=weight_decay), )\n    retv = opt.minimize(loss_mean, startup_program=sp, no_grad_set=no_grad_set)\n\nfluid.memory_optimize(\n    tp, print_log=False, skip_opt_set=set([pred.name, loss_mean.name]), level=1)\n\nplace = fluid.CPUPlace()\nif args.use_gpu:\n    place = fluid.CUDAPlace(0)\nexe = fluid.Executor(place)\nexe.run(sp)\n\nif args.init_weights_path:\n    print(\"load from:\", args.init_weights_path)\n    load_model()\n\ndataset = CityscapeDataset(args.dataset_path, 'train')\n\nif args.parallel:\n    exe_p = fluid.ParallelExecutor(\n        use_cuda=True, loss_name=loss_mean.name, main_program=tp)\n\nbatches = dataset.get_batch_generator(batch_size, total_step)\n\ntotal_time = 0.0\nepoch_idx = 0\ntrain_loss = 0\n\nfor i, imgs, labels, names in batches:\n    epoch_idx += 1\n    begin_time = time.time()\n    prev_start_time = time.time()\n    if args.parallel:\n        retv = exe_p.run(fetch_list=[pred.name, loss_mean.name],\n                         feed={'img': imgs,\n                               'label': labels})\n    else:\n        retv = exe.run(tp,\n                       feed={'img': imgs,\n                             'label': labels},\n                       fetch_list=[pred, loss_mean])\n    end_time = time.time()\n    total_time += end_time - begin_time\n    if i % 100 == 0:\n        print(\"Model is saved to\", args.save_weights_path)\n        save_model()\n    print(\"step {:d}, loss: {:.6f}, step_time_cost: {:.3f}\".format(\n        i, np.mean(retv[1]), end_time - prev_start_time))\n\n    # only for ce\n    train_loss = np.mean(retv[1])\n\nif args.enable_ce:\n    gpu_num = get_cards(args)\n    print(\"kpis\\teach_pass_duration_card%s\\t%s\" %\n          (gpu_num, total_time / epoch_idx))\n    print(\"kpis\\ttrain_loss_card%s\\t%s\" % (gpu_num, train_loss))\n\nprint(\"Training done. Model is saved to\", args.save_weights_path)\nsave_model()\n", "path": "fluid/PaddleCV/deeplabv3+/train.py"}]}