From 9cddc51a2ab61eebea712ee0c10afdc527ba2a24 Mon Sep 17 00:00:00 2001 From: Nemo <132769294+ChongWei905@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:11:35 +0800 Subject: [PATCH] merge commits fixing bugs from branch main to branch v0.4.0 (#799) * fix: fix all zero initialized tensor problem for vit (#794) Co-authored-by: ChongWei905 (cherry picked from commit 2a07185b368c66eea195531501e658fc30b22b91) * feat: add validate shuffle config and set default to False (#793) (cherry picked from commit 1c283bca26d6b63a90c018476f143b8f092e9f22) Co-authored-by: ChongWei905 (cherry picked from commit 69ae862bdddf994e0c75256683c6eb0c854a4c4f) * fix: fix load checkpoint failure for deeplabv3 (#790) Co-authored-by: ChongWei905 (cherry picked from commit c744121a1c9f4dfbba945e8900ac6e94c3af1a92) * ops.ResizeBilinear has been deprecated, thus using ops.ResizeBilinearV2 instead (#789) (cherry picked from commit a6d45f3fe1e536d90b43ee51afc2362ddaeba872) --------- Co-authored-by: Pingqi Li <58093835+PingqiLi@users.noreply.github.com> --- config.py | 2 ++ examples/det/ssd/model.py | 2 +- examples/seg/deeplabv3/callbacks.py | 2 +- examples/seg/deeplabv3/deeplabv3.py | 2 +- examples/seg/deeplabv3/train.py | 2 +- mindcv/models/vit.py | 4 +++- validate.py | 1 + 7 files changed, 10 insertions(+), 5 deletions(-) diff --git a/config.py b/config.py index 06bbabef0..b2eeeaa13 100644 --- a/config.py +++ b/config.py @@ -263,6 +263,8 @@ def create_parser(): help='Loss scale (default=1.0)') group.add_argument('--drop_overflow_update', type=bool, default=False, help='Whether to execute optimizer if there is an overflow (default=False)') + group.add_argument('--eval_shuffle', type=bool, default=False, + help='Whether to shuffle the evaluation data (default=False)') return parser_config, parser # fmt: on diff --git a/examples/det/ssd/model.py b/examples/det/ssd/model.py index 137ba716a..106331ff2 100644 --- a/examples/det/ssd/model.py +++ b/examples/det/ssd/model.py @@ -208,7 +208,7 @@ def construct(self, inputs): top = len(inputs) - i - 1 down = top - 1 size = ops.shape(inputs[down]) - top_down = ops.ResizeBilinear((size[2], size[3]))(features[-1]) + top_down = ops.ResizeBilinearV2()(features[-1], (size[2], size[3])) top_down = top_down + image_features[down] features = features + (top_down,) diff --git a/examples/seg/deeplabv3/callbacks.py b/examples/seg/deeplabv3/callbacks.py index 1024d64ed..1a26622a9 100644 --- a/examples/seg/deeplabv3/callbacks.py +++ b/examples/seg/deeplabv3/callbacks.py @@ -100,7 +100,7 @@ def on_train_end(self, run_context): def get_segment_train_callback(args, steps_per_epoch, rank_id): callbacks = [TimeMonitor(data_size=steps_per_epoch), LossMonitor()] - if rank_id == 0: + if rank_id == 0 or rank_id is None: ckpt_config = CheckpointConfig( save_checkpoint_steps=args.save_steps, keep_checkpoint_max=args.keep_checkpoint_max, diff --git a/examples/seg/deeplabv3/deeplabv3.py b/examples/seg/deeplabv3/deeplabv3.py index 10df2fd45..2d2f358d5 100644 --- a/examples/seg/deeplabv3/deeplabv3.py +++ b/examples/seg/deeplabv3/deeplabv3.py @@ -260,7 +260,7 @@ class DeepLabInferNetwork(nn.Cell): """ def __init__(self, network, input_format="NCHW"): - super(DeepLabInferNetwork, self).__init__() + super(DeepLabInferNetwork, self).__init__(auto_prefix=False) self.network = network self.softmax = nn.Softmax(axis=1) self.format = input_format diff --git a/examples/seg/deeplabv3/train.py b/examples/seg/deeplabv3/train.py index 45bc796ad..7c8379a22 100644 --- a/examples/seg/deeplabv3/train.py +++ b/examples/seg/deeplabv3/train.py @@ -140,7 +140,7 @@ def train(args): callbacks = get_segment_train_callback(args, steps_per_epoch, rank_id) # eval when train - if args.eval_while_train and rank_id == 0: + if args.eval_while_train and (rank_id == 0 or rank_id is None): eval_model = DeepLabInferNetwork(deeplab, input_format=args.input_format) eval_dataset = create_segment_dataset( name=args.dataset, diff --git a/mindcv/models/vit.py b/mindcv/models/vit.py index c158e6a39..c8ee0967e 100644 --- a/mindcv/models/vit.py +++ b/mindcv/models/vit.py @@ -329,7 +329,9 @@ def get_num_layers(self): def _init_weights(self): w = self.patch_embed.proj.weight w_shape_flatted = (w.shape[0], functools.reduce(lambda x, y: x*y, w.shape[1:])) - w.set_data(initializer(XavierUniform(), w_shape_flatted, w.dtype).reshape(w.shape)) + w_value = initializer(XavierUniform(), w_shape_flatted, w.dtype) + w_value.init_data() + w.set_data(w_value.reshape(w.shape)) for _, cell in self.cells_and_names(): if isinstance(cell, nn.Dense): cell.weight.set_data( diff --git a/validate.py b/validate.py index 158240fc4..fc4285779 100644 --- a/validate.py +++ b/validate.py @@ -37,6 +37,7 @@ def validate(args): split=args.val_split, num_parallel_workers=args.num_parallel_workers, download=args.dataset_download, + shuffle=args.eval_shuffle, ) # create transform