Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
3d26fe4d
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3d26fe4d
编写于
8月 27, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 27, 2020
浏览文件
操作
浏览文件
下载
差异文件
!5220 onnx net and fix bug
Merge pull request !5220 from 徐安越/master
上级
9f131702
7c223f2c
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
96 addition
and
34 deletion
+96
-34
mindspore/lite/schema/ops.fbs
mindspore/lite/schema/ops.fbs
+1
-0
mindspore/lite/src/ops/gather.cc
mindspore/lite/src/ops/gather.cc
+0
-4
mindspore/lite/src/ops/shape.cc
mindspore/lite/src/ops/shape.cc
+1
-0
mindspore/lite/src/ops/slice.cc
mindspore/lite/src/ops/slice.cc
+26
-13
mindspore/lite/src/ops/slice.h
mindspore/lite/src/ops/slice.h
+8
-0
mindspore/lite/src/populate_parameter.cc
mindspore/lite/src/populate_parameter.cc
+2
-2
mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc
mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc
+10
-1
mindspore/lite/tools/converter/converter_flags.cc
mindspore/lite/tools/converter/converter_flags.cc
+6
-2
mindspore/lite/tools/converter/legacy_optimizer/fusion/mul_add_fusion_pass.cc
.../converter/legacy_optimizer/fusion/mul_add_fusion_pass.cc
+2
-1
mindspore/lite/tools/converter/parser/onnx/onnx_slice_parser.cc
...ore/lite/tools/converter/parser/onnx/onnx_slice_parser.cc
+24
-8
mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc
...lite/tools/converter/parser/tflite/tflite_slice_parser.cc
+6
-1
mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc
...re/lite/tools/optimizer/fusion/constant_folding_fusion.cc
+10
-2
未找到文件。
mindspore/lite/schema/ops.fbs
浏览文件 @
3d26fe4d
...
...
@@ -457,6 +457,7 @@ table Min {
table Slice {
format: Format = 0;
axes: [int];
begin: [int];
size: [int];
}
...
...
mindspore/lite/src/ops/gather.cc
浏览文件 @
3d26fe4d
...
...
@@ -65,10 +65,6 @@ int Gather::InferShape(std::vector<tensor::Tensor *> inputs_, std::vector<tensor
}
auto
indices_shape
=
indices
->
shape
();
int
indices_rank
=
indices_shape
.
size
();
if
(
indices_rank
<
batch_dims
+
1
)
{
MS_LOG
(
ERROR
)
<<
"input[1]'s rank is less than batchDim + 1"
;
return
RET_ERROR
;
}
if
(
batch_dims
!=
0
)
{
MS_LOG
(
ERROR
)
<<
"batchDims "
<<
batch_dims
<<
" != 0, which is not support"
;
return
RET_ERROR
;
...
...
mindspore/lite/src/ops/shape.cc
浏览文件 @
3d26fe4d
...
...
@@ -38,6 +38,7 @@ int Shape::InferShape(std::vector<tensor::Tensor *> inputs_, std::vector<tensor:
auto
in_tensor
=
inputs_
.
front
();
auto
out_tensor
=
outputs_
.
front
();
out_tensor
->
set_data_type
(
kNumberTypeInt32
);
out_tensor
->
SetFormat
(
schema
::
Format_NHWC
);
if
(
!
GetInferFlag
())
{
return
RET_OK
;
}
...
...
mindspore/lite/src/ops/slice.cc
浏览文件 @
3d26fe4d
...
...
@@ -29,6 +29,7 @@ constexpr int kSliceOutputNum = 1;
int
Slice
::
GetFormat
()
const
{
return
this
->
primitive_
->
value
.
AsSlice
()
->
format
;
}
std
::
vector
<
int
>
Slice
::
GetBegin
()
const
{
return
this
->
primitive_
->
value
.
AsSlice
()
->
begin
;
}
std
::
vector
<
int
>
Slice
::
GetSize
()
const
{
return
this
->
primitive_
->
value
.
AsSlice
()
->
size
;
}
std
::
vector
<
int
>
Slice
::
GetAxes
()
const
{
return
this
->
primitive_
->
value
.
AsSlice
()
->
axes
;
}
void
Slice
::
SetFormat
(
int
format
)
{
this
->
primitive_
->
value
.
AsSlice
()
->
format
=
(
schema
::
Format
)
format
;
}
void
Slice
::
SetBegin
(
const
std
::
vector
<
int
>
&
begin
)
{
this
->
primitive_
->
value
.
AsSlice
()
->
begin
=
begin
;
}
...
...
@@ -45,9 +46,14 @@ std::vector<int> Slice::GetSize() const {
auto
fb_vector
=
this
->
primitive_
->
value_as_Slice
()
->
size
();
return
std
::
vector
<
int
>
(
fb_vector
->
begin
(),
fb_vector
->
end
());
}
std
::
vector
<
int
>
Slice
::
GetAxes
()
const
{
auto
fb_vector
=
this
->
primitive_
->
value_as_Slice
()
->
axes
();
return
std
::
vector
<
int
>
(
fb_vector
->
begin
(),
fb_vector
->
end
());
}
#endif
std
::
vector
<
int
>
Slice
::
GetPostProcessBegin
()
const
{
return
this
->
begin
;
}
std
::
vector
<
int
>
Slice
::
GetPostProcessSize
()
const
{
return
this
->
size
;
}
int
Slice
::
InferShape
(
std
::
vector
<
lite
::
tensor
::
Tensor
*>
inputs
,
std
::
vector
<
lite
::
tensor
::
Tensor
*>
outputs
)
{
MS_ASSERT
(
this
->
primitive_
!=
nullptr
);
if
(
inputs
.
size
()
!=
kSliceInputNum
||
outputs
.
size
()
!=
kSliceOutputNum
)
{
...
...
@@ -61,30 +67,37 @@ int Slice::InferShape(std::vector<lite::tensor::Tensor *> inputs, std::vector<li
return
RET_OK
;
}
auto
input_shape
=
input
->
shape
();
std
::
vector
<
int32_t
>
slice_begin
(
GetBegin
().
begin
(),
GetBegin
().
end
());
std
::
vector
<
int32_t
>
slice_size
(
GetSize
().
begin
(),
GetSize
().
end
());
std
::
vector
<
int32_t
>
slice_begin
(
GetBegin
());
std
::
vector
<
int32_t
>
slice_size
(
GetSize
());
std
::
vector
<
int32_t
>
slice_axes
(
GetAxes
());
std
::
vector
<
int32_t
>
output_shape
(
input_shape
.
size
());
begin
.
assign
(
input_shape
.
size
(),
0
);
size
.
assign
(
input_shape
.
size
(),
-
1
);
for
(
size_t
i
=
0
;
i
<
slice_axes
.
size
();
++
i
)
{
begin
[
slice_axes
[
i
]]
=
slice_begin
[
i
];
size
[
slice_axes
[
i
]]
=
slice_size
[
i
];
}
for
(
size_t
i
=
0
;
i
<
input_shape
.
size
();
++
i
)
{
if
(
s
lice_size
[
i
]
<
0
&&
slice_
size
[
i
]
!=
-
1
)
{
MS_LOG
(
ERROR
)
<<
"Invalid size input!size["
<<
i
<<
"]="
<<
s
lice_s
ize
[
i
];
if
(
s
ize
[
i
]
<
0
&&
size
[
i
]
!=
-
1
)
{
MS_LOG
(
ERROR
)
<<
"Invalid size input!size["
<<
i
<<
"]="
<<
size
[
i
];
return
RET_PARAM_INVALID
;
}
if
(
slice_
begin
[
i
]
<
0
)
{
MS_LOG
(
ERROR
)
<<
"Invalid begin input "
<<
slice_
begin
[
i
]
<<
" which should be >= 0"
;
if
(
begin
[
i
]
<
0
)
{
MS_LOG
(
ERROR
)
<<
"Invalid begin input "
<<
begin
[
i
]
<<
" which should be >= 0"
;
return
RET_PARAM_INVALID
;
}
if
(
input_shape
[
i
]
<=
slice_
begin
[
i
])
{
MS_LOG
(
ERROR
)
<<
"Invalid begin input!begin["
<<
i
<<
"]="
<<
slice_
begin
[
i
]
if
(
input_shape
[
i
]
<=
begin
[
i
])
{
MS_LOG
(
ERROR
)
<<
"Invalid begin input!begin["
<<
i
<<
"]="
<<
begin
[
i
]
<<
" which should be <= "
<<
input_shape
[
i
];
return
RET_PARAM_INVALID
;
}
if
(
s
lice_size
[
i
]
>
(
input_shape
[
i
]
-
slice_
begin
[
i
]))
{
MS_LOG
(
ERROR
)
<<
"Invalid size input "
<<
s
lice_s
ize
[
i
]
<<
" which should be <= "
<<
input_shape
[
i
]
-
slice_
begin
[
i
];
if
(
s
ize
[
i
]
>
(
input_shape
[
i
]
-
begin
[
i
]))
{
MS_LOG
(
ERROR
)
<<
"Invalid size input "
<<
size
[
i
]
<<
" which should be <= "
<<
input_shape
[
i
]
-
begin
[
i
];
return
RET_PARAM_INVALID
;
}
output_shape
[
i
]
=
s
lice_size
[
i
]
<
0
?
input_shape
[
i
]
-
slice_begin
[
i
]
:
slice_
size
[
i
];
output_shape
[
i
]
=
s
ize
[
i
]
<
0
?
input_shape
[
i
]
-
begin
[
i
]
:
size
[
i
];
}
outputs
[
0
]
->
set_shape
(
output_shape
);
...
...
mindspore/lite/src/ops/slice.h
浏览文件 @
3d26fe4d
...
...
@@ -41,6 +41,14 @@ class Slice : public PrimitiveC {
int
GetFormat
()
const
;
std
::
vector
<
int
>
GetBegin
()
const
;
std
::
vector
<
int
>
GetSize
()
const
;
std
::
vector
<
int
>
GetAxes
()
const
;
// due to difference between tflite and onnx, when inferring shape, construct new parameters of begin and size.
// when running graph, we need to obtain new begins and sizes using the two function as below.
std
::
vector
<
int
>
GetPostProcessBegin
()
const
;
std
::
vector
<
int
>
GetPostProcessSize
()
const
;
protected:
std
::
vector
<
int
>
begin
=
{
0
};
std
::
vector
<
int
>
size
=
{
-
1
};
};
}
// namespace lite
}
// namespace mindspore
...
...
mindspore/lite/src/populate_parameter.cc
浏览文件 @
3d26fe4d
...
...
@@ -1010,8 +1010,8 @@ OpParameter *PopulateSliceParameter(const mindspore::lite::PrimitiveC *primitive
memset
(
slice_param
,
0
,
sizeof
(
SliceParameter
));
auto
param
=
reinterpret_cast
<
mindspore
::
lite
::
Slice
*>
(
const_cast
<
mindspore
::
lite
::
PrimitiveC
*>
(
primitive
));
slice_param
->
op_parameter_
.
type_
=
primitive
->
Type
();
auto
param_begin
=
param
->
GetBegin
();
auto
param_size
=
param
->
GetSize
();
auto
param_begin
=
param
->
Get
PostProcess
Begin
();
auto
param_size
=
param
->
Get
PostProcess
Size
();
if
(
param_begin
.
size
()
!=
param_size
.
size
())
{
free
(
slice_param
);
return
nullptr
;
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc
浏览文件 @
3d26fe4d
...
...
@@ -20,6 +20,7 @@
#include "nnacl/fp32/slice.h"
#include "include/errorcode.h"
#include "src/runtime/runtime_api.h"
#include "src/ops/slice.h"
using
mindspore
::
lite
::
KernelRegistrar
;
using
mindspore
::
lite
::
RET_ERROR
;
...
...
@@ -40,7 +41,15 @@ int SliceLaunch(void *cdata, int task_id) {
}
// namespace
int
SliceCPUKernel
::
ReSize
()
{
auto
*
param
=
reinterpret_cast
<
SliceParameter
*>
(
op_parameter_
);
auto
primitive_slice
=
reinterpret_cast
<
const
mindspore
::
lite
::
Slice
*>
(
primitive_
);
auto
begin
=
primitive_slice
->
GetPostProcessBegin
();
auto
size
=
primitive_slice
->
GetPostProcessSize
();
auto
param
=
reinterpret_cast
<
SliceParameter
*>
(
op_parameter_
);
param
->
param_length_
=
in_tensors_
[
0
]
->
shape
().
size
();
for
(
int
i
=
0
;
i
<
param
->
param_length_
;
++
i
)
{
param
->
begin_
[
i
]
=
begin
[
i
];
param
->
size_
[
i
]
=
size
[
i
];
}
auto
input_shape
=
in_tensors_
[
0
]
->
shape
();
if
(
static_cast
<
int
>
(
input_shape
.
size
())
!=
param
->
param_length_
)
{
MS_LOG
(
ERROR
)
<<
"Input begin's lenth "
<<
param
->
param_length_
<<
"is not equal to input shape size "
...
...
mindspore/lite/tools/converter/converter_flags.cc
浏览文件 @
3d26fe4d
...
...
@@ -24,8 +24,8 @@ namespace lite {
namespace
converter
{
Flags
::
Flags
()
{
AddFlag
(
&
Flags
::
fmkIn
,
"fmk"
,
"Input model framework type. TFLITE | CAFFE | MS"
,
""
);
AddFlag
(
&
Flags
::
modelFile
,
"modelFile"
,
"Input model file path. TFLITE: *.tflite | CAFFE: *.prototxt | MS: *.mindir"
,
""
);
AddFlag
(
&
Flags
::
modelFile
,
"modelFile"
,
"
Input model file path. TFLITE: *.tflite | CAFFE: *.prototxt | MS: *.mindir | ONNX: *.onnx"
,
"
"
);
AddFlag
(
&
Flags
::
outputFile
,
"outputFile"
,
"Output model file path. Will add .ms automatically"
,
""
);
AddFlag
(
&
Flags
::
weightFile
,
"weightFile"
,
"Input model weight file path. Needed when fmk is CAFFE. CAFFE: *.caffemodel"
,
""
);
...
...
@@ -41,6 +41,10 @@ Flags::Flags() {
}
int
Flags
::
Init
(
int
argc
,
const
char
**
argv
)
{
if
(
argc
==
1
)
{
std
::
cout
<<
this
->
Usage
()
<<
std
::
endl
;
return
RET_SUCCESS_EXIT
;
}
Option
<
std
::
string
>
err
=
this
->
ParseFlags
(
argc
,
argv
);
if
(
err
.
IsSome
())
{
...
...
mindspore/lite/tools/converter/legacy_optimizer/fusion/mul_add_fusion_pass.cc
浏览文件 @
3d26fe4d
...
...
@@ -121,7 +121,8 @@ STATUS MulAddFusionPass::AddNewScaleNode(MetaGraphT *graph, const std::unique_pt
return
RET_ERROR
;
}
// NHWC
scaleParam
->
axis
=
-
1
;
int
shape_size
=
graph
->
allTensors
.
at
(
addBiasIndex
)
->
dims
.
size
();
scaleParam
->
axis
=
0
-
shape_size
;
mulNode
->
primitive
->
value
.
value
=
scaleParam
.
release
();
mulNode
->
inputIndex
.
push_back
(
addBiasIndex
);
if
(
addNode
->
primitive
->
value
.
AsAdd
()
->
activationType
!=
ActivationType_NO_ACTIVATION
)
{
...
...
mindspore/lite/tools/converter/parser/onnx/onnx_slice_parser.cc
浏览文件 @
3d26fe4d
...
...
@@ -38,22 +38,38 @@ STATUS OnnxSliceParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::No
return
RET_NULL_PTR
;
}
std
::
vector
<
int
>
axes
;
std
::
vector
<
int
>
starts
;
std
::
vector
<
int
>
ends
;
for
(
const
auto
&
onnx_node_attr
:
onnx_node
.
attribute
())
{
const
auto
&
attribute_name
=
onnx_node_attr
.
name
();
if
(
attribute_name
==
"starts"
)
{
const
int
size
=
onnx_node_attr
.
ints_size
();
MS_LOG
(
INFO
)
<<
"SLICE starts size "
<<
size
;
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
attr
->
begin
.
emplace_back
(
static_cast
<
int32_t
>
(
onnx_node_attr
.
ints
(
i
)));
const
int
num
=
onnx_node_attr
.
ints_size
();
starts
.
clear
();
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
starts
.
push_back
(
static_cast
<
int
>
(
onnx_node_attr
.
ints
()[
i
]));
}
}
else
if
(
attribute_name
==
"axes"
)
{
const
int
num
=
onnx_node_attr
.
ints_size
();
axes
.
clear
();
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
axes
.
push_back
(
static_cast
<
int
>
(
onnx_node_attr
.
ints
()[
i
]));
}
}
else
if
(
attribute_name
==
"ends"
)
{
const
int
size
=
onnx_node_attr
.
ints_size
();
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
attr
->
size
.
emplace_back
(
static_cast
<
int32_t
>
(
onnx_node_attr
.
ints
(
i
)));
const
int
num
=
onnx_node_attr
.
ints_size
();
ends
.
clear
();
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
ends
.
push_back
(
static_cast
<
int
>
(
onnx_node_attr
.
ints
()[
i
]));
}
}
}
std
::
vector
<
int
>
sizes
(
starts
.
size
(),
-
1
);
for
(
size_t
i
=
0
;
i
<
starts
.
size
();
++
i
)
{
sizes
[
i
]
=
(
ends
[
i
]
<
0
?
ends
[
i
]
:
ends
[
i
]
-
starts
[
i
]);
}
attr
->
axes
=
axes
;
attr
->
begin
=
starts
;
attr
->
size
=
sizes
;
op
->
primitive
->
value
.
type
=
schema
::
PrimitiveType_Slice
;
op
->
primitive
->
value
.
value
=
attr
.
release
();
return
RET_OK
;
...
...
mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc
浏览文件 @
3d26fe4d
...
...
@@ -55,7 +55,12 @@ STATUS TfliteSliceParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite
MS_LOG
(
ERROR
)
<<
"get slice -> size failed"
;
return
RET_ERROR
;
}
std
::
vector
<
int
>
axes
;
axes
.
clear
();
for
(
size_t
i
=
0
;
i
<
attr
->
begin
.
size
();
++
i
)
{
axes
.
push_back
(
i
);
}
attr
->
axes
=
axes
;
op
->
primitive
->
value
.
type
=
schema
::
PrimitiveType_Slice
;
op
->
primitive
->
value
.
value
=
attr
.
release
();
...
...
mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc
浏览文件 @
3d26fe4d
...
...
@@ -72,8 +72,7 @@ const std::vector<Tensor *> GetCNodeInputTensors(const CNodePtr &CNode) {
}
const
ParameterPtr
CreateNewParamter
(
const
FuncGraphPtr
&
func_graph
,
Tensor
*
tensor
)
{
auto
parameter
=
func_graph
->
add_parameter
();
std
::
vector
<
int
>
shape
;
std
::
copy
(
tensor
->
shape
().
begin
(),
tensor
->
shape
().
end
(),
std
::
back_inserter
(
shape
));
std
::
vector
<
int
>
shape
(
tensor
->
shape
());
auto
type_id
=
static_cast
<
TypeId
>
(
tensor
->
data_type
());
auto
type_ptr
=
TypeIdToType
(
type_id
);
auto
abstract_tensor
=
std
::
make_shared
<
abstract
::
AbstractTensor
>
(
type_ptr
,
shape
);
...
...
@@ -160,6 +159,15 @@ const AnfNodePtr ConstFoldPass::Process(const FuncGraphPtr &func_graph, const An
MS_LOG
(
ERROR
)
<<
"lite_primitive is nullptr"
;
return
nullptr
;
}
// here, input_tensor's format need to be transposed nhwc according to fmkType,
// but for the time being, we only transpose the tensor with 0/1/2/3D.
// Others should be added in future.
for
(
size_t
j
=
0
;
j
<
input_tensors
.
size
();
++
j
)
{
input_tensors
[
j
]
->
SetFormat
(
schema
::
Format_NHWC
);
if
(
input_tensors
[
j
]
->
shape
().
size
()
==
4
)
{
MS_LOG
(
WARNING
)
<<
"init input_tensor format to nhwc"
;
}
}
lite_primitive
->
InferShape
(
input_tensors
,
output_tensors
);
auto
lite_kernel
=
GetLiteKernel
(
input_tensors
,
output_tensors
,
lite_primitive
.
get
());
if
(
lite_kernel
==
nullptr
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录