Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f62a038d
提交
f62a038d
authored
3月 08, 2013
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #299 from nouiz/err_msg
Err msg
上级
7f860ba0
75336fb1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
53 行增加
和
11 行删除
+53
-11
conv.py
theano/tensor/nnet/conv.py
+27
-10
test_conv.py
theano/tensor/nnet/tests/test_conv.py
+26
-1
没有找到文件。
theano/tensor/nnet/conv.py
浏览文件 @
f62a038d
...
@@ -16,7 +16,7 @@ import numpy
...
@@ -16,7 +16,7 @@ import numpy
import
theano
import
theano
from
theano.tensor
import
(
as_tensor_variable
,
blas
,
get_scalar_constant_value
,
from
theano.tensor
import
(
as_tensor_variable
,
blas
,
get_scalar_constant_value
,
patternbroadcast
)
patternbroadcast
,
NotScalarConstantError
)
from
theano
import
OpenMPOp
,
config
from
theano
import
OpenMPOp
,
config
from
theano.gof
import
Apply
from
theano.gof
import
Apply
from
theano.gof.python25
import
any
from
theano.gof.python25
import
any
...
@@ -56,13 +56,16 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
...
@@ -56,13 +56,16 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
:type subsample: tuple of len 2
:type subsample: tuple of len 2
:param subsample: factor by which to subsample the output
:param subsample: factor by which to subsample the output
:type image_shape:
tuple
of len 4 of int or Constant variable
:type image_shape:
None, tuple/list
of len 4 of int or Constant variable
:param image_shape: (batch size, stack size, nb row, nb col)
:param image_shape: (batch size, stack size, nb row, nb col)
Optional, used for optimization.
Optional, used for optimization like loop unrolling
:type filter_shape: tuple of len 4 of int or Constant variable
You can put None for any element of the list
to tell that this element is not constant.
:type filter_shape: None, tuple/list of len 4 of int or Constant variable
:param filter_shape: (nb filters, stack size, nb row, nb col)
:param filter_shape: (nb filters, stack size, nb row, nb col)
Optional, used for optimization.
Optional, used for optimization like loop unrolling
You can put None for any element of the list
to tell that this element is not constant.
:param kwargs: kwargs are passed onto ConvOp.
:param kwargs: kwargs are passed onto ConvOp.
Can be used to set the following:
Can be used to set the following:
unroll_batch, unroll_kern, unroll_patch,
unroll_batch, unroll_kern, unroll_patch,
...
@@ -90,16 +93,30 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
...
@@ -90,16 +93,30 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
image_shape
=
list
(
image_shape
)
image_shape
=
list
(
image_shape
)
for
i
in
xrange
(
len
(
image_shape
)):
for
i
in
xrange
(
len
(
image_shape
)):
if
image_shape
[
i
]
is
not
None
:
if
image_shape
[
i
]
is
not
None
:
image_shape
[
i
]
=
get_scalar_constant_value
(
try
:
as_tensor_variable
(
image_shape
[
i
]))
image_shape
[
i
]
=
get_scalar_constant_value
(
as_tensor_variable
(
image_shape
[
i
]))
except
NotScalarConstantError
,
e
:
raise
NotScalarConstantError
(
"The convolution need that the shape"
" information are constant values. We got"
"
%
s for the image_shape parameter"
%
image_shape
[
i
])
assert
str
(
image_shape
[
i
]
.
dtype
)
.
startswith
(
'int'
)
assert
str
(
image_shape
[
i
]
.
dtype
)
.
startswith
(
'int'
)
image_shape
[
i
]
=
int
(
image_shape
[
i
])
image_shape
[
i
]
=
int
(
image_shape
[
i
])
if
filter_shape
is
not
None
:
if
filter_shape
is
not
None
:
filter_shape
=
list
(
filter_shape
)
filter_shape
=
list
(
filter_shape
)
for
i
in
xrange
(
len
(
filter_shape
)):
for
i
in
xrange
(
len
(
filter_shape
)):
if
filter_shape
[
i
]
is
not
None
:
if
filter_shape
[
i
]
is
not
None
:
filter_shape
[
i
]
=
get_scalar_constant_value
(
try
:
as_tensor_variable
(
filter_shape
[
i
]))
filter_shape
[
i
]
=
get_scalar_constant_value
(
as_tensor_variable
(
filter_shape
[
i
]))
except
NotScalarConstantError
,
e
:
raise
NotScalarConstantError
(
"The convolution need that the shape"
" information are constant values. We got"
"
%
s for the filter_shape "
"parameter"
%
filter_shape
[
i
])
assert
str
(
filter_shape
[
i
]
.
dtype
)
.
startswith
(
'int'
)
assert
str
(
filter_shape
[
i
]
.
dtype
)
.
startswith
(
'int'
)
filter_shape
[
i
]
=
int
(
filter_shape
[
i
])
filter_shape
[
i
]
=
int
(
filter_shape
[
i
])
...
...
theano/tensor/nnet/tests/test_conv.py
浏览文件 @
f62a038d
...
@@ -7,7 +7,7 @@ from theano.tests import unittest_tools as utt
...
@@ -7,7 +7,7 @@ from theano.tests import unittest_tools as utt
from
theano.tensor.nnet
import
conv
from
theano.tensor.nnet
import
conv
from
theano.tensor.basic
import
_allclose
from
theano.tensor.basic
import
_allclose
,
NotScalarConstantError
class
TestConv2D
(
utt
.
InferShapeTester
):
class
TestConv2D
(
utt
.
InferShapeTester
):
...
@@ -25,7 +25,18 @@ class TestConv2D(utt.InferShapeTester):
...
@@ -25,7 +25,18 @@ class TestConv2D(utt.InferShapeTester):
input
=
None
,
filters
=
None
,
input
=
None
,
filters
=
None
,
unroll_batch
=
None
,
unroll_kern
=
None
,
unroll_patch
=
None
,
unroll_batch
=
None
,
unroll_kern
=
None
,
unroll_patch
=
None
,
verify_grad
=
True
,
should_raise
=
False
):
verify_grad
=
True
,
should_raise
=
False
):
"""
:param image_shape: The constant shape info passed to conv2d.
:param filter_shape: The constant shape info passed to conv2d.
:param N_image_shape: None(default to image_shape) or tuple of
4 elements with the shape of the input image
:param N_filter_shape: None(default to filter_shape) or tuple
of 4 elements with the shape of the
input filter
"""
if
N_image_shape
is
None
:
if
N_image_shape
is
None
:
N_image_shape
=
[
T
.
get_scalar_constant_value
(
T
.
N_image_shape
=
[
T
.
get_scalar_constant_value
(
T
.
as_tensor_variable
(
x
))
for
x
in
image_shape
]
as_tensor_variable
(
x
))
for
x
in
image_shape
]
...
@@ -342,6 +353,20 @@ class TestConv2D(utt.InferShapeTester):
...
@@ -342,6 +353,20 @@ class TestConv2D(utt.InferShapeTester):
N_image_shape
=
(
3
,
2
,
8
,
8
),
N_image_shape
=
(
3
,
2
,
8
,
8
),
N_filter_shape
=
(
4
,
2
,
5
,
5
))
N_filter_shape
=
(
4
,
2
,
5
,
5
))
def
test_wrong_info
(
self
):
"""
Test convolutions when we don't give a constant as shape information
"""
i
=
theano
.
scalar
.
basic
.
int32
()
self
.
assertRaises
(
NotScalarConstantError
,
self
.
validate
,
(
3
,
2
,
8
,
i
),
(
4
,
2
,
5
,
5
),
N_image_shape
=
(
3
,
2
,
8
,
8
),
N_filter_shape
=
(
4
,
2
,
5
,
5
))
self
.
assertRaises
(
NotScalarConstantError
,
self
.
validate
,
(
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
i
),
N_image_shape
=
(
3
,
2
,
8
,
8
),
N_filter_shape
=
(
4
,
2
,
5
,
5
))
def
test_full_mode
(
self
):
def
test_full_mode
(
self
):
"""
"""
Tests basic convolution in full mode and case where filter
Tests basic convolution in full mode and case where filter
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论