|
- # Copyright 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.
- # 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.
- # ============================================================================
- """
- export launch.
- Export checkpoint file into mindir models.
- """
-
- import argparse
- import numpy as np
- import mindspore as ms
- import mindspore.nn as nn
- from mindspore import Tensor, load_checkpoint, load_param_into_net, export
- from src.deepmar import Deep_Mar
-
- parser = argparse.ArgumentParser(description='reidentification')
- parser.add_argument('--ckpt_file', type=str, default='./checkpoint/Deepmar.ckpt')
- parser.add_argument('--file_name', type=str, default='Deepmar_mindir')
- parser.add_argument('--file_format', type=str, default='MINDIR')
-
- parser.add_argument('--height', type=int, default=224)
- parser.add_argument('--width', type=int, default=224)
- args = parser.parse_args()
-
-
- class Network(nn.Cell):
- def __init__(self, deepmar):
- super(Network, self).__init__()
- self.deepmar = deepmar
-
- def construct(self, x):
- output = self.deepmar(x)
- return output
-
-
- def export_deepmar():
- """ export_deepmar """
-
- model = Deep_Mar()
- net = Network(model)
- param_dict = load_checkpoint(args.ckpt_file)
- load_param_into_net(net, param_dict)
- input_arr = Tensor(np.zeros([1, 3, args.height, args.width]), ms.float32)
- export(net, input_arr, file_name=args.file_name, file_format=args.file_format)
- print("Model exported successfully, format: ", args.file_format)
-
-
- if __name__ == '__main__':
- export_deepmar()
|