!9865 add export file for bgcf,maskrcnn_mobilenetv1,deepfm,mobilenetv1
From: @yuzhenhua666 Reviewed-by: @linqingke,@oacjiewen Signed-off-by: @linqingkepull/9865/MERGE
commit
5f5ee0b4aa
@ -0,0 +1,51 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
from mindspore import Tensor, context, load_checkpoint, export
|
||||||
|
|
||||||
|
from src.maskrcnn_mobilenetv1.mask_rcnn_mobilenetv1 import Mask_Rcnn_Mobilenetv1
|
||||||
|
from src.config import config
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="maskrcnn mobilnetv1 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="maskrcnn_mobilenetv1", help="output file name.")
|
||||||
|
parser.add_argument("--file_format", type=str, choices=["AIR", "ONNX", "MINDIR"], default="AIR", help="file format")
|
||||||
|
parser.add_argument("--device_target", type=str, choices=["Ascend", "GPU", "CPU"], default="Ascend",
|
||||||
|
help="device target")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
context.set_context(mode=context.GRAPH_MODE, device_target=args.device_target, device_id=args.device_id)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
config.test_batch_size = args.batch_size
|
||||||
|
net = Mask_Rcnn_Mobilenetv1(config)
|
||||||
|
load_checkpoint(args.ckpt_file, net=net)
|
||||||
|
|
||||||
|
net.set_train(False)
|
||||||
|
|
||||||
|
img_data = Tensor(np.zeros([args.batch_size, 3, config.img_height, config.img_width], np.float16))
|
||||||
|
img_metas = Tensor(np.zeros([args.batch_size, 4], np.float16))
|
||||||
|
gt_bboxes = Tensor(np.zeros([args.batch_size, config.num_gts, 4], np.float16))
|
||||||
|
gt_labels = Tensor(np.zeros([args.batch_size, config.num_gts], np.int32))
|
||||||
|
gt_num = Tensor(np.zeros([args.batch_size, config.num_gts], np.bool))
|
||||||
|
gt_mask = Tensor(np.zeros([args.batch_size, 1, 1, 1], np.bool))
|
||||||
|
|
||||||
|
input_data = [img_data, img_metas, gt_bboxes, gt_labels, gt_num, gt_mask]
|
||||||
|
export(net, *input_data, file_name=args.file_name, file_format=args.file_format)
|
@ -0,0 +1,57 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
from mindspore import context, Tensor
|
||||||
|
from mindspore.train.serialization import export, load_checkpoint
|
||||||
|
|
||||||
|
from src.mobilenet_v1 import mobilenet_v1 as mobilenet
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="mobilenetv1 export")
|
||||||
|
parser.add_argument("--device_id", type=int, default=0, help="Device id")
|
||||||
|
parser.add_argument("--batch_size", type=int, default=256, help="batch size")
|
||||||
|
parser.add_argument("--ckpt_file", type=str, required=True, help="Checkpoint file path.")
|
||||||
|
parser.add_argument("--dataset", type=str, default="imagenet2012", help="Dataset, either cifar10 or imagenet2012")
|
||||||
|
parser.add_argument("--file_name", type=str, default="mobilenetv1", help="output file name.")
|
||||||
|
parser.add_argument("--file_format", type=str, choices=["AIR", "ONNX", "MINDIR"], default="AIR", help="file format")
|
||||||
|
parser.add_argument("--device_target", type=str, choices=["Ascend", "GPU", "CPU"], default="Ascend",
|
||||||
|
help="device target")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend", device_id=args.device_id)
|
||||||
|
|
||||||
|
if args.dataset == "cifar10":
|
||||||
|
from src.config import config1 as config
|
||||||
|
else:
|
||||||
|
from src.config import config2 as config
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
config.batch_size = args.batch_size
|
||||||
|
|
||||||
|
target = args.device_target
|
||||||
|
if target != "GPU":
|
||||||
|
context.set_context(device_id=args.device_id)
|
||||||
|
|
||||||
|
network = mobilenet(class_num=config.class_num)
|
||||||
|
|
||||||
|
param_dict = load_checkpoint(args.ckpt_file, net=network)
|
||||||
|
|
||||||
|
network.set_train(False)
|
||||||
|
|
||||||
|
input_data = Tensor(np.zeros([config.batch_size, 3, 224, 224]).astype(np.float32))
|
||||||
|
|
||||||
|
export(network, input_data, file_name=args.file_name, file_format=args.file_format)
|
@ -0,0 +1,65 @@
|
|||||||
|
# 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.
|
||||||
|
# ============================================================================
|
||||||
|
"""export ckpt to model"""
|
||||||
|
import argparse
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
from mindspore import context, Tensor
|
||||||
|
from mindspore.train.serialization import export, load_checkpoint
|
||||||
|
|
||||||
|
from src.bgcf import BGCF
|
||||||
|
from src.callback import ForwardBGCF
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="bgcf export")
|
||||||
|
parser.add_argument("--device_id", type=int, default=0, help="Device id")
|
||||||
|
parser.add_argument("--ckpt_file", type=str, required=True, help="Checkpoint file path.")
|
||||||
|
parser.add_argument("--file_name", type=str, default="bgcf", help="output file name.")
|
||||||
|
parser.add_argument("--file_format", type=str, choices=["AIR", "ONNX", "MINDIR"], default="AIR", help="file format")
|
||||||
|
parser.add_argument("--device_target", type=str, choices=["Ascend", "GPU", "CPU"], default="Ascend",
|
||||||
|
help="device target")
|
||||||
|
parser.add_argument("--input_dim", type=int, choices=[64, 128], default=64, help="embedding dimension")
|
||||||
|
parser.add_argument("--embedded_dimension", type=int, default=64, help="output embedding dimension")
|
||||||
|
parser.add_argument("--row_neighs", type=int, default=40, help="num of sampling neighbors in raw graph")
|
||||||
|
parser.add_argument("--gnew_neighs", type=int, default=20, help="num of sampling neighbors in sample graph")
|
||||||
|
parser.add_argument("--activation", type=str, default="tanh", choices=["relu", "tanh"], help="activation function")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
context.set_context(mode=context.GRAPH_MODE, device_target=args.device_target, device_id=args.device_id)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
num_user, num_item = 7068, 3570
|
||||||
|
|
||||||
|
network = BGCF([args.input_dim, num_user, num_item],
|
||||||
|
args.embedded_dimension,
|
||||||
|
args.activation,
|
||||||
|
[0.0, 0.0, 0.0],
|
||||||
|
num_user,
|
||||||
|
num_item,
|
||||||
|
args.input_dim)
|
||||||
|
|
||||||
|
load_checkpoint(args.ckpt_file, net=network)
|
||||||
|
|
||||||
|
forward_net = ForwardBGCF(network)
|
||||||
|
|
||||||
|
users = Tensor(np.zeros([num_user,]).astype(np.int32))
|
||||||
|
items = Tensor(np.zeros([num_item,]).astype(np.int32))
|
||||||
|
neg_items = Tensor(np.zeros([num_item, 1]).astype(np.int32))
|
||||||
|
u_test_neighs = Tensor(np.zeros([num_user, args.row_neighs]).astype(np.int32))
|
||||||
|
u_test_gnew_neighs = Tensor(np.zeros([num_user, args.gnew_neighs]).astype(np.int32))
|
||||||
|
i_test_neighs = Tensor(np.zeros([num_item, args.row_neighs]).astype(np.int32))
|
||||||
|
i_test_gnew_neighs = Tensor(np.zeros([num_item, args.gnew_neighs]).astype(np.int32))
|
||||||
|
|
||||||
|
input_data = [users, items, neg_items, u_test_neighs, u_test_gnew_neighs, i_test_neighs, i_test_gnew_neighs]
|
||||||
|
export(forward_net, *input_data, file_name=args.file_name, file_format=args.file_format)
|
@ -0,0 +1,50 @@
|
|||||||
|
# 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.
|
||||||
|
# ============================================================================
|
||||||
|
"""export ckpt to model"""
|
||||||
|
import argparse
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
from mindspore import context, Tensor
|
||||||
|
from mindspore.train.serialization import export, load_checkpoint
|
||||||
|
|
||||||
|
from src.deepfm import ModelBuilder
|
||||||
|
from src.config import DataConfig, ModelConfig, TrainConfig
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="deepfm export")
|
||||||
|
parser.add_argument("--device_id", type=int, default=0, help="Device id")
|
||||||
|
parser.add_argument("--batch_size", type=int, default=16000, help="batch size")
|
||||||
|
parser.add_argument("--ckpt_file", type=str, required=True, help="Checkpoint file path.")
|
||||||
|
parser.add_argument("--file_name", type=str, default="deepfm", help="output file name.")
|
||||||
|
parser.add_argument("--file_format", type=str, choices=["AIR", "ONNX", "MINDIR"], default="AIR", help="file format")
|
||||||
|
parser.add_argument("--device_target", type=str, choices=["Ascend", "GPU", "CPU"], default="Ascend",
|
||||||
|
help="device target")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
context.set_context(mode=context.GRAPH_MODE, device_target=args.device_target, device_id=args.device_id)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
data_config = DataConfig()
|
||||||
|
|
||||||
|
model_builder = ModelBuilder(ModelConfig, TrainConfig)
|
||||||
|
_, network = model_builder.get_train_eval_net()
|
||||||
|
|
||||||
|
load_checkpoint(args.ckpt_file, net=network)
|
||||||
|
|
||||||
|
batch_ids = Tensor(np.zeros([data_config.batch_size, data_config.data_field_size]).astype(np.int32))
|
||||||
|
batch_wts = Tensor(np.zeros([data_config.batch_size, data_config.data_field_size]).astype(np.float32))
|
||||||
|
labels = Tensor(np.zeros([data_config.batch_size, 1]).astype(np.float32))
|
||||||
|
|
||||||
|
input_data = [batch_ids, batch_wts, labels]
|
||||||
|
export(network, *input_data, file_name=args.file_name, file_format=args.file_format)
|
Loading…
Reference in new issue