From 206b36cc9af5abee06ad6bfb12137b5460122283 Mon Sep 17 00:00:00 2001 From: shijianning Date: Fri, 8 May 2020 14:46:36 +0800 Subject: [PATCH 1/6] fix pylint warnings --- example/yolov3_coco2017/train.py | 11 +++++------ mindspore/_akg/utils/format_transform.py | 4 ++-- .../model_zoo/Bert_NEZHA/bert_for_pre_training.py | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/example/yolov3_coco2017/train.py b/example/yolov3_coco2017/train.py index 6a9729f2000..a5473feada8 100644 --- a/example/yolov3_coco2017/train.py +++ b/example/yolov3_coco2017/train.py @@ -41,23 +41,22 @@ from config import ConfigYOLOV3ResNet18 def get_lr(learning_rate, start_step, global_step, decay_step, decay_rate, steps=False): """Set learning rate.""" lr_each_step = [] - lr = learning_rate for i in range(global_step): if steps: - lr_each_step.append(lr * (decay_rate ** (i // decay_step))) + lr_each_step.append(learning_rate * (decay_rate ** (i // decay_step))) else: - lr_each_step.append(lr * (decay_rate ** (i / decay_step))) + lr_each_step.append(learning_rate * (decay_rate ** (i / decay_step))) lr_each_step = np.array(lr_each_step).astype(np.float32) lr_each_step = lr_each_step[start_step:] return lr_each_step -def init_net_param(net, init='ones'): - """Init the parameters in net.""" +def init_net_param(net, init_value='ones'): + """Init:wq the parameters in net.""" params = net.trainable_params() for p in params: if isinstance(p.data, Tensor) and 'beta' not in p.name and 'gamma' not in p.name and 'bias' not in p.name: - p.set_parameter_data(initializer(init, p.data.shape(), p.data.dtype())) + p.set_parameter_data(initializer(init_value, p.data.shape(), p.data.dtype())) if __name__ == '__main__': diff --git a/mindspore/_akg/utils/format_transform.py b/mindspore/_akg/utils/format_transform.py index f83130a32a2..c7a69b26cc1 100644 --- a/mindspore/_akg/utils/format_transform.py +++ b/mindspore/_akg/utils/format_transform.py @@ -15,9 +15,9 @@ """format transform function""" import _akg -def refine_reduce_axis(input, axis): +def refine_reduce_axis(input_content, axis): """make reduce axis legal.""" - shape = get_shape(input) + shape = get_shape(input_content) if axis is None: axis = [i for i in range(len(shape))] elif isinstance(axis, int): diff --git a/mindspore/model_zoo/Bert_NEZHA/bert_for_pre_training.py b/mindspore/model_zoo/Bert_NEZHA/bert_for_pre_training.py index 53a0d039330..f8b73a2b638 100644 --- a/mindspore/model_zoo/Bert_NEZHA/bert_for_pre_training.py +++ b/mindspore/model_zoo/Bert_NEZHA/bert_for_pre_training.py @@ -55,7 +55,7 @@ class ClipGradients(nn.Cell): grads, clip_type, clip_value): - if clip_type != 0 and clip_type != 1: + if clip_type not in (0, 1): return grads new_grads = () From 42ac7c50283095c41fc4313cf6995bcc276ab39a Mon Sep 17 00:00:00 2001 From: shijianning Date: Tue, 12 May 2020 09:14:03 +0800 Subject: [PATCH 2/6] fix Pylint Warning too-many-function-args --- example/alexnet_cifar10/eval.py | 8 ++++---- example/alexnet_cifar10/train.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/example/alexnet_cifar10/eval.py b/example/alexnet_cifar10/eval.py index be71e339950..7ce96d06c26 100644 --- a/example/alexnet_cifar10/eval.py +++ b/example/alexnet_cifar10/eval.py @@ -50,9 +50,9 @@ if __name__ == "__main__": print("============== Starting Testing ==============") param_dict = load_checkpoint(args.ckpt_path) load_param_into_net(network, param_dict) - ds_eval = create_dataset(args.data_path, - cfg.batch_size, - 1, - "test") + ds_eval = create_dataset(data_path=args.data_path, + batch_size=cfg.batch_size, + repeat_size=1, + status="test") acc = model.eval(ds_eval, dataset_sink_mode=args.dataset_sink_mode) print("============== Accuracy:{} ==============".format(acc)) diff --git a/example/alexnet_cifar10/train.py b/example/alexnet_cifar10/train.py index b97843902dd..e0588420e80 100644 --- a/example/alexnet_cifar10/train.py +++ b/example/alexnet_cifar10/train.py @@ -47,10 +47,10 @@ if __name__ == "__main__": model = Model(network, loss, opt, metrics={"Accuracy": Accuracy()}) # test print("============== Starting Training ==============") - ds_train = create_dataset(args.data_path, - cfg.batch_size, - cfg.epoch_size, - "train") + ds_train = create_dataset(data_path=args.data_path, + batch_size=cfg.batch_size, + repeat_size=cfg.epoch_size, + status="train") config_ck = CheckpointConfig(save_checkpoint_steps=cfg.save_checkpoint_steps, keep_checkpoint_max=cfg.keep_checkpoint_max) ckpoint_cb = ModelCheckpoint(prefix="checkpoint_alexnet", directory=args.ckpt_path, config=config_ck) From e2b5741e99f55fee6317b3ae07c00d159800c634 Mon Sep 17 00:00:00 2001 From: shijianning Date: Tue, 12 May 2020 09:19:44 +0800 Subject: [PATCH 3/6] disable fix for unsupported syntax --- mindspore/model_zoo/Bert_NEZHA/bert_for_pre_training.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mindspore/model_zoo/Bert_NEZHA/bert_for_pre_training.py b/mindspore/model_zoo/Bert_NEZHA/bert_for_pre_training.py index f8b73a2b638..53a0d039330 100644 --- a/mindspore/model_zoo/Bert_NEZHA/bert_for_pre_training.py +++ b/mindspore/model_zoo/Bert_NEZHA/bert_for_pre_training.py @@ -55,7 +55,7 @@ class ClipGradients(nn.Cell): grads, clip_type, clip_value): - if clip_type not in (0, 1): + if clip_type != 0 and clip_type != 1: return grads new_grads = () From 710a0e817b534f33e4497a030792bf6e24b0cac2 Mon Sep 17 00:00:00 2001 From: shijianning Date: Tue, 12 May 2020 10:19:26 +0800 Subject: [PATCH 4/6] remove unused args & fix pylint warning --- example/ssd_coco2017/dataset.py | 2 +- example/yolov3_coco2017/train.py | 6 +++--- mindspore/_akg/add_path.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/example/ssd_coco2017/dataset.py b/example/ssd_coco2017/dataset.py index c725c14e006..b88b22c8626 100644 --- a/example/ssd_coco2017/dataset.py +++ b/example/ssd_coco2017/dataset.py @@ -137,7 +137,7 @@ def ssd_bboxes_encode(boxes): num_match_num = np.array([len(np.nonzero(t_label)[0])], dtype=np.int32) return bboxes, t_label.astype(np.int32), num_match_num -def ssd_bboxes_decode(boxes, index, image_shape): +def ssd_bboxes_decode(boxes, index): """Decode predict boxes to [x, y, w, h]""" boxes_t = boxes[index] default_boxes_t = default_boxes[index] diff --git a/example/yolov3_coco2017/train.py b/example/yolov3_coco2017/train.py index a5473feada8..5c0d8921ad1 100644 --- a/example/yolov3_coco2017/train.py +++ b/example/yolov3_coco2017/train.py @@ -51,9 +51,9 @@ def get_lr(learning_rate, start_step, global_step, decay_step, decay_rate, steps return lr_each_step -def init_net_param(net, init_value='ones'): - """Init:wq the parameters in net.""" - params = net.trainable_params() +def init_net_param(network, init_value='ones'): + """Init:wq the parameters in network.""" + params = network.trainable_params() for p in params: if isinstance(p.data, Tensor) and 'beta' not in p.name and 'gamma' not in p.name and 'bias' not in p.name: p.set_parameter_data(initializer(init_value, p.data.shape(), p.data.dtype())) diff --git a/mindspore/_akg/add_path.py b/mindspore/_akg/add_path.py index a9fd0d4a094..2de2f73e1ca 100644 --- a/mindspore/_akg/add_path.py +++ b/mindspore/_akg/add_path.py @@ -31,7 +31,7 @@ def AKGAddPath(): class AKGMetaPathFinder: """class AKGMetaPath finder.""" - def find_module(self, fullname, path=None): + def find_module(self, fullname): """method _akg find module.""" if fullname.startswith("_akg.tvm"): rname = fullname[5:] From 5afcefdce491363d9ffa57565de60308361a432c Mon Sep 17 00:00:00 2001 From: shijianning Date: Wed, 13 May 2020 15:27:32 +0800 Subject: [PATCH 5/6] try fix pylint warning --- example/alexnet_cifar10/eval.py | 8 ++++---- example/alexnet_cifar10/train.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/example/alexnet_cifar10/eval.py b/example/alexnet_cifar10/eval.py index 7ce96d06c26..be71e339950 100644 --- a/example/alexnet_cifar10/eval.py +++ b/example/alexnet_cifar10/eval.py @@ -50,9 +50,9 @@ if __name__ == "__main__": print("============== Starting Testing ==============") param_dict = load_checkpoint(args.ckpt_path) load_param_into_net(network, param_dict) - ds_eval = create_dataset(data_path=args.data_path, - batch_size=cfg.batch_size, - repeat_size=1, - status="test") + ds_eval = create_dataset(args.data_path, + cfg.batch_size, + 1, + "test") acc = model.eval(ds_eval, dataset_sink_mode=args.dataset_sink_mode) print("============== Accuracy:{} ==============".format(acc)) diff --git a/example/alexnet_cifar10/train.py b/example/alexnet_cifar10/train.py index e0588420e80..b97843902dd 100644 --- a/example/alexnet_cifar10/train.py +++ b/example/alexnet_cifar10/train.py @@ -47,10 +47,10 @@ if __name__ == "__main__": model = Model(network, loss, opt, metrics={"Accuracy": Accuracy()}) # test print("============== Starting Training ==============") - ds_train = create_dataset(data_path=args.data_path, - batch_size=cfg.batch_size, - repeat_size=cfg.epoch_size, - status="train") + ds_train = create_dataset(args.data_path, + cfg.batch_size, + cfg.epoch_size, + "train") config_ck = CheckpointConfig(save_checkpoint_steps=cfg.save_checkpoint_steps, keep_checkpoint_max=cfg.keep_checkpoint_max) ckpoint_cb = ModelCheckpoint(prefix="checkpoint_alexnet", directory=args.ckpt_path, config=config_ck) From 2cf2a67dfda485307d3a2b739df5ab107ccde7a5 Mon Sep 17 00:00:00 2001 From: shijianning Date: Wed, 13 May 2020 16:21:24 +0800 Subject: [PATCH 6/6] fix wrong arg call --- mindspore/_akg/add_path.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mindspore/_akg/add_path.py b/mindspore/_akg/add_path.py index 2de2f73e1ca..d1e50f81771 100644 --- a/mindspore/_akg/add_path.py +++ b/mindspore/_akg/add_path.py @@ -31,8 +31,9 @@ def AKGAddPath(): class AKGMetaPathFinder: """class AKGMetaPath finder.""" - def find_module(self, fullname): + def find_module(self, fullname, path=None): """method _akg find module.""" + _ = path if fullname.startswith("_akg.tvm"): rname = fullname[5:] return AKGMetaPathLoader(rname)