未验证 提交 7feb739d 编写于 作者: Z zhaoyuchen2018 提交者: GitHub

Add readme and disable memopt (#2478)

* Add readme and disable memopt

memopt may affect GC result

test=develop
Signed-off-by: Nzhaoyuchen <zhaoyuchen01@baidu.com>

* Disable memopt as GC opend

test=develop
Signed-off-by: Nzhaoyuchen <zhaoyuchen01@baidu.com>
上级 c9f6394f
...@@ -64,6 +64,7 @@ python train.py \ ...@@ -64,6 +64,7 @@ python train.py \
--image_shape=3,224,224 \ --image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--with_mem_opt=False \ --with_mem_opt=False \
--with_inplace=True \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 --lr=0.1
``` ```
...@@ -76,7 +77,8 @@ python train.py \ ...@@ -76,7 +77,8 @@ python train.py \
* **class_dim**: the class number of the classification task. Default: 1000. * **class_dim**: the class number of the classification task. Default: 1000.
* **image_shape**: input size of the network. Default: "3,224,224". * **image_shape**: input size of the network. Default: "3,224,224".
* **model_save_dir**: the directory to save trained model. Default: "output". * **model_save_dir**: the directory to save trained model. Default: "output".
* **with_mem_opt**: whether to use memory optimization or not. Default: True. * **with_mem_opt**: whether to use memory optimization or not. Default: False.
* **with_inplace**: whether to use inplace memory optimization or not. Default: True.
* **lr_strategy**: learning rate changing strategy. Default: "piecewise_decay". * **lr_strategy**: learning rate changing strategy. Default: "piecewise_decay".
* **lr**: initialized learning rate. Default: 0.1. * **lr**: initialized learning rate. Default: 0.1.
* **pretrained_model**: model path for pretraining. Default: None. * **pretrained_model**: model path for pretraining. Default: None.
...@@ -185,4 +187,3 @@ Available top-1/top-5 validation accuracy on ImageNet 2012 are listed in table. ...@@ -185,4 +187,3 @@ Available top-1/top-5 validation accuracy on ImageNet 2012 are listed in table.
|[GoogleNet](https://paddle-imagenet-models-name.bj.bcebos.com/GoogleNet_pretrained.tar) | 70.70%/89.66% | |[GoogleNet](https://paddle-imagenet-models-name.bj.bcebos.com/GoogleNet_pretrained.tar) | 70.70%/89.66% |
|[ShuffleNetV2](https://paddle-imagenet-models-name.bj.bcebos.com/ShuffleNetV2_pretrained.tar) | 70.03%/89.17% | |[ShuffleNetV2](https://paddle-imagenet-models-name.bj.bcebos.com/ShuffleNetV2_pretrained.tar) | 70.03%/89.17% |
|[InceptionV4](https://paddle-imagenet-models-name.bj.bcebos.com/InceptionV4_pretrained.tar) | 80.77%/95.26% | |[InceptionV4](https://paddle-imagenet-models-name.bj.bcebos.com/InceptionV4_pretrained.tar) | 80.77%/95.26% |
...@@ -61,6 +61,7 @@ python train.py \ ...@@ -61,6 +61,7 @@ python train.py \
--image_shape=3,224,224 \ --image_shape=3,224,224 \
--model_save_dir=output/ \ --model_save_dir=output/ \
--with_mem_opt=False \ --with_mem_opt=False \
--with_inplace=True \
--lr_strategy=piecewise_decay \ --lr_strategy=piecewise_decay \
--lr=0.1 --lr=0.1
``` ```
...@@ -74,6 +75,7 @@ python train.py \ ...@@ -74,6 +75,7 @@ python train.py \
* **image_shape**: 图片大小,默认值: "3,224,224" * **image_shape**: 图片大小,默认值: "3,224,224"
* **model_save_dir**: 模型存储路径,默认值: "output/" * **model_save_dir**: 模型存储路径,默认值: "output/"
* **with_mem_opt**: 是否开启显存优化,默认值: False * **with_mem_opt**: 是否开启显存优化,默认值: False
* **with_inplace**: 是否开启inplace显存优化,默认值: True
* **lr_strategy**: 学习率变化策略,默认值: "piecewise_decay" * **lr_strategy**: 学习率变化策略,默认值: "piecewise_decay"
* **lr**: 初始学习率,默认值: 0.1 * **lr**: 初始学习率,默认值: 0.1
* **pretrained_model**: 预训练模型路径,默认值: None * **pretrained_model**: 预训练模型路径,默认值: None
......
...@@ -23,6 +23,7 @@ import sys ...@@ -23,6 +23,7 @@ import sys
import functools import functools
import math import math
def set_paddle_flags(flags): def set_paddle_flags(flags):
for key, value in flags.items(): for key, value in flags.items():
if os.environ.get(key, None) is None: if os.environ.get(key, None) is None:
...@@ -62,7 +63,7 @@ add_arg('num_epochs', int, 120, "number of epochs.") ...@@ -62,7 +63,7 @@ add_arg('num_epochs', int, 120, "number of epochs.")
add_arg('class_dim', int, 1000, "Class number.") add_arg('class_dim', int, 1000, "Class number.")
add_arg('image_shape', str, "3,224,224", "input image size") add_arg('image_shape', str, "3,224,224", "input image size")
add_arg('model_save_dir', str, "output", "model save directory") add_arg('model_save_dir', str, "output", "model save directory")
add_arg('with_mem_opt', bool, True, "Whether to use memory optimization or not.") add_arg('with_mem_opt', bool, False, "Whether to use memory optimization or not.")
add_arg('with_inplace', bool, True, "Whether to use inplace memory optimization.") add_arg('with_inplace', bool, True, "Whether to use inplace memory optimization.")
add_arg('pretrained_model', str, None, "Whether to use pretrained model.") add_arg('pretrained_model', str, None, "Whether to use pretrained model.")
add_arg('checkpoint', str, None, "Whether to resume checkpoint.") add_arg('checkpoint', str, None, "Whether to resume checkpoint.")
...@@ -248,7 +249,7 @@ def net_config(image, model, args, is_train, label=0, y_a=0, y_b=0, lam=0.0): ...@@ -248,7 +249,7 @@ def net_config(image, model, args, is_train, label=0, y_a=0, y_b=0, lam=0.0):
return avg_cost return avg_cost
else: else:
cost = calc_loss(epsilon,label,class_dim,softmax_out,use_label_smoothing) cost = calc_loss(epsilon,label,class_dim,softmax_out,use_label_smoothing)
else: else:
cost = fluid.layers.cross_entropy(input=softmax_out, label=label) cost = fluid.layers.cross_entropy(input=softmax_out, label=label)
else: else:
...@@ -256,7 +257,7 @@ def net_config(image, model, args, is_train, label=0, y_a=0, y_b=0, lam=0.0): ...@@ -256,7 +257,7 @@ def net_config(image, model, args, is_train, label=0, y_a=0, y_b=0, lam=0.0):
softmax_out1, softmax_out = fluid.layers.softmax(out1), fluid.layers.softmax(out2) softmax_out1, softmax_out = fluid.layers.softmax(out1), fluid.layers.softmax(out2)
smooth_out1 = fluid.layers.label_smooth(label=softmax_out1, epsilon=0.0, dtype="float32") smooth_out1 = fluid.layers.label_smooth(label=softmax_out1, epsilon=0.0, dtype="float32")
cost = fluid.layers.cross_entropy(input=softmax_out, label=smooth_out1, soft_label=True) cost = fluid.layers.cross_entropy(input=softmax_out, label=smooth_out1, soft_label=True)
avg_cost = fluid.layers.mean(cost) avg_cost = fluid.layers.mean(cost)
if args.scale_loss > 1: if args.scale_loss > 1:
avg_cost = fluid.layers.mean(x=cost) * float(args.scale_loss) avg_cost = fluid.layers.mean(x=cost) * float(args.scale_loss)
...@@ -428,7 +429,8 @@ def train(args): ...@@ -428,7 +429,8 @@ def train(args):
use_ngraph = os.getenv('FLAGS_use_ngraph') use_ngraph = os.getenv('FLAGS_use_ngraph')
if not use_ngraph: if not use_ngraph:
build_strategy = fluid.BuildStrategy() build_strategy = fluid.BuildStrategy()
build_strategy.memory_optimize = args.with_mem_opt # memopt may affect GC results
#build_strategy.memory_optimize = args.with_mem_opt
build_strategy.enable_inplace = args.with_inplace build_strategy.enable_inplace = args.with_inplace
#build_strategy.fuse_all_reduce_ops=1 #build_strategy.fuse_all_reduce_ops=1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册