Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Oneflow-Inc
oneflow_convert_tools
提交
9e266cab
O
oneflow_convert_tools
项目概览
Oneflow-Inc
/
oneflow_convert_tools
上一次同步 2 年多
通知
1
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oneflow_convert_tools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9e266cab
编写于
9月 18, 2021
作者:
B
BBuf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support max_pool2d bug
上级
69e0699a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
62 deletion
+32
-62
oneflow_onnx/oneflow2onnx/handlers/nn.py
oneflow_onnx/oneflow2onnx/handlers/nn.py
+31
-61
oneflow_onnx/onnx_wrapper.py
oneflow_onnx/onnx_wrapper.py
+1
-1
未找到文件。
oneflow_onnx/oneflow2onnx/handlers/nn.py
浏览文件 @
9e266cab
...
@@ -155,65 +155,35 @@ def _ConvConvertInputs(
...
@@ -155,65 +155,35 @@ def _ConvConvertInputs(
def
_AddPadding
(
ctx
,
node
,
kernel_shape
,
strides
,
dilations
=
None
,
spatial
=
2
):
def
_AddPadding
(
ctx
,
node
,
kernel_shape
,
strides
,
dilations
=
None
,
spatial
=
2
):
padding
=
node
.
attrs
.
get
(
"padding"
)
if
dilations
is
None
:
if
padding
:
dilations
=
[
1
]
*
spatial
*
2
if
dilations
is
None
:
pads
=
[
0
]
*
spatial
*
2
dilations
=
[
1
]
*
spatial
*
2
input_shape
=
ctx
.
get_shape
(
node
.
input_tensor_names
[
0
])
if
padding
==
"same"
:
output_shape
=
ctx
.
get_shape
(
node
.
output_tensor_names
[
0
])
padding
=
"same_lower"
# check if the input shape is valid
if
padding
in
[
"same_lower"
,
"same_upper"
]:
if
len
(
input_shape
)
!=
len
(
pads
):
pads
=
[
0
]
*
spatial
*
2
logger
.
error
(
input_shape
=
ctx
.
get_shape
(
node
.
input_tensor_names
[
0
])
"node %s input needs to be rank %d, is %d"
,
output_shape
=
ctx
.
get_shape
(
node
.
output_tensor_names
[
0
])
node
.
name
,
# check if the input shape is valid
len
(
pads
),
if
len
(
input_shape
)
!=
len
(
pads
):
len
(
input_shape
),
logger
.
error
(
)
"node %s input needs to be rank %d, is %d"
,
# transpose shape to nchw
node
.
name
,
if
node
.
is_nhwc
():
len
(
pads
),
input_shape
=
_SpatialMap
(
input_shape
,
constants
.
NHWC_TO_NCHW
)
len
(
input_shape
),
output_shape
=
_SpatialMap
(
output_shape
,
constants
.
NHWC_TO_NCHW
)
)
for
i
in
range
(
spatial
):
# transpose shape to nchw
pad
=
(
if
node
.
is_nhwc
():
(
output_shape
[
i
+
2
]
-
1
)
*
strides
[
i
]
input_shape
=
_SpatialMap
(
input_shape
,
constants
.
NHWC_TO_NCHW
)
+
dilations
[
i
]
*
(
kernel_shape
[
i
]
-
1
)
output_shape
=
_SpatialMap
(
output_shape
,
constants
.
NHWC_TO_NCHW
)
+
1
# calculate pads
-
input_shape
[
i
+
2
]
if
any
(
)
input_shape
[
i
+
2
]
==
-
1
or
output_shape
[
i
+
2
]
==
-
1
pad
=
max
(
pad
,
0
)
for
i
in
range
(
spatial
)
pads
[
i
+
spatial
]
=
pad
//
2
):
pads
[
i
]
=
pad
-
pad
//
2
logger
.
debug
(
node
.
attrs
[
"pads"
]
=
pads
"node %s has unknown dim for pads calculation, fallback to auto_pad: "
"input_shape=%s, output_shape=%s"
,
node
.
name
,
input_shape
,
output_shape
,
)
if
padding
==
"same_lower"
:
node
.
attrs
[
"auto_pad"
]
=
"SAME_LOWER"
else
:
node
.
attrs
[
"auto_pad"
]
=
"SAME_UPPER"
else
:
for
i
in
range
(
spatial
):
pad
=
(
(
output_shape
[
i
+
2
]
-
1
)
*
strides
[
i
]
+
dilations
[
i
]
*
(
kernel_shape
[
i
]
-
1
)
+
1
-
input_shape
[
i
+
2
]
)
pad
=
max
(
pad
,
0
)
if
padding
==
"same_lower"
:
pads
[
i
+
spatial
]
=
pad
//
2
pads
[
i
]
=
pad
-
pad
//
2
else
:
pads
[
i
]
=
pad
//
2
pads
[
i
+
spatial
]
=
pad
-
pad
//
2
node
.
attrs
[
"pads"
]
=
pads
elif
padding
==
"valid"
:
pass
else
:
raise
ValueError
(
"invalid padding value: "
+
padding
)
def
conv_dims_attr
(
node
,
name
,
new_name
=
None
):
def
conv_dims_attr
(
node
,
name
,
new_name
=
None
):
...
@@ -285,8 +255,8 @@ class PoolOp:
...
@@ -285,8 +255,8 @@ class PoolOp:
# T Y = MaxPool(T X, @AttrType.STRING auto_pad, @AttrType.INTS kernel_shape, @AttrType.INTS pads,
# T Y = MaxPool(T X, @AttrType.STRING auto_pad, @AttrType.INTS kernel_shape, @AttrType.INTS pads,
# @AttrType.INTS strides)
# @AttrType.INTS strides)
if
len
(
node
.
input_tensor_names
)
<
3
:
if
len
(
node
.
input_tensor_names
)
<
3
:
kernel_shape_flow
=
node
.
attrs
[
"
poo
l_size"
]
kernel_shape_flow
=
node
.
attrs
[
"
kerne
l_size"
]
strides_flow
=
node
.
attrs
[
"stride
s
"
]
strides_flow
=
node
.
attrs
[
"stride"
]
else
:
else
:
kernel_shape_flow
=
node
.
input_nodes
[
1
].
get_tensor_value
()
kernel_shape_flow
=
node
.
input_nodes
[
1
].
get_tensor_value
()
strides_flow
=
node
.
input_nodes
[
2
].
get_tensor_value
()
strides_flow
=
node
.
input_nodes
[
2
].
get_tensor_value
()
...
...
oneflow_onnx/onnx_wrapper.py
浏览文件 @
9e266cab
...
@@ -859,7 +859,7 @@ class Graph(object):
...
@@ -859,7 +859,7 @@ class Graph(object):
tensor_name
=
node
.
output_tensor_names
[
0
]
tensor_name
=
node
.
output_tensor_names
[
0
]
# TODO(daquexian): node.output_tensor_names[0] is "node_name/output_name", so this pathjoin doesn't work
# TODO(daquexian): node.output_tensor_names[0] is "node_name/output_name", so this pathjoin doesn't work
# on windows (where path separator is "\")
# on windows (where path separator is "\")
path
=
pathjoin
(
self
.
_model_save_dir
,
node
.
output_tensor_names
[
0
][
2
:]
)
path
=
pathjoin
(
self
.
_model_save_dir
,
"."
.
join
(
node
.
output_tensor_names
[
0
].
split
(
"."
)[
1
:])
)
tensor_value
=
np
.
fromfile
(
tensor_value
=
np
.
fromfile
(
path
,
dtype
=
util
.
Onnx2NumpyDtype
(
self
.
get_dtype
(
tensor_name
))
path
,
dtype
=
util
.
Onnx2NumpyDtype
(
self
.
get_dtype
(
tensor_name
))
).
reshape
(
self
.
get_shape
(
tensor_name
))
).
reshape
(
self
.
get_shape
(
tensor_name
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录