Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c81f8c36
提交
c81f8c36
authored
11月 10, 2015
作者:
Samira Shabanian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8 typed list directory
上级
33c97605
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
15 行增加
和
14 行删除
+15
-14
conv.py
theano/tensor/signal/conv.py
+9
-7
downsample.py
theano/tensor/signal/downsample.py
+0
-0
test_conv.py
theano/tensor/signal/tests/test_conv.py
+6
-7
test_downsample.py
theano/tensor/signal/tests/test_downsample.py
+0
-0
没有找到文件。
theano/tensor/signal/conv.py
浏览文件 @
c81f8c36
...
@@ -3,8 +3,6 @@ Contains a wrapper function for tensor.nnet.ConvOp, which can be used to perform
...
@@ -3,8 +3,6 @@ Contains a wrapper function for tensor.nnet.ConvOp, which can be used to perform
generic 2D convolution.
generic 2D convolution.
"""
"""
__docformat__
=
"restructuredtext en"
import
warnings
import
warnings
import
theano
import
theano
...
@@ -12,6 +10,10 @@ import theano.tensor as tensor
...
@@ -12,6 +10,10 @@ import theano.tensor as tensor
from
theano.tensor.nnet
import
conv
from
theano.tensor.nnet
import
conv
import
logging
import
logging
__docformat__
=
"restructuredtext en"
_logger
=
logging
.
getLogger
(
"theano.tensor.signal.conv"
)
_logger
=
logging
.
getLogger
(
"theano.tensor.signal.conv"
)
...
@@ -52,7 +54,7 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
...
@@ -52,7 +54,7 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
assert
input
.
ndim
in
(
2
,
3
)
assert
input
.
ndim
in
(
2
,
3
)
assert
filters
.
ndim
in
(
2
,
3
)
assert
filters
.
ndim
in
(
2
,
3
)
#
##
use shape information if it is given to us ###
# use shape information if it is given to us ###
if
filter_shape
and
image_shape
:
if
filter_shape
and
image_shape
:
if
input
.
ndim
==
3
:
if
input
.
ndim
==
3
:
bsize
=
image_shape
[
0
]
bsize
=
image_shape
[
0
]
...
@@ -69,7 +71,7 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
...
@@ -69,7 +71,7 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
nkern
,
kshp
=
None
,
None
nkern
,
kshp
=
None
,
None
bsize
,
imshp
=
None
,
None
bsize
,
imshp
=
None
,
None
#
##
reshape tensors to 4D, for compatibility with ConvOp ###
# reshape tensors to 4D, for compatibility with ConvOp ###
if
input
.
ndim
==
3
:
if
input
.
ndim
==
3
:
sym_bsize
=
input
.
shape
[
0
]
sym_bsize
=
input
.
shape
[
0
]
else
:
else
:
...
@@ -86,10 +88,10 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
...
@@ -86,10 +88,10 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
new_filter_shape
=
tensor
.
join
(
0
,
tensor
.
stack
([
sym_nkern
,
1
]),
filters
.
shape
[
-
2
:])
new_filter_shape
=
tensor
.
join
(
0
,
tensor
.
stack
([
sym_nkern
,
1
]),
filters
.
shape
[
-
2
:])
filters4D
=
tensor
.
reshape
(
filters
,
new_filter_shape
,
ndim
=
4
)
filters4D
=
tensor
.
reshape
(
filters
,
new_filter_shape
,
ndim
=
4
)
#
##
perform actual convolution ###
# perform actual convolution ###
op
=
conv
.
ConvOp
(
output_mode
=
border_mode
,
op
=
conv
.
ConvOp
(
output_mode
=
border_mode
,
dx
=
subsample
[
0
],
dy
=
subsample
[
1
],
dx
=
subsample
[
0
],
dy
=
subsample
[
1
],
imshp
=
imshp
,
kshp
=
kshp
,
nkern
=
nkern
,
bsize
=
bsize
,
**
kargs
)
imshp
=
imshp
,
kshp
=
kshp
,
nkern
=
nkern
,
bsize
=
bsize
,
**
kargs
)
output
=
op
(
input4D
,
filters4D
)
output
=
op
(
input4D
,
filters4D
)
...
...
theano/tensor/signal/downsample.py
浏览文件 @
c81f8c36
差异被折叠。
点击展开。
theano/tensor/signal/tests/test_conv.py
浏览文件 @
c81f8c36
...
@@ -31,7 +31,7 @@ class TestSignalConv2D(unittest.TestCase):
...
@@ -31,7 +31,7 @@ class TestSignalConv2D(unittest.TestCase):
if
filter_dim
!=
3
:
if
filter_dim
!=
3
:
nkern
=
1
nkern
=
1
#
############
THEANO IMPLEMENTATION ############
# THEANO IMPLEMENTATION ############
# we create a symbolic function so that verify_grad can work
# we create a symbolic function so that verify_grad can work
def
sym_conv2d
(
input
,
filters
):
def
sym_conv2d
(
input
,
filters
):
return
conv
.
conv2d
(
input
,
filters
)
return
conv
.
conv2d
(
input
,
filters
)
...
@@ -44,9 +44,8 @@ class TestSignalConv2D(unittest.TestCase):
...
@@ -44,9 +44,8 @@ class TestSignalConv2D(unittest.TestCase):
filter_data
=
numpy
.
random
.
random
(
filter_shape
)
filter_data
=
numpy
.
random
.
random
(
filter_shape
)
theano_output
=
theano_conv
(
image_data
,
filter_data
)
theano_output
=
theano_conv
(
image_data
,
filter_data
)
############# REFERENCE IMPLEMENTATION ############
# REFERENCE IMPLEMENTATION ############
out_shape2d
=
numpy
.
array
(
image_shape
[
-
2
:])
-
\
out_shape2d
=
numpy
.
array
(
image_shape
[
-
2
:])
-
numpy
.
array
(
filter_shape
[
-
2
:])
+
1
numpy
.
array
(
filter_shape
[
-
2
:])
+
1
ref_output
=
numpy
.
zeros
(
tuple
(
out_shape2d
))
ref_output
=
numpy
.
zeros
(
tuple
(
out_shape2d
))
# reshape as 3D input tensors to make life easier
# reshape as 3D input tensors to make life easier
...
@@ -76,7 +75,7 @@ class TestSignalConv2D(unittest.TestCase):
...
@@ -76,7 +75,7 @@ class TestSignalConv2D(unittest.TestCase):
self
.
assertTrue
(
_allclose
(
theano_output4d
[
b
,
k
,
:,
:],
self
.
assertTrue
(
_allclose
(
theano_output4d
[
b
,
k
,
:,
:],
output2d
))
output2d
))
#
############
TEST GRADIENT ############
# TEST GRADIENT ############
if
verify_grad
:
if
verify_grad
:
utt
.
verify_grad
(
sym_conv2d
,
[
image_data
,
filter_data
])
utt
.
verify_grad
(
sym_conv2d
,
[
image_data
,
filter_data
])
...
@@ -87,8 +86,8 @@ class TestSignalConv2D(unittest.TestCase):
...
@@ -87,8 +86,8 @@ class TestSignalConv2D(unittest.TestCase):
signal.conv.conv2d can support inputs and filters of type
signal.conv.conv2d can support inputs and filters of type
matrix or tensor3.
matrix or tensor3.
"""
"""
if
(
not
theano
.
tensor
.
nnet
.
conv
.
imported_scipy_signal
and
if
(
not
theano
.
tensor
.
nnet
.
conv
.
imported_scipy_signal
and
theano
.
config
.
cxx
==
""
):
theano
.
config
.
cxx
==
""
):
raise
SkipTest
(
"conv2d tests need SciPy or a c++ compiler"
)
raise
SkipTest
(
"conv2d tests need SciPy or a c++ compiler"
)
self
.
validate
((
1
,
4
,
5
),
(
2
,
2
,
3
),
out_dim
=
4
,
verify_grad
=
True
)
self
.
validate
((
1
,
4
,
5
),
(
2
,
2
,
3
),
out_dim
=
4
,
verify_grad
=
True
)
...
...
theano/tensor/signal/tests/test_downsample.py
浏览文件 @
c81f8c36
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论