!9055 add yolov3 export file and fix bert exprt bug
From: @yuzhenhua666 Reviewed-by: @liangchenghui Signed-off-by:pull/9055/MERGE
commit
9130660a2f
@ -0,0 +1,48 @@
|
|||||||
|
# Copyright 2020 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.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
import argparse
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
import mindspore as ms
|
||||||
|
from mindspore import context, Tensor
|
||||||
|
from mindspore.train.serialization import export, load_checkpoint, load_param_into_net
|
||||||
|
|
||||||
|
from src.yolo import YOLOV3DarkNet53
|
||||||
|
from src.config import ConfigYOLOV3DarkNet53
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='yolov3_darknet53 export')
|
||||||
|
parser.add_argument("--device_id", type=int, default=0, help="Device id")
|
||||||
|
parser.add_argument("--batch_size", type=int, default=1, help="batch size")
|
||||||
|
parser.add_argument("--ckpt_file", type=str, required=True, help="Checkpoint file path.")
|
||||||
|
parser.add_argument("--file_name", type=str, default="yolov3_darknet53.air", help="output file name.")
|
||||||
|
parser.add_argument('--file_format', type=str, choices=["AIR", "ONNX", "MINDIR"], default='AIR', help='file format')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend", device_id=args.device_id)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
network = YOLOV3DarkNet53(is_training=False)
|
||||||
|
|
||||||
|
param_dict = load_checkpoint(args.ckpt_file)
|
||||||
|
load_param_into_net(network, param_dict)
|
||||||
|
|
||||||
|
config = ConfigYOLOV3DarkNet53()
|
||||||
|
network.set_train(False)
|
||||||
|
|
||||||
|
shape = [args.batch_size, 3] + config.test_img_shape
|
||||||
|
input_data = Tensor(np.zeros(shape), ms.float32)
|
||||||
|
input_shape = Tensor(tuple(config.test_img_shape), ms.float32)
|
||||||
|
|
||||||
|
export(network, input_data, input_shape, file_name=args.file_name, file_format=args.file_format)
|
@ -0,0 +1,53 @@
|
|||||||
|
# Copyright 2020 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.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
import argparse
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
import mindspore as ms
|
||||||
|
from mindspore import context, Tensor
|
||||||
|
from mindspore.train.serialization import export, load_checkpoint, load_param_into_net
|
||||||
|
from mindspore.compression.quant import QuantizationAwareTraining
|
||||||
|
|
||||||
|
from src.yolo import YOLOV3DarkNet53
|
||||||
|
from src.config import ConfigYOLOV3DarkNet53
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='yolov3_darknet53_quant export')
|
||||||
|
parser.add_argument("--device_id", type=int, default=0, help="Device id")
|
||||||
|
parser.add_argument("--batch_size", type=int, default=1, help="batch size")
|
||||||
|
parser.add_argument("--ckpt_file", type=str, required=True, help="Checkpoint file path.")
|
||||||
|
parser.add_argument("--file_name", type=str, default="yolov3_darknet53_quant.mindir", help="output file name.")
|
||||||
|
parser.add_argument('--file_format', type=str, choices=["AIR", "ONNX", "MINDIR"], default='MINDIR', help='file format')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend", device_id=args.device_id)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
network = YOLOV3DarkNet53(is_training=False)
|
||||||
|
config = ConfigYOLOV3DarkNet53()
|
||||||
|
|
||||||
|
if config.quantization_aware:
|
||||||
|
quantizer = QuantizationAwareTraining(bn_fold=True, per_channel=[True, False], symmetric=[True, False])
|
||||||
|
network = quantizer.quantize(network)
|
||||||
|
|
||||||
|
param_dict = load_checkpoint(args.ckpt_file)
|
||||||
|
load_param_into_net(network, param_dict)
|
||||||
|
|
||||||
|
network.set_train(False)
|
||||||
|
|
||||||
|
shape = [args.batch_size, 3] + config.test_img_shape
|
||||||
|
input_data = Tensor(np.zeros(shape), ms.float32)
|
||||||
|
input_shape = Tensor(tuple(config.test_img_shape), ms.float32)
|
||||||
|
|
||||||
|
export(network, input_data, input_shape, file_name=args.file_name, file_format=args.file_format)
|
@ -0,0 +1,47 @@
|
|||||||
|
# Copyright 2020 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.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
import argparse
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
import mindspore as ms
|
||||||
|
from mindspore import context, Tensor
|
||||||
|
from mindspore.train.serialization import export, load_checkpoint, load_param_into_net
|
||||||
|
|
||||||
|
from src.yolov3 import yolov3_resnet18
|
||||||
|
from src.config import ConfigYOLOV3ResNet18
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='yolov3_resnet18 export')
|
||||||
|
parser.add_argument("--device_id", type=int, default=0, help="Device id")
|
||||||
|
parser.add_argument("--batch_size", type=int, default=1, help="batch size")
|
||||||
|
parser.add_argument("--ckpt_file", type=str, required=True, help="Checkpoint file path.")
|
||||||
|
parser.add_argument("--file_name", type=str, default="yolov3_resnet18.air", help="output file name.")
|
||||||
|
parser.add_argument('--file_format', type=str, choices=["AIR", "ONNX", "MINDIR"], default='AIR', help='file format')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend", device_id=args.device_id)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
config = ConfigYOLOV3ResNet18()
|
||||||
|
network = yolov3_resnet18(config)
|
||||||
|
|
||||||
|
param_dict = load_checkpoint(args.ckpt_file)
|
||||||
|
load_param_into_net(network, param_dict)
|
||||||
|
|
||||||
|
network.set_train(False)
|
||||||
|
|
||||||
|
shape = [args.batch_size, 3] + config.img_shape
|
||||||
|
input_data = Tensor(np.zeros(shape), ms.float32)
|
||||||
|
|
||||||
|
export(network, input_data, file_name=args.file_name, file_format=args.file_format)
|
@ -0,0 +1,56 @@
|
|||||||
|
# Copyright 2020 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.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
"""maskrcnn testing script."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
import numpy as np
|
||||||
|
from model_zoo.official.cv.maskrcnn.src.maskrcnn.mask_rcnn_r50 import Mask_Rcnn_Resnet50
|
||||||
|
from model_zoo.official.cv.maskrcnn.src.config import config
|
||||||
|
|
||||||
|
from mindspore import Tensor, context, export
|
||||||
|
|
||||||
|
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||||
|
|
||||||
|
@pytest.mark.level0
|
||||||
|
@pytest.mark.platform_arm_ascend_training
|
||||||
|
@pytest.mark.platform_x86_ascend_training
|
||||||
|
@pytest.mark.env_onecard
|
||||||
|
def test_maskrcnn_export():
|
||||||
|
"""
|
||||||
|
export maskrcnn air.
|
||||||
|
"""
|
||||||
|
net = Mask_Rcnn_Resnet50(config=config)
|
||||||
|
net.set_train(False)
|
||||||
|
|
||||||
|
bs = config.test_batch_size
|
||||||
|
|
||||||
|
img = Tensor(np.zeros([bs, 3, 768, 1280], np.float16))
|
||||||
|
img_metas = Tensor(np.zeros([bs, 4], np.float16))
|
||||||
|
gt_bboxes = Tensor(np.zeros([bs, 128, 4], np.float16))
|
||||||
|
gt_labels = Tensor(np.zeros([bs, 128], np.int32))
|
||||||
|
gt_num = Tensor(np.zeros([bs, 128], np.bool))
|
||||||
|
gt_mask = Tensor(np.zeros([bs, 128], np.bool))
|
||||||
|
|
||||||
|
input_data = [img, img_metas, gt_bboxes, gt_labels, gt_num, gt_mask]
|
||||||
|
file_name = "maskrcnn.air"
|
||||||
|
|
||||||
|
export(net, *input_data, file_name=file_name, file_format="AIR")
|
||||||
|
|
||||||
|
assert os.path.exists(file_name)
|
||||||
|
os.remove(file_name)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
test_maskrcnn_export()
|
Loading…
Reference in new issue