Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Oneflow-Inc
OneFlow-Benchmark
提交
ba9492a4
O
OneFlow-Benchmark
项目概览
Oneflow-Inc
/
OneFlow-Benchmark
上一次同步 2 年多
通知
1
Star
92
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
OneFlow-Benchmark
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ba9492a4
编写于
6月 23, 2021
作者:
B
BBuf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix export onnx script bug
上级
2489e500
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
10 addition
and
10 deletion
+10
-10
Classification/cnns/resnet_to_onnx.py
Classification/cnns/resnet_to_onnx.py
+10
-10
未找到文件。
Classification/cnns/resnet_to_onnx.py
浏览文件 @
ba9492a4
"""
"""
Copyright 2020 The OneFlow Authors. All rights reserved.
Copyright 2020 The OneFlow Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -22,8 +19,6 @@ from typing import Callable, Text
...
@@ -22,8 +19,6 @@ from typing import Callable, Text
import
numpy
as
np
import
numpy
as
np
import
oneflow
as
flow
import
oneflow
as
flow
import
oneflow_onnx
from
oneflow_onnx.oneflow2onnx.util
import
convert_to_onnx_and_check
import
oneflow.typing
as
tp
import
oneflow.typing
as
tp
import
onnx
import
onnx
import
onnxruntime
as
ort
import
onnxruntime
as
ort
...
@@ -31,6 +26,7 @@ import onnxruntime as ort
...
@@ -31,6 +26,7 @@ import onnxruntime as ort
from
resnet_model
import
resnet50
from
resnet_model
import
resnet50
import
config
as
configs
import
config
as
configs
from
imagenet1000_clsidx_to_labels
import
clsidx_2_labels
from
imagenet1000_clsidx_to_labels
import
clsidx_2_labels
from
oneflow_onnx.oneflow2onnx.util
import
export_onnx_model
parser
=
configs
.
get_parser
()
parser
=
configs
.
get_parser
()
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
...
@@ -94,9 +90,15 @@ def oneflow_to_onnx(
...
@@ -94,9 +90,15 @@ def oneflow_to_onnx(
assert
os
.
path
.
exists
(
flow_weights_path
)
and
os
.
path
.
isdir
(
onnx_model_dir
)
assert
os
.
path
.
exists
(
flow_weights_path
)
and
os
.
path
.
isdir
(
onnx_model_dir
)
onnx_model_path
=
os
.
path
.
join
(
onnx_model_path
=
os
.
path
.
join
(
onnx_model_dir
,
os
.
path
.
basename
(
flow_weights_path
)
+
".onnx"
onnx_model_dir
,
"model.onnx"
)
export_onnx_model
(
job_func
,
flow_weight_dir
=
flow_weights_path
,
onnx_model_path
=
onnx_model_dir
,
opset
=
11
,
external_data
=
external_data
,
)
)
convert_to_onnx_and_check
(
job_func
,
flow_weight_dir
=
flow_weights_path
,
onnx_model_path
=
onnx_model_path
,
opset
=
11
,
external_data
=
external_data
)
print
(
"Convert to onnx success! >> "
,
onnx_model_path
)
print
(
"Convert to onnx success! >> "
,
onnx_model_path
)
return
onnx
.
load_model
(
onnx_model_path
)
return
onnx
.
load_model
(
onnx_model_path
)
...
@@ -116,8 +118,6 @@ if __name__ == "__main__":
...
@@ -116,8 +118,6 @@ if __name__ == "__main__":
# set up your model path
# set up your model path
flow_weights_path
=
"resnet_v15_of_best_model_val_top1_77318"
flow_weights_path
=
"resnet_v15_of_best_model_val_top1_77318"
onnx_model_dir
=
"onnx/model"
onnx_model_dir
=
"onnx/model"
flow
.
train
.
CheckPoint
().
init
()
flow
.
load_variables
(
flow
.
checkpoint
.
get
(
flow_weights_path
))
flow
.
load_variables
(
flow
.
checkpoint
.
get
(
flow_weights_path
))
...
@@ -130,4 +130,4 @@ if __name__ == "__main__":
...
@@ -130,4 +130,4 @@ if __name__ == "__main__":
are_equal
,
onnx_res
=
check_equality
(
InferenceNet
,
onnx_model
,
image_path
)
are_equal
,
onnx_res
=
check_equality
(
InferenceNet
,
onnx_model
,
image_path
)
clsidx_onnx
=
onnx_res
.
argmax
()
clsidx_onnx
=
onnx_res
.
argmax
()
print
(
"Are the results equal? {}"
.
format
(
"Yes"
if
are_equal
else
"No"
))
print
(
"Are the results equal? {}"
.
format
(
"Yes"
if
are_equal
else
"No"
))
print
(
"Class: {}; score: {}"
.
format
(
clsidx_2_labels
[
clsidx_onnx
],
onnx_res
.
max
()))
print
(
"Class: {}; score: {}"
.
format
(
clsidx_2_labels
[
clsidx_onnx
],
onnx_res
.
max
()))
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录