diff --git a/demo/nas/block_sa_nas_mobilenetv2.py b/demo/nas/block_sa_nas_mobilenetv2.py index 075c7068b1dc263e3d09592e115c0d1fdb8f2882..b58fc9effee2f8d5675edb780a45a8d263804c98 100644 --- a/demo/nas/block_sa_nas_mobilenetv2.py +++ b/demo/nas/block_sa_nas_mobilenetv2.py @@ -20,7 +20,7 @@ reduce_rate = 0.85 init_temperature = 10.24 max_flops = 321208544 server_address = "" -port = 8909 +port = 8979 retain_epoch = 5 @@ -243,42 +243,7 @@ if __name__ == '__main__': type=int, default=100, help='controller server number.') - # optimizer args - parser.add_argument( - '--lr_strategy', - type=str, - default='piecewise_decay', - help='learning rate decay strategy.') parser.add_argument('--lr', type=float, default=0.1, help='learning rate.') - parser.add_argument( - '--l2_decay', type=float, default=1e-4, help='learning rate decay.') - parser.add_argument( - '--step_epochs', - nargs='+', - type=int, - default=[30, 60, 90], - help="piecewise decay step") - parser.add_argument( - '--momentum_rate', - type=float, - default=0.9, - help='learning rate decay.') - parser.add_argument( - '--warm_up_epochs', - type=float, - default=5.0, - help='learning rate decay.') - parser.add_argument( - '--num_epochs', type=int, default=120, help='learning rate decay.') - parser.add_argument( - '--decay_epochs', type=float, default=2.4, help='learning rate decay.') - parser.add_argument( - '--decay_rate', type=float, default=0.97, help='learning rate decay.') - parser.add_argument( - '--total_images', - type=int, - default=1281167, - help='learning rate decay.') args = parser.parse_args() print(args) diff --git a/demo/nas/sa_nas_mobilenetv2.py b/demo/nas/sa_nas_mobilenetv2.py index 990a9629d8c53bc9d112fb1e69a609c239054852..5e60da0fec30210afc177f0cdbe65b5154b73472 100644 --- a/demo/nas/sa_nas_mobilenetv2.py +++ b/demo/nas/sa_nas_mobilenetv2.py @@ -22,7 +22,7 @@ reduce_rate = 0.85 init_temperature = 10.24 max_flops = 321208544 server_address = "" -port = 8909 +port = 8989 retain_epoch = 5 @@ -284,6 +284,8 @@ if __name__ == '__main__': help='Whether to use GPU in train/test model.') parser.add_argument( '--batch_size', type=int, default=256, help='batch size.') + parser.add_argument( + '--class_dim', type=int, default=1000, help='classify number.') parser.add_argument( '--data', type=str, @@ -300,43 +302,7 @@ if __name__ == '__main__': type=int, default=100, help='controller server number.') - parser.add_argument( - '--lr_strategy', - type=str, - default='cosine_decay', - help='learning rate decay strategy.') parser.add_argument('--lr', type=float, default=0.1, help='learning rate.') - parser.add_argument( - '--l2_decay', type=float, default=1e-4, help='learning rate decay.') - parser.add_argument( - '--class_dim', type=int, default=100, help='classify number.') - parser.add_argument( - '--step_epochs', - nargs='+', - type=int, - default=[30, 60, 90], - help="piecewise decay step") - parser.add_argument( - '--momentum_rate', - type=float, - default=0.9, - help='learning rate decay.') - parser.add_argument( - '--warm_up_epochs', - type=float, - default=5.0, - help='learning rate decay.') - parser.add_argument( - '--num_epochs', type=int, default=120, help='learning rate decay.') - parser.add_argument( - '--decay_epochs', type=float, default=2.4, help='learning rate decay.') - parser.add_argument( - '--decay_rate', type=float, default=0.97, help='learning rate decay.') - parser.add_argument( - '--total_images', - type=int, - default=1281167, - help='learning rate decay.') args = parser.parse_args() print(args) diff --git a/demo/optimizer.py b/demo/optimizer.py index 73f441f897d22c10d2d6e05afaa7491b227b27d4..0f0c57985f839097e9e1ae4643ba2e5a2fb64698 100644 --- a/demo/optimizer.py +++ b/demo/optimizer.py @@ -23,6 +23,16 @@ import paddle.fluid.layers.ops as ops from paddle.fluid.initializer import init_on_cpu from paddle.fluid.layers.learning_rate_scheduler import _decay_step_counter +lr_strategy = 'cosine_decay' +l2_decay = 1e-4 +step_epochs = [30, 60, 90] +momentum_rate = 0.9 +warm_up_epochs = 5.0 +num_epochs = 120 +decay_epochs = 2.4 +decay_rate = 0.97 +total_images = 1281167 + def cosine_decay(learning_rate, step_each_epoch, epochs=120): """Applies cosine decay to the learning rate. @@ -152,15 +162,15 @@ class Optimizer(object): def __init__(self, args): self.batch_size = args.batch_size self.lr = args.lr - self.lr_strategy = args.lr_strategy - self.l2_decay = args.l2_decay - self.momentum_rate = args.momentum_rate - self.step_epochs = args.step_epochs - self.num_epochs = args.num_epochs - self.warm_up_epochs = args.warm_up_epochs - self.decay_epochs = args.decay_epochs - self.decay_rate = args.decay_rate - self.total_images = args.total_images + self.lr_strategy = lr_strategy + self.l2_decay = l2_decay + self.momentum_rate = momentum_rate + self.step_epochs = step_epochs + self.num_epochs = num_epochs + self.warm_up_epochs = warm_up_epochs + self.decay_epochs = decay_epochs + self.decay_rate = decay_rate + self.total_images = total_images self.step = int(math.ceil(float(self.total_images) / self.batch_size)) @@ -295,6 +305,6 @@ class Optimizer(object): def create_optimizer(args): Opt = Optimizer(args) - optimizer = getattr(Opt, args.lr_strategy)() + optimizer = getattr(Opt, lr_strategy)() return optimizer