pb 转 onnx
model_path_pb = "mmoe.pb"
model_path_onnx = "mmoe.onnx"
inputs = "input:0"
outputs = "functional_3/Year/Softmax:0,functional_3/ratings/Softmax:0"
desc = subprocess.Popen(
"python -m tf2onnx.convert --input {} --output {} --inputs {} --outputs {}".format(
model_path_pb, model_path_onnx, inputs, outputs
),
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
desc.communicate()
h5 转 onnx
model_path_h5 = "resnet101_keras.h5"
model_path_onnx = "resnet101_keras.onnx"
model = load_model(model_path_h5)
onnx_model = keras2onnx.convert_keras(model, model.name)
onnx.save_model(onnx_model, model_path_onnx)
torch 转 onnx
torch.onnx.export(
dlrm_model,
(
# input list
torch.tensor(np.load('./dlrm_dense_x.npy')),
torch.tensor(np.load('./dlrm_lS_o.npy')),
torch.tensor(np.load('./dlrm_lS_i.npy')),
),
"dlrm.onnx",
opset_version=11
)