Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
8307b0cb
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
8307b0cb
编写于
9月 07, 2021
作者:
W
wangxinxin08
提交者:
GitHub
9月 07, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add conv op check for illegal input or attributes (#35337)
* add conv op check for illegal input or attributes
上级
eae4bf5b
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
519 addition
and
0 deletion
+519
-0
paddle/fluid/operators/conv_op.cc
paddle/fluid/operators/conv_op.cc
+4
-0
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+22
-0
python/paddle/fluid/tests/unittests/test_functional_conv1d.py
...on/paddle/fluid/tests/unittests/test_functional_conv1d.py
+70
-0
python/paddle/fluid/tests/unittests/test_functional_conv1d_transpose.py
...fluid/tests/unittests/test_functional_conv1d_transpose.py
+70
-0
python/paddle/fluid/tests/unittests/test_functional_conv2d.py
...on/paddle/fluid/tests/unittests/test_functional_conv2d.py
+76
-0
python/paddle/fluid/tests/unittests/test_functional_conv2d_transpose.py
...fluid/tests/unittests/test_functional_conv2d_transpose.py
+76
-0
python/paddle/fluid/tests/unittests/test_functional_conv3d.py
...on/paddle/fluid/tests/unittests/test_functional_conv3d.py
+76
-0
python/paddle/fluid/tests/unittests/test_functional_conv3d_transpose.py
...fluid/tests/unittests/test_functional_conv3d_transpose.py
+77
-0
python/paddle/nn/functional/conv.py
python/paddle/nn/functional/conv.py
+48
-0
未找到文件。
paddle/fluid/operators/conv_op.cc
浏览文件 @
8307b0cb
...
...
@@ -116,6 +116,10 @@ std::vector<int64_t> ConvOp::ComputeOutputShape(
"the output channels is %d, the filter's shape is [%s], "
"the groups is %d."
,
filter_dims
[
0
],
filter_dims
,
groups
));
PADDLE_ENFORCE_GT
(
filter_dims
[
0
],
0
,
platform
::
errors
::
InvalidArgument
(
"the size of filter at axis 0 should be greater than 0"
));
framework
::
DDim
in_data_dims
;
if
(
channel_last
)
{
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
8307b0cb
...
...
@@ -1816,6 +1816,10 @@ def conv3d(input,
"Attr(data_format): %s." % str(data_format))
channel_last = (data_format == "NDHWC")
if len(input.shape) != 5:
raise ValueError(
"Input should be 5D tensor, but received input with the shape of {}".
format(input.shape))
num_channels = input.shape[4] if channel_last else input.shape[1]
if num_channels < 0:
raise ValueError(
...
...
@@ -1824,6 +1828,10 @@ def conv3d(input,
if groups is None:
num_filter_channels = num_channels
elif groups <= 0:
raise ValueError(
"the groups of conv3d should be greater than 0. Received groups: {}".
format(groups))
else:
if num_channels % groups != 0:
raise ValueError(
...
...
@@ -4244,10 +4252,15 @@ def conv3d_transpose(input,
raise ValueError(
"Param(data_format) of Op(fluid.layers.conv3d_transpose) got wrong value: received "
+ data_format + " but only NCDHW or NDHWC supported.")
l_type = "conv3d_transpose"
helper = LayerHelper(l_type, **locals())
if not isinstance(input, Variable):
raise TypeError("Input of conv3d_transpose must be Variable")
if len(input.shape) != 5:
raise ValueError(
"Input should be 5D tensor, but received input with the shape of {}".
format(input.shape))
input_channel = input.shape[1] if data_format == 'NCDHW' else input.shape[
-1]
...
...
@@ -4339,6 +4352,15 @@ def conv3d_transpose(input,
raise ValueError("output_size should be int, list[int] or tuple[int]")
groups = 1 if groups is None else groups
if groups <= 0:
raise ValueError(
"the groups of conv3d_transpose should be greater than 0. Received groups: {}".
format(groups))
if num_filters % groups != 0:
raise ValueError("Attr(num_filters) must be divisible by groups,"
"Received: Attr(num_filters) is {}, the groups is {}".
format(num_filters, groups))
filter_shape = [input_channel, num_filters // groups] + filter_size
img_filter = helper.create_parameter(
dtype=input.dtype, shape=filter_shape, attr=helper.param_attr)
...
...
python/paddle/fluid/tests/unittests/test_functional_conv1d.py
0 → 100644
浏览文件 @
8307b0cb
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# 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.
import
paddle
import
paddle.nn.functional
as
F
from
paddle
import
fluid
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid.initializer
as
I
import
numpy
as
np
import
unittest
from
unittest
import
TestCase
class
TestFunctionalConv1DError
(
TestCase
):
def
setUp
(
self
):
self
.
input
=
[]
self
.
filter
=
[]
self
.
bias
=
None
self
.
padding
=
0
self
.
stride
=
1
self
.
dilation
=
1
self
.
groups
=
1
self
.
data_format
=
"NCL"
def
dygraph_case
(
self
):
with
dg
.
guard
():
x
=
dg
.
to_variable
(
self
.
input
,
dtype
=
paddle
.
float32
)
w
=
dg
.
to_variable
(
self
.
filter
,
dtype
=
paddle
.
float32
)
b
=
None
if
self
.
bias
is
None
else
dg
.
to_variable
(
self
.
bias
,
dtype
=
paddle
.
float32
)
y
=
F
.
conv1d
(
x
,
w
,
b
,
padding
=
self
.
padding
,
stride
=
self
.
stride
,
dilation
=
self
.
dilation
,
groups
=
self
.
groups
,
data_format
=
self
.
data_format
)
def
test_exception
(
self
):
with
self
.
assertRaises
(
ValueError
):
self
.
dygraph_case
()
class
TestFunctionalConv1DErrorCase1
(
TestFunctionalConv1DError
):
def
setUp
(
self
):
self
.
input
=
np
.
random
.
randn
(
1
,
3
,
3
)
self
.
filter
=
np
.
random
.
randn
(
3
,
3
,
1
)
self
.
bias
=
None
self
.
padding
=
0
self
.
stride
=
1
self
.
dilation
=
1
self
.
groups
=
0
self
.
data_format
=
"NCL"
if
__name__
==
"__main__"
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_functional_conv1d_transpose.py
0 → 100644
浏览文件 @
8307b0cb
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# 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.
import
paddle
import
paddle.nn.functional
as
F
from
paddle
import
fluid
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid.initializer
as
I
import
numpy
as
np
import
unittest
from
unittest
import
TestCase
class
TestFunctionalConv1DError
(
TestCase
):
def
setUp
(
self
):
self
.
input
=
[]
self
.
filter
=
[]
self
.
bias
=
None
self
.
padding
=
0
self
.
stride
=
1
self
.
dilation
=
1
self
.
groups
=
1
self
.
data_format
=
"NCL"
def
dygraph_case
(
self
):
with
dg
.
guard
():
x
=
dg
.
to_variable
(
self
.
input
,
dtype
=
paddle
.
float32
)
w
=
dg
.
to_variable
(
self
.
filter
,
dtype
=
paddle
.
float32
)
b
=
None
if
self
.
bias
is
None
else
dg
.
to_variable
(
self
.
bias
,
dtype
=
paddle
.
float32
)
y
=
F
.
conv1d_transpose
(
x
,
w
,
b
,
padding
=
self
.
padding
,
stride
=
self
.
stride
,
dilation
=
self
.
dilation
,
groups
=
self
.
groups
,
data_format
=
self
.
data_format
)
def
test_exception
(
self
):
with
self
.
assertRaises
(
ValueError
):
self
.
dygraph_case
()
class
TestFunctionalConv1DErrorCase1
(
TestFunctionalConv1DError
):
def
setUp
(
self
):
self
.
input
=
np
.
random
.
randn
(
1
,
3
,
3
)
self
.
filter
=
np
.
random
.
randn
(
3
,
3
,
1
)
self
.
bias
=
None
self
.
padding
=
0
self
.
stride
=
1
self
.
dilation
=
1
self
.
groups
=
0
self
.
data_format
=
"NCL"
if
__name__
==
"__main__"
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_functional_conv2d.py
浏览文件 @
8307b0cb
...
...
@@ -457,5 +457,81 @@ class TestFunctionalConv2DErrorCase11(TestFunctionalConv2DError):
self
.
data_format
=
"NHCW"
class
TestFunctionalConv2DErrorCase12
(
TestCase
):
def
setUp
(
self
):
self
.
input
=
np
.
array
([])
self
.
filter
=
np
.
array
([])
self
.
num_filters
=
0
self
.
filter_size
=
0
self
.
bias
=
None
self
.
padding
=
0
self
.
stride
=
1
self
.
dilation
=
1
self
.
groups
=
1
self
.
data_format
=
"NCHW"
def
static_graph_case
(
self
):
main
=
fluid
.
Program
()
start
=
fluid
.
Program
()
with
fluid
.
unique_name
.
guard
():
with
fluid
.
program_guard
(
main
,
start
):
x
=
fluid
.
data
(
"input"
,
self
.
input
.
shape
,
dtype
=
paddle
.
float32
)
y
=
fluid
.
layers
.
conv2d
(
x
,
self
.
num_filters
,
self
.
filter_size
,
stride
=
self
.
stride
,
padding
=
self
.
padding
,
dilation
=
self
.
dilation
,
groups
=
self
.
groups
,
param_attr
=
I
.
NumpyArrayInitializer
(
self
.
filter
),
bias_attr
=
False
if
self
.
bias
is
None
else
I
.
NumpyArrayInitializer
(
self
.
bias
),
act
=
None
,
data_format
=
self
.
data_format
)
exe
=
fluid
.
Executor
()
exe
.
run
(
start
)
out
,
=
exe
.
run
(
main
,
feed
=
{
"input"
:
self
.
input
},
fetch_list
=
[
y
])
return
out
def
dygraph_case
(
self
):
with
dg
.
guard
():
x
=
dg
.
to_variable
(
self
.
input
,
dtype
=
paddle
.
float32
)
w
=
dg
.
to_variable
(
self
.
filter
,
dtype
=
paddle
.
float32
)
b
=
None
if
self
.
bias
is
None
else
dg
.
to_variable
(
self
.
bias
,
dtype
=
paddle
.
float32
)
y
=
F
.
conv2d
(
x
,
w
,
b
,
padding
=
self
.
padding
,
stride
=
self
.
stride
,
dilation
=
self
.
dilation
,
groups
=
self
.
groups
,
data_format
=
self
.
data_format
)
def
test_dygraph_exception
(
self
):
with
self
.
assertRaises
(
ValueError
):
self
.
dygraph_case
()
def
test_static_exception
(
self
):
with
self
.
assertRaises
(
ValueError
):
self
.
static_graph_case
()
class
TestFunctionalConv2DErrorCase13
(
TestFunctionalConv2DErrorCase12
):
def
setUp
(
self
):
self
.
input
=
np
.
random
.
randn
(
1
,
3
,
3
,
3
)
self
.
filter
=
np
.
random
.
randn
(
3
,
3
,
1
,
1
)
self
.
num_filters
=
3
self
.
filter_size
=
1
self
.
bias
=
None
self
.
padding
=
0
self
.
stride
=
1
self
.
dilation
=
1
self
.
groups
=
0
self
.
data_format
=
"NCHW"
if
__name__
==
"__main__"
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_functional_conv2d_transpose.py
浏览文件 @
8307b0cb
...
...
@@ -463,5 +463,81 @@ class TestFunctionalConv2DErrorCase9(TestFunctionalConv2DError):
self
.
data_format
=
"NCHW"
class
TestFunctionalConv2DErrorCase10
(
TestCase
):
def
setUp
(
self
):
self
.
input
=
np
.
array
([])
self
.
filter
=
np
.
array
([])
self
.
num_filters
=
0
self
.
filter_size
=
0
self
.
bias
=
None
self
.
padding
=
0
self
.
stride
=
1
self
.
dilation
=
1
self
.
groups
=
1
self
.
data_format
=
"NCHW"
def
static_graph_case
(
self
):
main
=
fluid
.
Program
()
start
=
fluid
.
Program
()
with
fluid
.
unique_name
.
guard
():
with
fluid
.
program_guard
(
main
,
start
):
x
=
fluid
.
data
(
"input"
,
self
.
input
.
shape
,
dtype
=
paddle
.
float32
)
y
=
fluid
.
layers
.
conv2d
(
x
,
self
.
num_filters
,
self
.
filter_size
,
stride
=
self
.
stride
,
padding
=
self
.
padding
,
dilation
=
self
.
dilation
,
groups
=
self
.
groups
,
param_attr
=
I
.
NumpyArrayInitializer
(
self
.
filter
),
bias_attr
=
False
if
self
.
bias
is
None
else
I
.
NumpyArrayInitializer
(
self
.
bias
),
act
=
None
,
data_format
=
self
.
data_format
)
exe
=
fluid
.
Executor
()
exe
.
run
(
start
)
out
,
=
exe
.
run
(
main
,
feed
=
{
"input"
:
self
.
input
},
fetch_list
=
[
y
])
return
out
def
dygraph_case
(
self
):
with
dg
.
guard
():
x
=
dg
.
to_variable
(
self
.
input
,
dtype
=
paddle
.
float32
)
w
=
dg
.
to_variable
(
self
.
filter
,
dtype
=
paddle
.
float32
)
b
=
None
if
self
.
bias
is
None
else
dg
.
to_variable
(
self
.
bias
,
dtype
=
paddle
.
float32
)
y
=
F
.
conv2d_transpose
(
x
,
w
,
b
,
padding
=
self
.
padding
,
stride
=
self
.
stride
,
dilation
=
self
.
dilation
,
groups
=
self
.
groups
,
data_format
=
self
.
data_format
)
def
test_dygraph_exception
(
self
):
with
self
.
assertRaises
(
ValueError
):
self
.
dygraph_case
()
def
test_static_exception
(
self
):
with
self
.
assertRaises
(
ValueError
):
self
.
static_graph_case
()
class
TestFunctionalConv2DErrorCase11
(
TestFunctionalConv2DErrorCase10
):
def
setUp
(
self
):
self
.
input
=
np
.
random
.
randn
(
1
,
3
,
3
,
3
)
self
.
filter
=
np
.
random
.
randn
(
3
,
3
,
1
,
1
)
self
.
num_filters
=
3
self
.
filter_size
=
1
self
.
bias
=
None
self
.
padding
=
0
self
.
stride
=
1
self
.
dilation
=
1
self
.
groups
=
0
self
.
data_format
=
"NCHW"
if
__name__
==
"__main__"
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_functional_conv3d.py
浏览文件 @
8307b0cb
...
...
@@ -432,5 +432,81 @@ class TestFunctionalConv3DErrorCase10(TestFunctionalConv3DError):
self
.
data_format
=
"NDHWC"
class
TestFunctionalConv3DErrorCase11
(
TestCase
):
def
setUp
(
self
):
self
.
input
=
np
.
array
([])
self
.
filter
=
np
.
array
([])
self
.
num_filters
=
0
self
.
filter_size
=
0
self
.
bias
=
None
self
.
padding
=
0
self
.
stride
=
1
self
.
dilation
=
1
self
.
groups
=
1
self
.
data_format
=
"NCDHW"
def
static_graph_case
(
self
):
main
=
fluid
.
Program
()
start
=
fluid
.
Program
()
with
fluid
.
unique_name
.
guard
():
with
fluid
.
program_guard
(
main
,
start
):
x
=
fluid
.
data
(
"input"
,
self
.
input
.
shape
,
dtype
=
paddle
.
float32
)
y
=
fluid
.
layers
.
conv3d
(
x
,
self
.
num_filters
,
self
.
filter_size
,
stride
=
self
.
stride
,
padding
=
self
.
padding
,
dilation
=
self
.
dilation
,
groups
=
self
.
groups
,
param_attr
=
I
.
NumpyArrayInitializer
(
self
.
filter
),
bias_attr
=
False
if
self
.
bias
is
None
else
I
.
NumpyArrayInitializer
(
self
.
bias
),
act
=
None
,
data_format
=
self
.
data_format
)
exe
=
fluid
.
Executor
()
exe
.
run
(
start
)
out
,
=
exe
.
run
(
main
,
feed
=
{
"input"
:
self
.
input
},
fetch_list
=
[
y
])
return
out
def
dygraph_case
(
self
):
with
dg
.
guard
():
x
=
dg
.
to_variable
(
self
.
input
,
dtype
=
paddle
.
float32
)
w
=
dg
.
to_variable
(
self
.
filter
,
dtype
=
paddle
.
float32
)
b
=
None
if
self
.
bias
is
None
else
dg
.
to_variable
(
self
.
bias
,
dtype
=
paddle
.
float32
)
y
=
F
.
conv3d
(
x
,
w
,
b
,
padding
=
self
.
padding
,
stride
=
self
.
stride
,
dilation
=
self
.
dilation
,
groups
=
self
.
groups
,
data_format
=
self
.
data_format
)
def
test_dygraph_exception
(
self
):
with
self
.
assertRaises
(
ValueError
):
self
.
dygraph_case
()
def
test_static_exception
(
self
):
with
self
.
assertRaises
(
ValueError
):
self
.
static_graph_case
()
class
TestFunctionalConv3DErrorCase12
(
TestFunctionalConv3DErrorCase11
):
def
setUp
(
self
):
self
.
input
=
np
.
random
.
randn
(
1
,
3
,
3
,
3
,
3
)
self
.
filter
=
np
.
random
.
randn
(
3
,
3
,
1
,
1
,
1
)
self
.
num_filters
=
3
self
.
filter_size
=
1
self
.
bias
=
None
self
.
padding
=
0
self
.
stride
=
1
self
.
dilation
=
1
self
.
groups
=
0
self
.
data_format
=
"NCDHW"
if
__name__
==
"__main__"
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_functional_conv3d_transpose.py
浏览文件 @
8307b0cb
...
...
@@ -483,5 +483,82 @@ class TestFunctionalConv3DTransposeErrorCase9(
self
.
data_format
=
"NCDHW"
class
TestFunctionalConv3DTransposeErrorCase10
(
TestCase
):
def
setUp
(
self
):
self
.
input
=
np
.
array
([])
self
.
filter
=
np
.
array
([])
self
.
num_filters
=
0
self
.
filter_size
=
0
self
.
bias
=
None
self
.
padding
=
0
self
.
stride
=
1
self
.
dilation
=
1
self
.
groups
=
1
self
.
data_format
=
"NCDHW"
def
static_graph_case
(
self
):
main
=
fluid
.
Program
()
start
=
fluid
.
Program
()
with
fluid
.
unique_name
.
guard
():
with
fluid
.
program_guard
(
main
,
start
):
x
=
fluid
.
data
(
"input"
,
self
.
input
.
shape
,
dtype
=
paddle
.
float32
)
y
=
fluid
.
layers
.
conv3d_transpose
(
x
,
self
.
num_filters
,
self
.
filter_size
,
stride
=
self
.
stride
,
padding
=
self
.
padding
,
dilation
=
self
.
dilation
,
groups
=
self
.
groups
,
param_attr
=
I
.
NumpyArrayInitializer
(
self
.
filter
),
bias_attr
=
False
if
self
.
bias
is
None
else
I
.
NumpyArrayInitializer
(
self
.
bias
),
act
=
None
,
data_format
=
self
.
data_format
)
exe
=
fluid
.
Executor
()
exe
.
run
(
start
)
out
,
=
exe
.
run
(
main
,
feed
=
{
"input"
:
self
.
input
},
fetch_list
=
[
y
])
return
out
def
dygraph_case
(
self
):
with
dg
.
guard
():
x
=
dg
.
to_variable
(
self
.
input
,
dtype
=
paddle
.
float32
)
w
=
dg
.
to_variable
(
self
.
filter
,
dtype
=
paddle
.
float32
)
b
=
None
if
self
.
bias
is
None
else
dg
.
to_variable
(
self
.
bias
,
dtype
=
paddle
.
float32
)
y
=
F
.
conv3d_transpose
(
x
,
w
,
b
,
padding
=
self
.
padding
,
stride
=
self
.
stride
,
dilation
=
self
.
dilation
,
groups
=
self
.
groups
,
data_format
=
self
.
data_format
)
def
test_dygraph_exception
(
self
):
with
self
.
assertRaises
(
ValueError
):
self
.
dygraph_case
()
def
test_static_exception
(
self
):
with
self
.
assertRaises
(
ValueError
):
self
.
static_graph_case
()
class
TestFunctionalConv3DTransposeErrorCase11
(
TestFunctionalConv3DTransposeErrorCase10
):
def
setUp
(
self
):
self
.
input
=
np
.
random
.
randn
(
1
,
3
,
3
,
3
,
3
)
self
.
filter
=
np
.
random
.
randn
(
3
,
3
,
1
,
1
,
1
)
self
.
num_filters
=
3
self
.
filter_size
=
1
self
.
bias
=
None
self
.
padding
=
0
self
.
stride
=
1
self
.
dilation
=
1
self
.
groups
=
0
self
.
data_format
=
"NCDHW"
if
__name__
==
"__main__"
:
unittest
.
main
()
python/paddle/nn/functional/conv.py
浏览文件 @
8307b0cb
...
...
@@ -299,12 +299,20 @@ def conv1d(x,
channel_last
=
(
data_format
==
"NLC"
)
channel_dim
=
-
1
if
channel_last
else
1
conv2d_data_format
=
"NHWC"
if
channel_last
else
"NCHW"
if
len
(
x
.
shape
)
!=
3
:
raise
ValueError
(
"Input x should be 3D tensor, but received x with the shape of {}"
.
format
(
x
.
shape
))
num_channels
=
x
.
shape
[
channel_dim
]
num_filters
=
weight
.
shape
[
0
]
if
num_channels
<
0
:
raise
ValueError
(
"The channel dimension of the input({}) "
"should be defined. Received: {}."
.
format
(
x
.
shape
,
num_channels
))
if
groups
<=
0
:
raise
ValueError
(
"The groups of conv1d should be greater than 0. Received groups: {}"
.
format
(
groups
))
if
num_channels
%
groups
!=
0
:
raise
ValueError
(
"the channel of input must be divisible by groups,"
...
...
@@ -508,12 +516,20 @@ def conv2d(x,
channel_last
=
(
data_format
==
"NHWC"
)
channel_dim
=
-
1
if
channel_last
else
1
if
len
(
x
.
shape
)
!=
4
:
raise
ValueError
(
"Input x should be 4D tensor, but received x with the shape of {}"
.
format
(
x
.
shape
))
num_channels
=
x
.
shape
[
channel_dim
]
num_filters
=
weight
.
shape
[
0
]
if
num_channels
<
0
:
raise
ValueError
(
"The channel dimension of the input({}) "
"should be defined. Received: {}."
.
format
(
x
.
shape
,
num_channels
))
if
groups
<=
0
:
raise
ValueError
(
"The groups of conv2d should be greater than 0. Received groups: {}"
.
format
(
groups
))
if
num_channels
%
groups
!=
0
:
raise
ValueError
(
"the channel of input must be divisible by groups,"
...
...
@@ -710,12 +726,20 @@ def conv1d_transpose(x,
data_format
))
channel_last
=
(
data_format
==
"NLC"
)
channel_dim
=
-
1
if
channel_last
else
1
if
len
(
x
.
shape
)
!=
3
:
raise
ValueError
(
"Input x should be 3D tensor, but received x with the shape of {}"
.
format
(
x
.
shape
))
num_channels
=
x
.
shape
[
channel_dim
]
if
num_channels
<
0
:
raise
ValueError
(
"The channel dimension of the input({}) "
"should be defined. Received: {}."
.
format
(
x
.
shape
,
num_channels
))
if
groups
<=
0
:
raise
ValueError
(
"The groups of conv1d_transpose should be greater than 0. Received groups: {}"
.
format
(
groups
))
if
num_channels
%
groups
!=
0
:
raise
ValueError
(
"the channel of input must be divisible by groups,"
...
...
@@ -964,11 +988,19 @@ def conv2d_transpose(x,
data_format
))
channel_last
=
(
data_format
==
"NHWC"
)
channel_dim
=
-
1
if
channel_last
else
1
if
len
(
x
.
shape
)
!=
4
:
raise
ValueError
(
"Input x should be 4D tensor, but received x with the shape of {}"
.
format
(
x
.
shape
))
num_channels
=
x
.
shape
[
channel_dim
]
if
num_channels
<
0
:
raise
ValueError
(
"The channel dimension of the input({}) "
"should be defined. Received: {}."
.
format
(
x
.
shape
,
num_channels
))
if
groups
<=
0
:
raise
ValueError
(
"The groups of conv2d_transpose should be greater than 0. Received groups: {}"
.
format
(
groups
))
if
num_channels
%
groups
!=
0
:
raise
ValueError
(
"the channel of input must be divisible by groups,"
...
...
@@ -1167,12 +1199,20 @@ def conv3d(x,
channel_last
=
(
data_format
==
"NDHWC"
)
channel_dim
=
-
1
if
channel_last
else
1
if
len
(
x
.
shape
)
!=
5
:
raise
ValueError
(
"Input x should be 5D tensor, but received x with the shape of {}"
.
format
(
x
.
shape
))
num_channels
=
x
.
shape
[
channel_dim
]
num_filters
=
weight
.
shape
[
0
]
if
num_channels
<
0
:
raise
ValueError
(
"The channel dimension of the input({}) should be defined. "
"Received: {}."
.
format
(
x
.
shape
,
num_channels
))
if
groups
<=
0
:
raise
ValueError
(
"The groups of conv3d should be greater than 0. Received groups: {}"
.
format
(
groups
))
if
num_channels
%
groups
!=
0
:
raise
ValueError
(
"The number of input channels must be divisible by Attr(groups). "
...
...
@@ -1358,12 +1398,20 @@ def conv3d_transpose(x,
channel_last
=
(
data_format
==
"NDHWC"
)
channel_dim
=
-
1
if
channel_last
else
1
if
len
(
x
.
shape
)
!=
5
:
raise
ValueError
(
"Input x should be 5D tensor, but received x with the shape of {}"
.
format
(
x
.
shape
))
num_channels
=
x
.
shape
[
channel_dim
]
num_filters
=
weight
.
shape
[
1
]
if
num_channels
<
0
:
raise
ValueError
(
"The channel dimension of the input({}) should be defined. "
"Received: {}."
.
format
(
x
.
shape
,
num_channels
))
if
groups
<=
0
:
raise
ValueError
(
"The groups of conv3d_transpose should be greater than 0. Received groups: {}"
.
format
(
groups
))
if
num_channels
%
groups
!=
0
:
raise
ValueError
(
"The number of input channels must be divisible by Attr(groups). "
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录