Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindinsight
提交
2f2f6a3f
M
mindinsight
项目概览
MindSpore
/
mindinsight
通知
8
Star
4
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindinsight
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2f2f6a3f
编写于
6月 06, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
6月 06, 2020
浏览文件
操作
浏览文件
下载
差异文件
!245 use json to save op mapping in mindconverter
Merge pull request !245 from quyongxiu1/br_0601_config_optim
上级
3abcb4a2
6adc58f0
变更
11
展开全部
显示空白变更内容
内联
并排
Showing
11 changed file
with
660 addition
and
312 deletion
+660
-312
mindinsight/mindconverter/config.py
mindinsight/mindconverter/config.py
+62
-290
mindinsight/mindconverter/enums.py
mindinsight/mindconverter/enums.py
+0
-22
mindinsight/mindconverter/funcs.py
mindinsight/mindconverter/funcs.py
+106
-0
mindinsight/mindconverter/mappings/f_mappings.json
mindinsight/mindconverter/mappings/f_mappings.json
+108
-0
mindinsight/mindconverter/mappings/nn_mappings.json
mindinsight/mindconverter/mappings/nn_mappings.json
+220
-0
mindinsight/mindconverter/mappings/tensor_dot_mappings.json
mindinsight/mindconverter/mappings/tensor_dot_mappings.json
+119
-0
mindinsight/mindconverter/mappings/torch_dot_mappings.json
mindinsight/mindconverter/mappings/torch_dot_mappings.json
+45
-0
mindinsight/mindconverter/ops/f_list.json
mindinsight/mindconverter/ops/f_list.json
+0
-0
mindinsight/mindconverter/ops/nn_list.json
mindinsight/mindconverter/ops/nn_list.json
+0
-0
mindinsight/mindconverter/ops/tensor_dot_list.json
mindinsight/mindconverter/ops/tensor_dot_list.json
+0
-0
mindinsight/mindconverter/ops/torch_dot_list.json
mindinsight/mindconverter/ops/torch_dot_list.json
+0
-0
未找到文件。
mindinsight/mindconverter/config.py
浏览文件 @
2f2f6a3f
此差异已折叠。
点击以展开。
mindinsight/mindconverter/enums.py
已删除
100644 → 0
浏览文件 @
3abcb4a2
# 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.
# ============================================================================
"""Enums."""
from
enum
import
Enum
class
RequriedType
(
Enum
):
"""If param is required"""
REQUIRED
=
1
UNREQUIRED
=
2
mindinsight/mindconverter/funcs.py
0 → 100644
浏览文件 @
2f2f6a3f
# 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.
# ============================================================================
"""funcs for gen_explicit_map"""
from
functools
import
partial
def
gen_explicit_map_f_max_pool2d
(
params_pt
,
args_pt
):
"""
Generate explicit_map for F.MaxPool2d.
Args:
params_pt (dict): Params for APIPt.
args_pt (dict): Args for APIPt.
Returns:
dict, map between frames.
"""
if
'padding'
in
args_pt
:
padding
=
args_pt
[
'padding'
]
else
:
padding
=
params_pt
[
'padding'
]
if
padding
.
strip
()
in
(
"0"
,
"(0,0)"
,
"(0, 0)"
):
padding
=
"'valid'"
else
:
padding
=
"'same'"
return
{
"padding"
:
padding
}
def
gen_explicit_map_nn_sequential
(
_
,
args_pt
):
"""
Generate explicit_map for nn.Sequential.
Args:
args_pt (dict): Args for APIPt.
Returns:
dict, map between frames.
"""
args
=
args_pt
[
'*args'
]
return
{
"*args"
:
"[{}]"
.
format
(
args
)}
def
gen_explicit_map_one_delta
(
params_pt
,
args_pt
,
k_ms
,
k_pt
):
"""
Generate explicit_map for which include mapping relationship is `1 - k_ms = k_pt`.
Args:
params_pt (dict): Params for APIPt.
args_pt (dict): Args for APIPt.
Returns:
dict, map between frames.
"""
value
=
args_pt
[
k_pt
]
if
k_pt
in
args_pt
else
params_pt
[
k_pt
]
value
=
value
.
strip
()
def
is_number
(
string
):
try
:
float
(
string
)
return
True
except
ValueError
:
return
False
if
is_number
(
value
):
return
{
k_ms
:
str
(
1
-
float
(
value
))}
return
{
k_ms
:
"1.0 - "
+
value
}
def
gen_explicit_map_nn_maxpool2d
(
params_pt
,
args_pt
):
"""
Generate explicit_map for nn.MaxPool2d.
Args:
params_pt (dict): Params for APIPt.
args_pt (dict): Args for APIPt.
Returns:
dict, map between frames.
"""
if
'padding'
in
args_pt
:
padding
=
args_pt
[
'padding'
]
else
:
padding
=
params_pt
[
'padding'
]
if
padding
.
strip
()
in
(
"0"
,
"(0,0)"
,
"(0, 0)"
):
pad_mode
=
"'valid'"
else
:
pad_mode
=
"'same'"
return
{
"pad_mode"
:
pad_mode
}
tensor_dot_view_gen_explicit_map
=
lambda
params_pt
,
args_pt
:
{
"shape"
:
"("
+
args_pt
[
"*shape"
]
+
",)"
}
tensor_dot_reshape_gen_explicit_map
=
lambda
params_pt
,
args_pt
:
{
"shape"
:
"("
+
args_pt
[
"*shape"
]
+
",)"
}
nn_conv2d_gen_explicit_map
=
lambda
params_pt
,
args_pt
:
{
"pad_mode"
:
"'pad'"
}
nn_batchnorm2d_gen_explicit_map
=
partial
(
gen_explicit_map_one_delta
,
k_ms
=
"momentum"
,
k_pt
=
"momentum"
)
nn_dropout_gen_explicit_map
=
partial
(
gen_explicit_map_one_delta
,
k_ms
=
"keep_prob"
,
k_pt
=
"p"
)
mindinsight/mindconverter/mappings/f_mappings.json
0 → 100644
浏览文件 @
2f2f6a3f
{
"F.avg_pool2d"
:
{
"ms_api"
:
[
"P.AvgPool"
,
{
"ksize"
:
1
,
"strides"
:
1
,
"padding"
:
"valid"
,
"input"
:
"REQUIRED"
},
[
"ksize"
,
"strides"
,
"padding"
]
],
"pt_api"
:
[
"F.avg_pool2d"
,
{
"input"
:
"REQUIRED"
,
"kernel_size"
:
"REQUIRED"
,
"stride"
:
null
,
"padding"
:
0
,
"dilation"
:
1
,
"ceil_mode"
:
false
,
"return_indices"
:
false
}
],
"ms2pt_mapping"
:
{
"ksize"
:
"kernel_size"
,
"strides"
:
"stride"
,
"input"
:
"input"
},
"gen_explicit_map"
:
"gen_explicit_map_f_max_pool2d"
},
"F.max_pool2d"
:
{
"ms_api"
:
[
"P.MaxPool"
,
{
"ksize"
:
1
,
"strides"
:
1
,
"padding"
:
"valid"
,
"input"
:
"REQUIRED"
},
[
"ksize"
,
"strides"
,
"padding"
]
],
"pt_api"
:
[
"F.max_pool2d"
,
{
"input"
:
"REQUIRED"
,
"kernel_size"
:
"REQUIRED"
,
"stride"
:
null
,
"padding"
:
0
,
"dilation"
:
1
,
"ceil_mode"
:
false
,
"return_indices"
:
false
}
],
"ms2pt_mapping"
:
{
"ksize"
:
"kernel_size"
,
"strides"
:
"stride"
,
"input"
:
"input"
},
"gen_explicit_map"
:
"gen_explicit_map_f_max_pool2d"
},
"F.relu"
:
{
"ms_api"
:
[
"P.ReLU"
,
{
"input"
:
"REQUIRED"
}
],
"pt_api"
:
[
"F.relu"
,
{
"input"
:
"REQUIRED"
,
"inplace"
:
false
}
],
"ms2pt_mapping"
:
{
"input"
:
"input"
},
"gen_explicit_map"
:
null
},
"F.relu6"
:
{
"ms_api"
:
[
"P.ReLU6"
,
{
"input"
:
"REQUIRED"
}
],
"pt_api"
:
[
"F.relu6"
,
{
"input"
:
"REQUIRED"
,
"inplace"
:
false
}
],
"ms2pt_mapping"
:
{
"input"
:
"input"
},
"gen_explicit_map"
:
null
}
}
\ No newline at end of file
mindinsight/mindconverter/mappings/nn_mappings.json
0 → 100644
浏览文件 @
2f2f6a3f
{
"nn.Dropout"
:
{
"ms_api"
:
[
"nn.Dropout"
,
{
"keep_prob"
:
0.5
,
"seed0"
:
0
,
"seed1"
:
0
,
"dtype"
:
"mstype.float32"
}
],
"pt_api"
:
[
"nn.Dropout"
,
{
"p"
:
0.5
,
"inplace"
:
false
}
],
"ms2pt_mapping"
:
{
"keep_prob"
:
"p"
},
"gen_explicit_map"
:
"nn_dropout_gen_explicit_map"
},
"nn.AvgPool2d"
:
{
"ms_api"
:
[
"nn.AvgPool2d"
,
{
"kernel_size"
:
1
,
"stride"
:
1
,
"pad_mode"
:
"valid"
}
],
"pt_api"
:
[
"nn.AvgPool2d"
,
{
"kernel_size"
:
"REQUIRED"
,
"stride"
:
null
,
"padding"
:
0
,
"dilation"
:
1
,
"return_indices"
:
false
,
"ceil_mode"
:
"False"
}
],
"ms2pt_mapping"
:
{
"kernel_size"
:
"kernel_size"
,
"stride"
:
"stride"
},
"gen_explicit_map"
:
"gen_explicit_map_nn_maxpool2d"
},
"nn.MaxPool2d"
:
{
"ms_api"
:
[
"nn.MaxPool2d"
,
{
"kernel_size"
:
1
,
"stride"
:
1
,
"pad_mode"
:
"valid"
}
],
"pt_api"
:
[
"nn.MaxPool2d"
,
{
"kernel_size"
:
"REQUIRED"
,
"stride"
:
null
,
"padding"
:
0
,
"dilation"
:
1
,
"return_indices"
:
false
,
"ceil_mode"
:
"False"
}
],
"ms2pt_mapping"
:
{
"kernel_size"
:
"kernel_size"
,
"stride"
:
"stride"
},
"gen_explicit_map"
:
"gen_explicit_map_nn_maxpool2d"
},
"nn.Linear"
:
{
"ms_api"
:
[
"nn.Dense"
,
{
"in_channels"
:
"REQUIRED"
,
"out_channels"
:
"REQUIRED"
,
"weight_init"
:
"normal"
,
"bias_init"
:
"zeros"
,
"has_bias"
:
true
,
"activation"
:
null
}
],
"pt_api"
:
[
"nn.Linear"
,
{
"in_features"
:
"REQUIRED"
,
"out_features"
:
"REQUIRED"
,
"bias"
:
true
}
],
"ms2pt_mapping"
:
{
"in_channels"
:
"in_features"
,
"out_channels"
:
"out_features"
,
"has_bias"
:
"bias"
}
},
"nn.ReLU6"
:
{
"ms_api"
:
[
"nn.ReLU6"
,
{}
],
"pt_api"
:
[
"nn.ReLU6"
,
{
"inplace"
:
false
}
],
"ms2pt_mapping"
:
{}
},
"nn.ReLU"
:
{
"ms_api"
:
[
"nn.ReLU"
,
{}
],
"pt_api"
:
[
"F.relu"
,
{
"inplace"
:
false
}
],
"ms2pt_mapping"
:
{}
},
"nn.BatchNorm2d"
:
{
"ms_api"
:
[
"nn.BatchNorm2d"
,
{
"num_features"
:
"REQUIRED"
,
"eps"
:
1e-05
,
"momentum"
:
0.9
,
"affine"
:
true
,
"gamma_init"
:
"ones"
,
"beta_init"
:
"zeros"
,
"moving_mean_init"
:
"zeros"
,
"moving_var_init"
:
"ones"
,
"use_batch_statistics"
:
true
}
],
"pt_api"
:
[
"nn.BatchNorm2d"
,
{
"num_features"
:
"REQUIRED"
,
"eps"
:
1e-05
,
"momentum"
:
0.1
,
"affine"
:
true
,
"track_running_stats"
:
true
}
],
"ms2pt_mapping"
:
{
"num_features"
:
"num_features"
,
"eps"
:
"eps"
,
"affine"
:
"affine"
,
"use_batch_statistics"
:
"track_running_stats"
},
"gen_explicit_map"
:
"nn_batchnorm2d_gen_explicit_map"
},
"nn.Conv2d"
:
{
"ms_api"
:
[
"nn.Conv2d"
,
{
"in_channels"
:
"REQUIRED"
,
"out_channels"
:
"REQUIRED"
,
"kernel_size"
:
"REQUIRED"
,
"stride"
:
1
,
"pad_mode"
:
"same"
,
"padding"
:
0
,
"dilation"
:
1
,
"group"
:
1
,
"has_bias"
:
false
,
"weight_init"
:
"normal"
,
"bias_init"
:
"zeros"
}
],
"pt_api"
:
[
"nn.Conv2d"
,
{
"in_channels"
:
"REQUIRED"
,
"out_channels"
:
"REQUIRED"
,
"kernel_size"
:
"REQUIRED"
,
"stride"
:
1
,
"padding"
:
0
,
"dilation"
:
1
,
"groups"
:
1
,
"bias"
:
true
,
"padding_mode"
:
"zeros"
}
],
"ms2pt_mapping"
:
{
"in_channels"
:
"in_channels"
,
"out_channels"
:
"out_channels"
,
"kernel_size"
:
"kernel_size"
,
"stride"
:
"stride"
,
"padding"
:
"padding"
,
"dilation"
:
"dilation"
,
"group"
:
"groups"
,
"has_bias"
:
"bias"
},
"gen_explicit_map"
:
"nn_conv2d_gen_explicit_map"
},
"nn.Sequential"
:
{
"ms_api"
:
[
"nn.SequentialCell"
,
{
"*args"
:
" REQUIRED"
}
],
"pt_api"
:
[
"nn.Sequential"
,
{
"*args"
:
" REQUIRED"
}
],
"export_key"
:
false
,
"gen_explicit_map"
:
"gen_explicit_map_nn_sequential"
}
}
\ No newline at end of file
mindinsight/mindconverter/mappings/tensor_dot_mappings.json
0 → 100644
浏览文件 @
2f2f6a3f
{
".view"
:
{
"ms_api"
:
[
"P.Reshape"
,
{
"x"
:
"REQUIRED"
,
"shape"
:
"REQUIRED"
}
],
"pt_api"
:
[
".view"
,
{
"*shape"
:
"REQUIRED"
}
],
"ms2pt_mapping"
:
{
"x"
:
"call_name"
},
"gen_explicit_map"
:
"tensor_dot_view_gen_explicit_map"
},
".size"
:
{
"ms_api"
:
[
"P.Shape"
,
{
"x"
:
"REQUIRED"
}
],
"pt_api"
:
[
".size"
,
{
"idx"
:
"REQUIRED"
}
],
"ms2pt_mapping"
:
{
"x"
:
"call_name"
}
},
".flatten"
:
{
"ms_api"
:
[
"P.Flatten"
,
{
"input"
:
"REQUIRED"
}
],
"pt_api"
:
[
".flatten"
,
{
"start_dim"
:
0
,
"end_dim"
:
-1
}
],
"ms2pt_mapping"
:
{
"input"
:
"call_name"
}
},
".reshape"
:
{
"ms_api"
:
[
"P.Reshape"
,
{
"x"
:
"REQUIRED"
,
"shape"
:
"REQUIRED"
}
],
"pt_api"
:
[
".reshape"
,
{
"*shape"
:
"REQUIRED"
}
],
"ms2pt_mapping"
:
{
"x"
:
"call_name"
},
"gen_explicit_map"
:
"tensor_dot_reshape_gen_explicit_map"
},
".mean"
:
{
"ms_api"
:
[
"P.ReduceMean"
,
{
"keep_dims"
:
false
,
"input"
:
"REQUIRED"
,
"axis"
:
[]
}
],
"pt_api"
:
[
".mean"
,
{
"dim"
:
null
,
"keepdim"
:
false
}
],
"ms2pt_mapping"
:
{
"keep_dims"
:
"keepdim"
,
"axis"
:
"dim"
,
"input"
:
"call_name"
}
},
".squeeze"
:
{
"ms_api"
:
[
"P.ReduceMean"
,
{
"input"
:
"REQUIRED"
,
"axis"
:
[]
},
[
"axis"
]
],
"pt_api"
:
[
".squeeze"
,
{
"dim"
:
null
}
],
"ms2pt_mapping"
:
{
"axis"
:
"dim"
,
"input"
:
"call_name"
}
}
}
\ No newline at end of file
mindinsight/mindconverter/mappings/torch_dot_mappings.json
0 → 100644
浏览文件 @
2f2f6a3f
{
"torch.flatten"
:
{
"ms_api"
:
[
"P.Flatten"
,
{
"input"
:
"REQUIRED"
}
],
"pt_api"
:
[
"torch.flatten"
,
{
"input"
:
"REQUIRED"
,
"start_dim"
:
0
,
"end_dim"
:
-1
}
],
"ms2pt_mapping"
:
{
"input"
:
"input"
}
},
"torch.cat"
:
{
"ms_api"
:
[
"P.Concat"
,
{
"axis"
:
0
,
"input"
:
"REQUIRED"
},
[
"axis"
]
],
"pt_api"
:
[
"torch.cat"
,
{
"tensors"
:
"REQUIRED"
,
"dim"
:
0
,
"out"
:
null
}
],
"ms2pt_mapping"
:
{
"input"
:
"tensors"
,
"axis"
:
"dim"
}
}
}
\ No newline at end of file
mindinsight/mindconverter/f_list.json
→
mindinsight/mindconverter/
ops/
f_list.json
浏览文件 @
2f2f6a3f
文件已移动
mindinsight/mindconverter/nn_list.json
→
mindinsight/mindconverter/
ops/
nn_list.json
浏览文件 @
2f2f6a3f
文件已移动
mindinsight/mindconverter/tensor_dot_list.json
→
mindinsight/mindconverter/
ops/
tensor_dot_list.json
浏览文件 @
2f2f6a3f
文件已移动
mindinsight/mindconverter/torch_dot_list.json
→
mindinsight/mindconverter/
ops/
torch_dot_list.json
浏览文件 @
2f2f6a3f
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录