Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
4237d333
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看板
提交
4237d333
编写于
9月 02, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
9月 02, 2020
浏览文件
操作
浏览文件
下载
差异文件
!5604 add caffe slice parser
Merge pull request !5604 from yeyunpeng2020/master_caffe_slice
上级
68c0f1bc
6c96e556
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
129 addition
and
3 deletion
+129
-3
mindspore/lite/nnacl/split.c
mindspore/lite/nnacl/split.c
+8
-0
mindspore/lite/src/ops/split.cc
mindspore/lite/src/ops/split.cc
+10
-2
mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt
mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt
+3
-1
mindspore/lite/tools/converter/parser/caffe/caffe_slice_parser.cc
...e/lite/tools/converter/parser/caffe/caffe_slice_parser.cc
+72
-0
mindspore/lite/tools/converter/parser/caffe/caffe_slice_parser.h
...re/lite/tools/converter/parser/caffe/caffe_slice_parser.h
+36
-0
未找到文件。
mindspore/lite/nnacl/split.c
浏览文件 @
4237d333
...
...
@@ -50,6 +50,14 @@ int DoSplit(float *in_data, float **out_data, const int *input_shape, int offset
split_which
=
i
%
num_split
;
split_times
=
i
/
num_split
;
int
split_size
=
split_sizes
[
split_which
];
// support split size is -1 in the end.
if
(
split_size
==
-
1
)
{
int
split_dim_i
=
input_shape
[
split_dim
];
for
(
int
j
=
0
;
j
<
num_split
-
1
;
++
j
)
{
split_dim_i
-=
split_sizes
[
j
];
}
split_size
=
split_dim_i
;
}
float
*
dst
=
out_data
[
split_which
]
+
split_times
*
in_stride
*
split_size
;
(
void
)
memcpy
(
dst
,
src
,
split_size
*
in_stride_bytes
);
src
+=
split_size
*
in_stride
;
...
...
mindspore/lite/src/ops/split.cc
浏览文件 @
4237d333
...
...
@@ -88,7 +88,7 @@ int Split::InferShape(std::vector<tensor::Tensor *> inputs_, std::vector<tensor:
if
(
!
GetInferFlag
())
{
return
RET_OK
;
}
int
split_dim
=
GetSplitDim
();
size_t
split_dim
=
GetSplitDim
()
==
-
1
?
input
->
shape
().
size
()
-
1
:
GetSplitDim
();
std
::
vector
<
int
>
input_shape
=
input
->
shape
();
std
::
vector
<
int
>
size_split
;
for
(
size_t
i
=
0
;
i
<
GetSizeSplits
().
size
();
++
i
)
{
...
...
@@ -97,7 +97,15 @@ int Split::InferShape(std::vector<tensor::Tensor *> inputs_, std::vector<tensor:
for
(
int
i
=
0
;
i
<
number_split
;
++
i
)
{
std
::
vector
<
int
>
output_shape
;
output_shape
.
insert
(
output_shape
.
begin
(),
input_shape
.
begin
(),
input_shape
.
end
());
auto
split_dim_i
=
size_split
.
empty
()
?
input_shape
[
split_dim
]
/
number_split
:
size_split
[
i
];
int
split_dim_i
=
input_shape
[
split_dim
];
// support split size is -1 in the end.
if
(
i
==
number_split
-
1
&&
size_split
[
i
]
==
-
1
)
{
for
(
size_t
j
=
0
;
j
<
size_split
.
size
()
-
1
;
++
j
)
{
split_dim_i
-=
size_split
[
j
];
}
}
else
{
split_dim_i
=
size_split
.
empty
()
?
input_shape
[
split_dim
]
/
number_split
:
size_split
[
i
];
}
output_shape
[
split_dim
]
=
split_dim_i
;
outputs_
[
i
]
->
set_shape
(
output_shape
);
outputs_
[
i
]
->
set_data_type
(
input
->
data_type
());
...
...
mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt
浏览文件 @
4237d333
...
...
@@ -29,4 +29,6 @@ add_library(caffe_parser_mid OBJECT
${
CMAKE_CURRENT_SOURCE_DIR
}
/caffe_permute_parser.cc
${
CMAKE_CURRENT_SOURCE_DIR
}
/caffe_tile_parser.cc
${
CMAKE_CURRENT_SOURCE_DIR
}
/caffe_tanh_parser.cc
${
CMAKE_CURRENT_SOURCE_DIR
}
/caffe_exp_parser.cc
)
${
CMAKE_CURRENT_SOURCE_DIR
}
/caffe_exp_parser.cc
${
CMAKE_CURRENT_SOURCE_DIR
}
/caffe_slice_parser.cc
)
mindspore/lite/tools/converter/parser/caffe/caffe_slice_parser.cc
0 → 100644
浏览文件 @
4237d333
/**
* 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.
*/
#include "tools/converter/parser/caffe/caffe_slice_parser.h"
#include <memory>
namespace
mindspore
{
namespace
lite
{
STATUS
CaffeSliceParser
::
Parse
(
const
caffe
::
LayerParameter
&
proto
,
const
caffe
::
LayerParameter
&
weight
,
schema
::
CNodeT
*
op
,
std
::
vector
<
schema
::
TensorT
*>
*
weightVec
)
{
MS_LOG
(
DEBUG
)
<<
"parse CaffeSliceParser"
;
if
(
op
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"op is null"
;
return
RET_NULL_PTR
;
}
op
->
primitive
=
std
::
make_unique
<
schema
::
PrimitiveT
>
();
if
(
op
->
primitive
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"op->primitive is null"
;
return
RET_NULL_PTR
;
}
std
::
unique_ptr
<
schema
::
SplitT
>
attr
=
std
::
make_unique
<
schema
::
SplitT
>
();
if
(
attr
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"new op failed"
;
return
RET_NULL_PTR
;
}
const
caffe
::
SliceParameter
&
slice_param
=
proto
.
slice_param
();
if
(
!
slice_param
.
slice_point
().
empty
())
{
attr
->
numberSplit
=
slice_param
.
slice_point_size
()
+
1
;
std
::
vector
<
int32_t
>
size_splits
;
for
(
int
i
=
0
;
i
<
slice_param
.
slice_point_size
();
++
i
)
{
if
(
i
==
0
)
{
size_splits
.
push_back
(
slice_param
.
slice_point
(
i
));
}
else
{
size_splits
.
push_back
(
slice_param
.
slice_point
(
i
)
-
slice_param
.
slice_point
(
i
-
1
));
}
}
size_splits
.
push_back
(
-
1
);
attr
->
sizeSplits
=
size_splits
;
}
// The axis along which to slice -- may be negative to index from the end (e.g., -1 for the last axis).
if
(
slice_param
.
has_axis
())
{
attr
->
splitDim
=
slice_param
.
axis
();
}
else
if
(
slice_param
.
has_slice_dim
())
{
attr
->
splitDim
=
slice_param
.
slice_dim
();
}
op
->
name
=
proto
.
name
();
op
->
primitive
->
value
.
type
=
schema
::
PrimitiveType_Split
;
op
->
primitive
->
value
.
value
=
attr
.
release
();
return
RET_OK
;
}
CaffeNodeRegistrar
g_caffeSliceParser
(
"Slice"
,
new
CaffeSliceParser
());
}
// namespace lite
}
// namespace mindspore
mindspore/lite/tools/converter/parser/caffe/caffe_slice_parser.h
0 → 100644
浏览文件 @
4237d333
/**
* 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.
*/
#ifndef MMINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_SLICE_PARSER_H_
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_SLICE_PARSER_H_
#include <vector>
#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.h"
#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace
mindspore
{
namespace
lite
{
class
CaffeSliceParser
:
public
CaffeNodeParser
{
public:
CaffeSliceParser
()
:
CaffeNodeParser
(
"slice"
)
{}
STATUS
Parse
(
const
caffe
::
LayerParameter
&
proto
,
const
caffe
::
LayerParameter
&
weight
,
schema
::
CNodeT
*
op
,
std
::
vector
<
schema
::
TensorT
*>
*
weightVec
)
override
;
};
}
// namespace lite
}
// namespace mindspore
#endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_SLICE_PARSER_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录