diff --git a/official/cv/maskrcnn/src/maskrcnn/fpn_neck.py b/official/cv/maskrcnn/src/maskrcnn/fpn_neck.py index d4e9b8b62d6994248ac2e4c0b009d44bba9a3bc5..6a98de5d2c0b8b80587f7c9330979795e7d77ca8 100644 --- a/official/cv/maskrcnn/src/maskrcnn/fpn_neck.py +++ b/official/cv/maskrcnn/src/maskrcnn/fpn_neck.py @@ -55,7 +55,7 @@ class FeatPyramidNeck(nn.Cell): Tuple, with tensors of same channel size. Examples: - neck = FeatPyramidNeck([100,200,300], 50, 4) + neck = FeatPyramidNeck([100,200,300], 50, 4, config.feature_shapes) input_data = (normal(0,0.1,(1,c,1280//(4*2**i), 768//(4*2**i)), dtype=np.float32) \ for i, c in enumerate(config.fpn_in_channels)) @@ -65,7 +65,8 @@ class FeatPyramidNeck(nn.Cell): def __init__(self, in_channels, out_channels, - num_outs): + num_outs, + feature_shapes): super(FeatPyramidNeck, self).__init__() if context.get_context("device_target") == "Ascend": @@ -91,9 +92,9 @@ class FeatPyramidNeck(nn.Cell): self.fpn_convs_.append(fpn_conv) self.lateral_convs_list = nn.layer.CellList(self.lateral_convs_list_) self.fpn_convs_list = nn.layer.CellList(self.fpn_convs_) - self.interpolate1 = P.ResizeBilinear((48, 80)) - self.interpolate2 = P.ResizeBilinear((96, 160)) - self.interpolate3 = P.ResizeBilinear((192, 320)) + self.interpolate1 = P.ResizeBilinear(feature_shapes[2]) + self.interpolate2 = P.ResizeBilinear(feature_shapes[1]) + self.interpolate3 = P.ResizeBilinear(feature_shapes[0]) self.cast = P.Cast() self.maxpool = P.MaxPool(kernel_size=1, strides=2, pad_mode="same") diff --git a/official/cv/maskrcnn/src/maskrcnn/mask_rcnn_r50.py b/official/cv/maskrcnn/src/maskrcnn/mask_rcnn_r50.py index eec5350df3e95785021755255a75618c12fa69ee..c5be17cb1641d00344b86f8e5b64fb6fd33086fc 100644 --- a/official/cv/maskrcnn/src/maskrcnn/mask_rcnn_r50.py +++ b/official/cv/maskrcnn/src/maskrcnn/mask_rcnn_r50.py @@ -96,7 +96,8 @@ class Mask_Rcnn_Resnet50(nn.Cell): # Fpn self.fpn_ncek = FeatPyramidNeck(config.fpn_in_channels, config.fpn_out_channels, - config.fpn_num_outs) + config.fpn_num_outs, + config.feature_shapes) # Rpn and rpn loss self.gt_labels_stage1 = Tensor(np.ones((self.train_batch_size, config.num_gts)).astype(np.uint8)) diff --git a/official/cv/maskrcnn/src/maskrcnn/proposal_generator.py b/official/cv/maskrcnn/src/maskrcnn/proposal_generator.py index d3c0f781e36679b24fd81848e61533baffaac032..f556d0e176b50a63ed8f803dfda66d95b338af20 100644 --- a/official/cv/maskrcnn/src/maskrcnn/proposal_generator.py +++ b/official/cv/maskrcnn/src/maskrcnn/proposal_generator.py @@ -1,4 +1,4 @@ -# Copyright 2020-2021 Huawei Technologies Co., Ltd +# Copyright 2020-2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -64,15 +64,14 @@ class Proposal(nn.Cell): self.target_means = target_means self.target_stds = target_stds self.use_sigmoid_cls = use_sigmoid_cls + self.reshape_shape = (-1, 1) if self.use_sigmoid_cls: self.cls_out_channels = num_classes - 1 self.activation = P.Sigmoid() - self.reshape_shape = (-1, 1) else: self.cls_out_channels = num_classes self.activation = P.Softmax(axis=1) - self.reshape_shape = (-1, 2) if self.cls_out_channels <= 0: raise ValueError('num_classes={} is too small'.format(num_classes)) diff --git a/research/cv/FaceRecognition/base_config.yaml b/research/cv/FaceRecognition/base_config.yaml index f975ad90f319c579fd7896cb34155c57e085c363..211b03221cf046e67187040944ae51206bc959c2 100644 --- a/research/cv/FaceRecognition/base_config.yaml +++ b/research/cv/FaceRecognition/base_config.yaml @@ -27,7 +27,6 @@ backbone: "r100" use_se: 1 emb_size: 512 act_type: "relu" -fp16: 1 pre_bn: 1 inference: 0 use_drop: 1 diff --git a/research/cv/FaceRecognition/base_config_cpu.yaml b/research/cv/FaceRecognition/base_config_cpu.yaml index 3ea99b1a09bec9231f7d1320a47598fdd33f8243..51891748188465ce1741bfc64ecfe82efc2deec2 100644 --- a/research/cv/FaceRecognition/base_config_cpu.yaml +++ b/research/cv/FaceRecognition/base_config_cpu.yaml @@ -27,7 +27,6 @@ backbone: "r100" use_se: 1 emb_size: 512 act_type: "relu" -fp16: 1 pre_bn: 1 inference: 0 use_drop: 1 diff --git a/research/cv/FaceRecognition/beta_config.yaml b/research/cv/FaceRecognition/beta_config.yaml index 1a4a2a4ac477033fc1811c39ac8f89fa32f824fa..a8b31381107618670e078499d0f088f1fdb5bbb8 100644 --- a/research/cv/FaceRecognition/beta_config.yaml +++ b/research/cv/FaceRecognition/beta_config.yaml @@ -27,7 +27,6 @@ backbone: "r100" use_se: 0 emb_size: 256 act_type: "relu" -fp16: 1 pre_bn: 0 inference: 0 use_drop: 1 diff --git a/research/cv/FaceRecognition/beta_config_cpu.yaml b/research/cv/FaceRecognition/beta_config_cpu.yaml index a0f329a17a4f07fcd20cd86e28222231d46add68..f57680ec6d25b422a298d20b4d4ce783341560e3 100644 --- a/research/cv/FaceRecognition/beta_config_cpu.yaml +++ b/research/cv/FaceRecognition/beta_config_cpu.yaml @@ -27,7 +27,6 @@ backbone: "r100" use_se: 0 emb_size: 256 act_type: "relu" -fp16: 1 pre_bn: 0 inference: 0 use_drop: 1 diff --git a/research/cv/FaceRecognition/default_config.yaml b/research/cv/FaceRecognition/default_config.yaml index 5cf5601226c520b6336d20f021955c152e79c469..22bc9b75f86190485954cbf4febd14e2b7442f8b 100644 --- a/research/cv/FaceRecognition/default_config.yaml +++ b/research/cv/FaceRecognition/default_config.yaml @@ -27,7 +27,6 @@ backbone: "r100" use_se: 1 emb_size: 512 act_type: "relu" -fp16: 1 pre_bn: 1 inference: 0 use_drop: 1 diff --git a/research/cv/FaceRecognition/inference_config.yaml b/research/cv/FaceRecognition/inference_config.yaml index a427b1910453141e87708df58ea10c19de4088f3..2d000b3e3ad3a18c44a534a995c3a63234ad6aee 100644 --- a/research/cv/FaceRecognition/inference_config.yaml +++ b/research/cv/FaceRecognition/inference_config.yaml @@ -29,7 +29,6 @@ backbone: "r100" use_se: 0 emb_size: 256 act_type: "relu" -fp16: 1 pre_bn: 0 inference: 1 use_drop: 0 diff --git a/research/cv/FaceRecognition/inference_config_cpu.yaml b/research/cv/FaceRecognition/inference_config_cpu.yaml index ad52c98049ffa42b36150b7ffdf15ee812ffcad9..f0b015600a7f7641d5076c5f47e7aaa8cf780b0a 100644 --- a/research/cv/FaceRecognition/inference_config_cpu.yaml +++ b/research/cv/FaceRecognition/inference_config_cpu.yaml @@ -29,7 +29,6 @@ backbone: "r100" use_se: 0 emb_size: 256 act_type: "relu" -fp16: 1 pre_bn: 0 inference: 1 use_drop: 0 diff --git a/research/cv/FaceRecognition/train.py b/research/cv/FaceRecognition/train.py index c5bf4acd5ec6f906170cfb4c023b198bd54c8750..6bea022c3bf244e1a8143605d83c33b6cfd09510 100644 --- a/research/cv/FaceRecognition/train.py +++ b/research/cv/FaceRecognition/train.py @@ -260,12 +260,11 @@ def run_train(): network_1 = DistributedHelper(_backbone, margin_fc_1) config.logger.info('DistributedHelper----out----') config.logger.info('network fp16----in----') - if config.fp16 == 1: - network_1.add_flags_recursive(fp16=True) + network_1.add_flags_recursive(fp16=True) config.logger.info('network fp16----out----') criterion_1 = get_loss(config) - if config.fp16 == 1 and config.model_parallel == 0: + if config.model_parallel == 0: criterion_1.add_flags_recursive(fp32=True) network_1 = load_pretrain(config, network_1) diff --git a/research/cv/centernet/src/decode.py b/research/cv/centernet/src/decode.py index d7291a73d8329857e6a69c9103c646bea4d9f44d..54c44f59e5829087f8296a8e523b2f5702035739 100644 --- a/research/cv/centernet/src/decode.py +++ b/research/cv/centernet/src/decode.py @@ -148,7 +148,6 @@ class GatherFeatureByInd(nn.Cell): self.reshape = ops.Reshape() self.enable_cpu_gatherd = enable_cpu_gatherd if self.enable_cpu_gatherd: - self.value = Tensor(2, mstype.int32) self.gather_nd = ops.GatherD() self.expand_dims = ops.ExpandDims() else: @@ -165,7 +164,7 @@ class GatherFeatureByInd(nn.Cell): # (b, J, K, N) index = self.expand_dims(ind, -1) index = self.tile(index, (1, 1, 1, N)) - feat = self.gather_nd(feat, self.value, index) + feat = self.gather_nd(feat, 2, index) else: ind = self.reshape(ind, (-1, 1)) ind_b = nn.Range(0, b * J, 1)() diff --git a/research/cv/centernet/src/utils.py b/research/cv/centernet/src/utils.py index b065dd97672ed514f456f08ab70856597bd74b2a..89b73d803c6ff2ee3a993ce997978f18e20b68ae 100644 --- a/research/cv/centernet/src/utils.py +++ b/research/cv/centernet/src/utils.py @@ -134,7 +134,6 @@ class GatherFeature(nn.Cell): self.reshape = ops.Reshape() self.enable_cpu_gather = enable_cpu_gather if self.enable_cpu_gather: - self.value = Tensor(1, mstype.int32) self.gather_nd = ops.GatherD() self.expand_dims = ops.ExpandDims() else: @@ -147,7 +146,7 @@ class GatherFeature(nn.Cell): # (b, N, c) index = self.expand_dims(ind, -1) index = self.tile(index, (1, 1, c)) - feat = self.gather_nd(feat, self.value, index) + feat = self.gather_nd(feat, 1, index) else: # (b, N)->(b*N, 1) b, N = self.shape(ind)