diff --git a/PaddleCV/image_classification/README.md b/PaddleCV/image_classification/README.md index bf4f509d67a05adb0d04298bd202b72612c572cb..7b469d1b982cdb6cfc59edfd07f85c4b01641eb3 100644 --- a/PaddleCV/image_classification/README.md +++ b/PaddleCV/image_classification/README.md @@ -64,6 +64,7 @@ python train.py \ --image_shape=3,224,224 \ --model_save_dir=output/ \ --with_mem_opt=False \ + --with_inplace=True \ --lr_strategy=piecewise_decay \ --lr=0.1 ``` @@ -76,7 +77,8 @@ python train.py \ * **class_dim**: the class number of the classification task. Default: 1000. * **image_shape**: input size of the network. Default: "3,224,224". * **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**: initialized learning rate. Default: 0.1. * **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. |[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% | |[InceptionV4](https://paddle-imagenet-models-name.bj.bcebos.com/InceptionV4_pretrained.tar) | 80.77%/95.26% | - diff --git a/PaddleCV/image_classification/README_cn.md b/PaddleCV/image_classification/README_cn.md index 4af494e7b961505959ebe3c11e02999ad239145f..94781e5d6da1aee78fa6b960be5e5c78ade5c48e 100644 --- a/PaddleCV/image_classification/README_cn.md +++ b/PaddleCV/image_classification/README_cn.md @@ -61,6 +61,7 @@ python train.py \ --image_shape=3,224,224 \ --model_save_dir=output/ \ --with_mem_opt=False \ + --with_inplace=True \ --lr_strategy=piecewise_decay \ --lr=0.1 ``` @@ -74,6 +75,7 @@ python train.py \ * **image_shape**: 图片大小,默认值: "3,224,224" * **model_save_dir**: 模型存储路径,默认值: "output/" * **with_mem_opt**: 是否开启显存优化,默认值: False +* **with_inplace**: 是否开启inplace显存优化,默认值: True * **lr_strategy**: 学习率变化策略,默认值: "piecewise_decay" * **lr**: 初始学习率,默认值: 0.1 * **pretrained_model**: 预训练模型路径,默认值: None diff --git a/PaddleCV/image_classification/train.py b/PaddleCV/image_classification/train.py index e72af3d9a0e2699d494d4e6640d338af49454b71..a50b1253b701fb19947f4a391c48cc3d99886696 100644 --- a/PaddleCV/image_classification/train.py +++ b/PaddleCV/image_classification/train.py @@ -23,6 +23,7 @@ import sys import functools import math + def set_paddle_flags(flags): for key, value in flags.items(): if os.environ.get(key, None) is None: @@ -62,7 +63,7 @@ add_arg('num_epochs', int, 120, "number of epochs.") add_arg('class_dim', int, 1000, "Class number.") add_arg('image_shape', str, "3,224,224", "input image size") 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('pretrained_model', str, None, "Whether to use pretrained model.") 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): return avg_cost else: cost = calc_loss(epsilon,label,class_dim,softmax_out,use_label_smoothing) - + else: cost = fluid.layers.cross_entropy(input=softmax_out, label=label) else: @@ -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) 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) - + avg_cost = fluid.layers.mean(cost) if args.scale_loss > 1: avg_cost = fluid.layers.mean(x=cost) * float(args.scale_loss) @@ -428,7 +429,8 @@ def train(args): use_ngraph = os.getenv('FLAGS_use_ngraph') if not use_ngraph: 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.fuse_all_reduce_ops=1