Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6907ba45
提交
6907ba45
authored
7月 08, 2016
作者:
theano-bot
提交者:
GitHub
7月 08, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4691 from JesseLivezey/corrmm_dtype
CorrMM upcasts mixed input dtypes fixes #4687
上级
aaa59e03
33d04174
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
38 行增加
和
0 行删除
+38
-0
corr.py
theano/tensor/nnet/corr.py
+11
-0
test_corr.py
theano/tensor/nnet/tests/test_corr.py
+27
-0
没有找到文件。
theano/tensor/nnet/corr.py
浏览文件 @
6907ba45
...
@@ -85,6 +85,14 @@ class BaseCorrMM(gof.OpenMPOp):
...
@@ -85,6 +85,14 @@ class BaseCorrMM(gof.OpenMPOp):
str
(
self
.
subsample
),
str
(
self
.
subsample
),
str
(
self
.
filter_dilation
))
str
(
self
.
filter_dilation
))
@staticmethod
def
as_common_dtype
(
in1
,
in2
):
"""
Upcast input variables if neccesary.
"""
dtype
=
theano
.
scalar
.
upcast
(
in1
.
dtype
,
in2
.
dtype
)
return
in1
.
astype
(
dtype
),
in2
.
astype
(
dtype
)
def
c_support_code
(
self
):
def
c_support_code
(
self
):
ccodes
=
blas_headers
.
blas_header_text
()
ccodes
=
blas_headers
.
blas_header_text
()
if
self
.
blas_type
==
'openblas'
:
if
self
.
blas_type
==
'openblas'
:
...
@@ -420,6 +428,7 @@ class CorrMM(BaseCorrMM):
...
@@ -420,6 +428,7 @@ class CorrMM(BaseCorrMM):
def
make_node
(
self
,
img
,
kern
):
def
make_node
(
self
,
img
,
kern
):
img
=
as_tensor_variable
(
img
)
img
=
as_tensor_variable
(
img
)
kern
=
as_tensor_variable
(
kern
)
kern
=
as_tensor_variable
(
kern
)
img
,
kern
=
self
.
as_common_dtype
(
img
,
kern
)
if
img
.
type
.
ndim
!=
4
:
if
img
.
type
.
ndim
!=
4
:
raise
TypeError
(
'img must be 4D tensor'
)
raise
TypeError
(
'img must be 4D tensor'
)
if
kern
.
type
.
ndim
!=
4
:
if
kern
.
type
.
ndim
!=
4
:
...
@@ -476,6 +485,7 @@ class CorrMM_gradWeights(BaseCorrMM):
...
@@ -476,6 +485,7 @@ class CorrMM_gradWeights(BaseCorrMM):
def
make_node
(
self
,
img
,
topgrad
,
shape
=
None
):
def
make_node
(
self
,
img
,
topgrad
,
shape
=
None
):
img
=
as_tensor_variable
(
img
)
img
=
as_tensor_variable
(
img
)
topgrad
=
as_tensor_variable
(
topgrad
)
topgrad
=
as_tensor_variable
(
topgrad
)
img
,
topgrad
=
self
.
as_common_dtype
(
img
,
topgrad
)
if
img
.
type
.
ndim
!=
4
:
if
img
.
type
.
ndim
!=
4
:
raise
TypeError
(
'img must be 4D tensor'
)
raise
TypeError
(
'img must be 4D tensor'
)
if
topgrad
.
type
.
ndim
!=
4
:
if
topgrad
.
type
.
ndim
!=
4
:
...
@@ -572,6 +582,7 @@ class CorrMM_gradInputs(BaseCorrMM):
...
@@ -572,6 +582,7 @@ class CorrMM_gradInputs(BaseCorrMM):
def
make_node
(
self
,
kern
,
topgrad
,
shape
=
None
):
def
make_node
(
self
,
kern
,
topgrad
,
shape
=
None
):
kern
=
as_tensor_variable
(
kern
)
kern
=
as_tensor_variable
(
kern
)
topgrad
=
as_tensor_variable
(
topgrad
)
topgrad
=
as_tensor_variable
(
topgrad
)
kern
,
topgrad
=
self
.
as_common_dtype
(
kern
,
topgrad
)
if
kern
.
type
.
ndim
!=
4
:
if
kern
.
type
.
ndim
!=
4
:
raise
TypeError
(
'kern must be 4D tensor'
)
raise
TypeError
(
'kern must be 4D tensor'
)
if
topgrad
.
type
.
ndim
!=
4
:
if
topgrad
.
type
.
ndim
!=
4
:
...
...
theano/tensor/nnet/tests/test_corr.py
浏览文件 @
6907ba45
...
@@ -2,6 +2,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -2,6 +2,7 @@ from __future__ import absolute_import, print_function, division
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.attrib
import
attr
from
nose.plugins.attrib
import
attr
from
nose.tools
import
assert_equals
import
numpy
import
numpy
from
six
import
integer_types
from
six
import
integer_types
...
@@ -259,6 +260,32 @@ class TestCorr2D(utt.InferShapeTester):
...
@@ -259,6 +260,32 @@ class TestCorr2D(utt.InferShapeTester):
self
.
assertRaises
(
Exception
,
self
.
validate
,
(
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
self
.
assertRaises
(
Exception
,
self
.
validate
,
(
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
'valid'
,
input
=
T
.
dtensor3
())
'valid'
,
input
=
T
.
dtensor3
())
def
test_dtype_upcast
(
self
):
"""
Checks dtype upcast for CorrMM methods.
"""
def
rand
(
shape
,
dtype
=
'float64'
):
r
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
dtype
)
return
r
*
2
-
1
ops
=
[
corr
.
CorrMM
,
corr
.
CorrMM_gradWeights
,
corr
.
CorrMM_gradInputs
]
a_shapes
=
[[
4
,
5
,
6
,
3
],
[
1
,
5
,
6
,
3
],
[
1
,
5
,
6
,
3
]]
b_shapes
=
[[
7
,
5
,
3
,
2
],
[
1
,
5
,
3
,
1
],
[
7
,
1
,
3
,
1
]]
dtypes
=
[
'float32'
,
'float64'
]
for
op
,
a_shape
,
b_shape
in
zip
(
ops
,
a_shapes
,
b_shapes
):
for
a_dtype
in
dtypes
:
for
b_dtype
in
dtypes
:
c_dtype
=
theano
.
scalar
.
upcast
(
a_dtype
,
b_dtype
)
a_tens
=
T
.
tensor4
(
dtype
=
a_dtype
)
b_tens
=
T
.
tensor4
(
dtype
=
b_dtype
)
a_tens_val
=
rand
(
a_shape
,
dtype
=
a_dtype
)
b_tens_val
=
rand
(
b_shape
,
dtype
=
b_dtype
)
c_tens
=
op
()(
a_tens
,
b_tens
)
f
=
theano
.
function
([
a_tens
,
b_tens
],
c_tens
,
mode
=
self
.
mode
)
assert_equals
(
f
(
a_tens_val
,
b_tens_val
)
.
dtype
,
c_dtype
)
@attr
(
'slow'
)
@attr
(
'slow'
)
def
test_infer_shape_forward
(
self
):
def
test_infer_shape_forward
(
self
):
if
theano
.
config
.
mode
==
"FAST_COMPILE"
:
if
theano
.
config
.
mode
==
"FAST_COMPILE"
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论