Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c3b54b9b
提交
c3b54b9b
authored
2月 09, 2016
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix tests and code so that they can be happy forever after.
上级
05a63694
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
23 行增加
和
21 行删除
+23
-21
__init__.py
theano/tensor/nnet/__init__.py
+1
-2
corr.py
theano/tensor/nnet/corr.py
+2
-2
corr_gemm.c
theano/tensor/nnet/corr_gemm.c
+2
-2
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+18
-15
没有找到文件。
theano/tensor/nnet/__init__.py
浏览文件 @
c3b54b9b
...
@@ -31,6 +31,7 @@ from .bn import batch_normalization
...
@@ -31,6 +31,7 @@ from .bn import batch_normalization
import
warnings
import
warnings
from
.abstract_conv
import
conv2d
as
abstract_conv2d
from
.abstract_conv
import
conv2d
as
abstract_conv2d
def
conv2d
(
input
,
filters
,
input_shape
=
None
,
filter_shape
=
None
,
def
conv2d
(
input
,
filters
,
input_shape
=
None
,
filter_shape
=
None
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
filter_flip
=
True
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
filter_flip
=
True
,
image_shape
=
None
,
**
kwargs
):
image_shape
=
None
,
**
kwargs
):
...
@@ -139,5 +140,3 @@ def conv2d(input, filters, input_shape=None, filter_shape=None,
...
@@ -139,5 +140,3 @@ def conv2d(input, filters, input_shape=None, filter_shape=None,
return
abstract_conv2d
(
input
,
filters
,
input_shape
,
filter_shape
,
return
abstract_conv2d
(
input
,
filters
,
input_shape
,
filter_shape
,
border_mode
,
subsample
,
filter_flip
)
border_mode
,
subsample
,
filter_flip
)
theano/tensor/nnet/corr.py
浏览文件 @
c3b54b9b
...
@@ -424,7 +424,7 @@ class CorrMM_gradWeights(BaseCorrMM):
...
@@ -424,7 +424,7 @@ class CorrMM_gradWeights(BaseCorrMM):
if
shape
is
None
:
if
shape
is
None
:
raise
ValueError
(
'shape must be given if subsample != (1, 1)'
raise
ValueError
(
'shape must be given if subsample != (1, 1)'
' or border_mode == "half"'
)
' or border_mode == "half"'
)
height_width
=
[
shape
[
0
],
shape
[
1
]
]
height_width
=
[
as_tensor_variable
(
shape
[
0
]),
as_tensor_variable
(
shape
[
1
])
]
else
:
else
:
height_width
=
[]
height_width
=
[]
...
@@ -519,7 +519,7 @@ class CorrMM_gradInputs(BaseCorrMM):
...
@@ -519,7 +519,7 @@ class CorrMM_gradInputs(BaseCorrMM):
raise
TypeError
(
'topgrad must be 4D tensor'
)
raise
TypeError
(
'topgrad must be 4D tensor'
)
if
self
.
subsample
!=
(
1
,
1
)
and
shape
is
None
:
if
self
.
subsample
!=
(
1
,
1
)
and
shape
is
None
:
raise
ValueError
(
'shape must be given if subsample != (1, 1)'
)
raise
ValueError
(
'shape must be given if subsample != (1, 1)'
)
height_width
=
[
shape
[
0
],
shape
[
1
]
]
if
self
.
subsample
!=
(
1
,
1
)
else
[]
height_width
=
[
as_tensor_variable
(
shape
[
0
]),
as_tensor_variable
(
shape
[
1
])
]
if
self
.
subsample
!=
(
1
,
1
)
else
[]
broadcastable
=
[
topgrad
.
type
.
broadcastable
[
0
],
kern
.
type
.
broadcastable
[
1
],
broadcastable
=
[
topgrad
.
type
.
broadcastable
[
0
],
kern
.
type
.
broadcastable
[
1
],
False
,
False
]
False
,
False
]
...
...
theano/tensor/nnet/corr_gemm.c
浏览文件 @
c3b54b9b
...
@@ -162,7 +162,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
...
@@ -162,7 +162,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
"CorrMM shape inconsistency:
\n
"
"CorrMM shape inconsistency:
\n
"
" bottom shape: %%d %%d %%d %%d
\n
"
" bottom shape: %%d %%d %%d %%d
\n
"
" weight shape: %%d %%d %%d %%d
\n
"
" weight shape: %%d %%d %%d %%d
\n
"
" top shape: %%
d %%d %%d %%
d (expected %%d %%d %%d %%d)
\n
"
,
" top shape: %%
ld %%ld %%ld %%l
d (expected %%d %%d %%d %%d)
\n
"
,
batchSize
,
nChannels
,
bottomHeight
,
bottomWidth
,
batchSize
,
nChannels
,
bottomHeight
,
bottomWidth
,
nFilters
,
nChannels
,
kH
,
kW
,
nFilters
,
nChannels
,
kH
,
kW
,
PyArray_DIMS
(
top
)[
0
],
PyArray_DIMS
(
top
)[
1
],
PyArray_DIMS
(
top
)[
0
],
PyArray_DIMS
(
top
)[
1
],
...
@@ -182,7 +182,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
...
@@ -182,7 +182,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
if
(
NULL
==
col
)
if
(
NULL
==
col
)
{
{
PyErr_Format
(
PyExc_RuntimeError
,
PyErr_Format
(
PyExc_RuntimeError
,
"CorrMM failed to allocate working memory of %%
d x %%
d
\n
"
,
"CorrMM failed to allocate working memory of %%
ld x %%l
d
\n
"
,
col_dim
[
0
],
col_dim
[
1
]);
col_dim
[
0
],
col_dim
[
1
]);
return
NULL
;
return
NULL
;
}
}
...
...
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
c3b54b9b
...
@@ -4,12 +4,12 @@ import itertools
...
@@ -4,12 +4,12 @@ import itertools
import
theano
import
theano
from
theano
import
tensor
from
theano
import
tensor
from
theano.tests
import
unittests_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
from
theano.tensor.nnet.abstract_conv
import
conv
,
get_conv_output_shape
from
theano.tensor.nnet
import
corr
,
abstract_conv
as
conv
from
theano.tensor.nnet
import
corr
from
theano.tensor.nnet.abstract_conv
import
get_conv_output_shape
from
theano.tensor.nnet.conv
import
ConvOp
from
theano.tensor.nnet.corr
import
(
CorrMM
,
CorrMM_gradWeights
,
from
theano.tensor.nnet.corr
import
(
CorrMM
,
CorrMM_gradWeights
,
CorrMM_gradInputs
)
CorrMM_gradInputs
)
from
theano.tensor.nnet.conv
import
ConvOp
from
theano.tensor.nnet.ConvGrad3D
import
ConvGrad3D
from
theano.tensor.nnet.ConvGrad3D
import
ConvGrad3D
from
theano.tensor.nnet.ConvTransp3D
import
ConvTransp3D
from
theano.tensor.nnet.ConvTransp3D
import
ConvTransp3D
...
@@ -21,18 +21,21 @@ def conv_corr(inputs, filters, border_mode="valid", subsample=(1, 1),
...
@@ -21,18 +21,21 @@ def conv_corr(inputs, filters, border_mode="valid", subsample=(1, 1),
return
corr
.
CorrMM
(
border_mode
,
subsample
)(
inputs
,
filters
)
return
corr
.
CorrMM
(
border_mode
,
subsample
)(
inputs
,
filters
)
def
conv_corr_gw
(
inputs
,
filters
,
border_mode
=
"valid"
,
subsample
=
(
1
,
1
),
def
conv_corr_gw
(
inputs
,
topgrad
,
filters_shape
,
border_mode
=
"valid"
,
conv_mode
=
'conv'
):
subsample
=
(
1
,
1
),
conv_mode
=
'conv'
):
rval
=
corr
.
CorrMM_gradWeights
(
border_mode
,
subsample
)(
inputs
,
topgrad
,
filters_shape
[
2
:])
if
conv_mode
==
'conv'
:
if
conv_mode
==
'conv'
:
filters
=
filters
[:,
:,
::
-
1
,
::
-
1
]
rval
=
rval
[:,
:,
::
-
1
,
::
-
1
]
return
corr
.
CorrMM
(
border_mode
,
subsample
)(
inputs
,
filters
)
return
rval
def
conv_corr_gi
(
inputs
,
filters
,
border_mode
=
"valid"
,
subsample
=
(
1
,
1
)
,
def
conv_corr_gi
(
filters
,
topgrad
,
inputs_shape
,
border_mode
=
"valid"
,
conv_mode
=
'conv'
):
subsample
=
(
1
,
1
),
conv_mode
=
'conv'
):
if
conv_mode
==
'conv'
:
if
conv_mode
==
'conv'
:
filters
=
filters
[:,
:,
::
-
1
,
::
-
1
]
filters
=
filters
[:,
:,
::
-
1
,
::
-
1
]
return
corr
.
CorrMM
(
border_mode
,
subsample
)(
inputs
,
filters
)
return
corr
.
CorrMM_gradInputs
(
border_mode
,
subsample
)(
filters
,
topgrad
,
inputs_shape
[
2
:])
class
TestGetConvOutShape
(
unittest
.
TestCase
):
class
TestGetConvOutShape
(
unittest
.
TestCase
):
...
@@ -279,7 +282,7 @@ class TestCpuConv2d(TestConv2d):
...
@@ -279,7 +282,7 @@ class TestCpuConv2d(TestConv2d):
gradweight_OK
=
False
gradweight_OK
=
False
gradinput_OK
=
False
gradinput_OK
=
False
if
b
not
in
(
'valid'
,
'full'
):
if
b
not
in
(
(
0
,
0
),
'valid'
,
'full'
):
fwd_OK
=
False
fwd_OK
=
False
gradweight_OK
=
False
gradweight_OK
=
False
gradinput_OK
=
False
gradinput_OK
=
False
...
@@ -294,7 +297,7 @@ class TestCpuConv2d(TestConv2d):
...
@@ -294,7 +297,7 @@ class TestCpuConv2d(TestConv2d):
if
fwd_OK
:
if
fwd_OK
:
self
.
run_fwd
(
inputs_shape
=
i
,
filters_shape
=
f
,
subsample
=
s
,
self
.
run_fwd
(
inputs_shape
=
i
,
filters_shape
=
f
,
subsample
=
s
,
verify_grad
=
True
,
mode
=
mode
,
device
=
'cpu'
,
verify_grad
=
True
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
ConvOp
)
filter_flip
=
flip
,
target_op
=
ConvOp
)
else
:
else
:
...
@@ -312,7 +315,7 @@ class TestCpuConv2d(TestConv2d):
...
@@ -312,7 +315,7 @@ class TestCpuConv2d(TestConv2d):
if
gradweight_OK
:
if
gradweight_OK
:
self
.
run_gradweight
(
inputs_shape
=
i
,
filters_shape
=
f
,
self
.
run_gradweight
(
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
mode
=
mode
,
device
=
'cpu'
,
verify_grad
=
False
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
filter_flip
=
flip
,
target_op
=
(
ConvOp
,
ConvGrad3D
))
target_op
=
(
ConvOp
,
ConvGrad3D
))
...
@@ -332,7 +335,7 @@ class TestCpuConv2d(TestConv2d):
...
@@ -332,7 +335,7 @@ class TestCpuConv2d(TestConv2d):
if
gradinput_OK
:
if
gradinput_OK
:
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
mode
=
mode
,
device
=
'cpu'
,
verify_grad
=
False
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
filter_flip
=
flip
,
target_op
=
(
ConvOp
,
ConvTransp3D
))
target_op
=
(
ConvOp
,
ConvTransp3D
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论