Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
3b65bc7a
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3b65bc7a
编写于
5月 26, 2017
作者:
H
hedaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a naive convolution implement
上级
37114700
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
195 addition
and
0 deletion
+195
-0
paddle/function/ConvOp.cpp
paddle/function/ConvOp.cpp
+128
-0
paddle/function/ConvOp.h
paddle/function/ConvOp.h
+67
-0
未找到文件。
paddle/function/ConvOp.cpp
0 → 100644
浏览文件 @
3b65bc7a
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
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 "ConvFunc.h"
namespace
paddle
{
/*
* The three arguments are stored in memory in row major order.
* inputData = [batchSize, inputChannels, inputHeight, inputWidth]
* filterData = [outputChannels, inputChannels, filterHeight, filterWidth]
* outputData = [batchSize, outputChannels, outputHeight, outputWidth]
*/
template
<
class
T
>
class
NaiveConvFunctor
{
public:
void
operator
()(
const
T
*
inputData
,
size_t
batchSize
,
size_t
inputChannels
,
size_t
inputHeight
,
size_t
inputWidth
,
const
T
*
filterData
,
size_t
filterHeight
,
size_t
filterWidth
,
T
*
outputData
,
size_t
outputChannels
,
size_t
outputHeight
,
size_t
outputWidth
,
size_t
padding
,
size_t
stride
)
{
for
(
size_t
batch
=
0
;
batch
<
batchSize
;
batch
++
)
{
for
(
size_t
outC
=
0
;
outC
<
outputChannels
;
outC
++
)
{
for
(
size_t
outH
=
0
;
outH
<
outputHeight
;
outH
++
)
{
for
(
size_t
outW
=
0
;
outW
<
outputWidth
;
outW
++
)
{
const
int
inStartH
=
(
outH
*
stride
)
-
padding
;
const
int
inStartW
=
(
outW
*
stride
)
-
padding
;
T
outValue
=
(
T
)
0
;
for
(
size_t
inC
=
0
;
inC
<
inputChannels
;
inC
++
)
{
for
(
size_t
fH
=
0
;
fH
<
filterHeight
;
fH
++
)
{
for
(
size_t
fW
=
0
;
fW
<
filterWidth
;
fW
++
)
{
T
inValue
;
const
int
inH
=
inStartH
+
fH
;
const
int
inW
=
inStartW
+
fW
;
if
((
inH
>=
0
&&
inH
<
inputHeight
)
&&
(
inW
>=
0
&&
inW
<
inputWidth
))
{
size_t
offsetInput
=
batch
*
inputChannels
*
inputHeight
*
inputWidth
+
inC
*
inputHeight
*
inputWidth
+
inH
*
inputWidth
+
inW
;
inValue
=
inputData
[
offsetInput
];
}
else
{
inValue
=
(
T
)
0
;
}
size_t
offsetFilter
=
outC
*
inputChannels
*
filterHeight
*
filterWidth
+
inC
*
filterHeight
*
filterWidth
+
fH
*
filterWidth
+
fW
;
T
filterValue
=
filterData
[
offsetFilter
];
outValue
+=
(
inValue
*
filterValue
);
}
}
}
size_t
offset
=
batch
*
outputChannels
*
outputHeight
*
outputWidth
+
outC
*
outputHeight
*
outputWidth
+
outH
*
outputWidth
+
outW
;
outputData
[
offset
]
=
outValue
;
}
}
}
}
}
};
template
<
DeviceType
Device
>
class
NaiveConvFunction
:
public
ConvFunctionBase
{
public:
void
init
(
const
FuncConfig
&
config
)
override
{
ConvFunctionBase
::
init
(
config
);
}
void
calc
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
check
(
inputs
,
outputs
);
CHECK_EQ
(
outputs
[
0
].
getArgType
(),
ASSIGN_TO
);
size_t
batchSize
=
inputs
[
0
].
shape
()[
0
];
size_t
inputChannels
=
inputs
[
0
].
shape
()[
1
];
size_t
inputHeight
=
inputs
[
0
].
shape
()[
2
];
size_t
inputWidth
=
inputs
[
0
].
shape
()[
3
];
size_t
filterHeight
=
inputs
[
1
].
shape
()[
2
];
size_t
filterWidth
=
inputs
[
1
].
shape
()[
2
];
size_t
outputChannels
=
outputs
[
0
].
shape
()[
1
];
size_t
outputHeight
=
outputs
[
0
].
shape
()[
2
];
size_t
outputWidth
=
outputs
[
0
].
shape
()[
3
];
float
*
inputData
=
inputs
[
0
].
data
<
float
>
();
float
*
filterData
=
inputs
[
1
].
data
<
float
>
();
float
*
outputData
=
outputs
[
0
].
data
<
float
>
();
NaiveConvFunctor
<
float
>
conv
;
conv
(
inputData
,
batchSize
,
inputChannels
,
inputHeight
,
inputWidth
,
filterData
,
filterHeight
,
filterWidth
,
outputData
,
outputChannels
,
outputHeight
,
outputWidth
,
padding_
,
stride_
);
}
};
REGISTER_TYPED_FUNC
(
NaiveConv
,
CPU
,
NaiveConvFunction
);
}
// namespace paddle
paddle/function/ConvOp.h
0 → 100644
浏览文件 @
3b65bc7a
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
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 "Function.h"
namespace
paddle
{
/*
* Function Arguments:
*
* \param inputs[0] Input image data, is NCHW format, where N is batch size,
* C is the number of channels, H and W is the height and
* width of input image.
* \param inputs[1] Filter data, is MCHW, where M is the number of output
* channels, C is the number of input channels, H and W
* is height and width of filter.
* \param outputs[0] Output image data, is NCHW format, where N is batch size,
* C is the number of channels, H and W is the height and
* width of output image.
*
* \note Implemented based on the ConvFunctionBase class only supports
* input data in the NCHW format.
*/
class
ConvFunctionBase
:
public
FunctionBase
{
public:
void
init
(
const
FuncConfig
&
config
)
override
{
// function arguments
stride_
=
config
.
get
<
size_t
>
(
"stride"
);
padding_
=
config
.
get
<
size_t
>
(
"padding"
);
// number of inputs and outputs
numInputs_
=
2
;
numOutputs_
=
1
;
}
virtual
void
calc
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
{}
void
check
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
CHECK_EQ
(
numInputs_
,
inputs
.
size
());
CHECK_EQ
(
numOutputs_
,
outputs
.
size
());
CHECK_EQ
(
inputs
[
0
].
shape
().
ndims
(),
(
size_t
)
4
);
CHECK_EQ
(
inputs
[
1
].
shape
().
ndims
(),
(
size_t
)
4
);
CHECK_EQ
(
outputs
[
0
].
shape
().
ndims
(),
(
size_t
)
4
);
CHECK
(
inputs
[
0
].
shape
()[
0
]
==
outputs
[
0
].
shape
()[
0
]);
CHECK
(
inputs
[
0
].
shape
()[
1
]
==
inputs
[
1
].
shape
()[
1
]);
CHECK
(
outputs
[
0
].
shape
()[
1
]
==
inputs
[
1
].
shape
()[
0
]);
}
protected:
size_t
padding_
;
size_t
stride_
;
};
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录