Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4e7913c2
提交
4e7913c2
authored
3月 04, 2016
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Accept arrays in AbstractConv make_node
We are not calling `as_tensor_variable` to avoid transfers when the inputs are on GPU, but the the cuda/numpy arrays should still be converted to Constant variables.
上级
121ec69a
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
73 行增加
和
4 行删除
+73
-4
test_abstractconv.py
theano/sandbox/cuda/tests/test_abstractconv.py
+4
-0
test_abstractconv.py
theano/sandbox/gpuarray/tests/test_abstractconv.py
+7
-1
abstract_conv.py
theano/tensor/nnet/abstract_conv.py
+15
-3
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+47
-0
没有找到文件。
theano/sandbox/cuda/tests/test_abstractconv.py
浏览文件 @
4e7913c2
import
numpy
import
theano
from
theano.tensor.nnet.tests
import
test_abstract_conv
from
theano.sandbox.cuda
import
float32_shared_constructor
as
gpu_shared
...
...
@@ -82,3 +84,5 @@ class TestDnnConvTypes(test_abstract_conv.TestConvTypes):
self
.
input
=
cuda
.
ftensor4
()
self
.
filters
=
cuda
.
ftensor4
()
self
.
topgrad
=
cuda
.
ftensor4
()
self
.
constant_tensor
=
cuda
.
CudaNdarray
(
numpy
.
zeros
((
3
,
5
,
7
,
11
),
dtype
=
'float32'
))
theano/sandbox/gpuarray/tests/test_abstractconv.py
浏览文件 @
4e7913c2
from
nose.plugins.skip
import
SkipTest
import
numpy
from
theano.tensor.nnet.tests
import
test_abstract_conv
from
..type
import
GpuArrayType
,
gpuarray_shared_constructor
from
..type
import
GpuArrayType
,
gpuarray_shared_constructor
,
get_context
from
..dnn
import
dnn_available
,
GpuDnnConv
,
GpuDnnConvGradW
,
GpuDnnConvGradI
from
.config
import
mode_with_gpu
,
test_ctx_name
from
pygpu
import
gpuarray
gpu_ftensor4
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,)
*
4
)
...
...
@@ -43,3 +46,6 @@ class TestDnnConvTypes(test_abstract_conv.TestConvTypes):
self
.
input
=
gpu_ftensor4
()
self
.
filters
=
gpu_ftensor4
()
self
.
topgrad
=
gpu_ftensor4
()
self
.
constant_tensor
=
gpuarray
.
array
(
numpy
.
zeros
((
3
,
5
,
7
,
11
),
dtype
=
'float32'
),
context
=
get_context
(
test_ctx_name
))
theano/tensor/nnet/abstract_conv.py
浏览文件 @
4e7913c2
...
...
@@ -510,7 +510,11 @@ class AbstractConv2d(BaseAbstractConv2d):
filter_flip
)
def
make_node
(
self
,
img
,
kern
):
# Make sure both inputs have the same Type
# Make sure both inputs are Variables with the same Type
if
not
isinstance
(
img
,
theano
.
Variable
):
img
=
as_tensor_variable
(
img
)
if
not
isinstance
(
kern
,
theano
.
Variable
):
kern
=
as_tensor_variable
(
kern
)
ktype
=
img
.
type
.
clone
(
dtype
=
kern
.
dtype
,
broadcastable
=
kern
.
broadcastable
)
kern
=
ktype
.
filter_variable
(
kern
)
...
...
@@ -635,7 +639,11 @@ class AbstractConv2d_gradWeights(BaseAbstractConv2d):
# Update shape/height_width
def
make_node
(
self
,
img
,
topgrad
,
shape
):
# Make sure both inputs have the same Type
# Make sure both inputs are Variables with the same Type
if
not
isinstance
(
img
,
theano
.
Variable
):
img
=
as_tensor_variable
(
img
)
if
not
isinstance
(
topgrad
,
theano
.
Variable
):
topgrad
=
as_tensor_variable
(
topgrad
)
gtype
=
img
.
type
.
clone
(
dtype
=
topgrad
.
dtype
,
broadcastable
=
topgrad
.
broadcastable
)
topgrad
=
gtype
.
filter_variable
(
topgrad
)
...
...
@@ -766,7 +774,11 @@ class AbstractConv2d_gradInputs(BaseAbstractConv2d):
# Update shape/height_width
def
make_node
(
self
,
kern
,
topgrad
,
shape
):
# Make sure both inputs have the same Type
# Make sure both inputs are Variables with the same Type
if
not
isinstance
(
kern
,
theano
.
Variable
):
kern
=
as_tensor_variable
(
kern
)
if
not
isinstance
(
topgrad
,
theano
.
Variable
):
topgrad
=
as_tensor_variable
(
topgrad
)
gtype
=
kern
.
type
.
clone
(
dtype
=
topgrad
.
dtype
,
broadcastable
=
topgrad
.
broadcastable
)
topgrad
=
gtype
.
filter_variable
(
topgrad
)
...
...
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
4e7913c2
...
...
@@ -441,6 +441,8 @@ class TestConvTypes(unittest.TestCase):
self
.
filters
=
tensor
.
ftensor4
()
self
.
topgrad
=
tensor
.
ftensor4
()
self
.
constant_tensor
=
numpy
.
zeros
((
3
,
5
,
7
,
11
),
dtype
=
'float32'
)
def
test_grad_types
(
self
):
# This function simply tests the behaviour of the AbstractConv
# Ops, not their optimizations
...
...
@@ -477,3 +479,48 @@ class TestConvTypes(unittest.TestCase):
grad_filters
,
grad_filters
.
type
,
filters
,
filters
.
type
)
assert
grad_topgrad
.
type
==
topgrad
.
type
,
(
grad_topgrad
,
grad_topgrad
.
type
,
topgrad
,
topgrad
.
type
)
def
test_constant_input
(
self
):
# Check the AbstractConv Ops for constant inputs
input
=
self
.
input
filters
=
self
.
filters
topgrad
=
self
.
topgrad
constant_tensor
=
self
.
constant_tensor
out_shape
=
tensor
.
lvector
()
# Check the forward Op
output
=
conv
.
conv2d
(
constant_tensor
,
filters
)
grad_filters
=
theano
.
grad
(
output
.
sum
(),
wrt
=
filters
)
assert
grad_filters
.
type
==
filters
.
type
,
(
grad_filters
,
grad_filters
.
type
,
filters
,
filters
.
type
)
output
=
conv
.
conv2d
(
input
,
constant_tensor
)
grad_input
=
theano
.
grad
(
output
.
sum
(),
wrt
=
input
)
assert
grad_input
.
type
==
input
.
type
,
(
grad_input
,
grad_input
.
type
,
input
,
input
.
type
)
# Check grad wrt weights
grad_filters
=
conv
.
AbstractConv2d_gradWeights
()(
constant_tensor
,
topgrad
,
out_shape
)
grad_topgrad
=
theano
.
grad
(
grad_filters
.
sum
(),
wrt
=
topgrad
)
assert
grad_topgrad
.
type
==
topgrad
.
type
,
(
grad_topgrad
,
grad_topgrad
.
type
,
topgrad
,
topgrad
.
type
)
grad_filters
=
conv
.
AbstractConv2d_gradWeights
()(
input
,
constant_tensor
,
out_shape
)
grad_input
=
theano
.
grad
(
grad_filters
.
sum
(),
wrt
=
input
)
assert
grad_input
.
type
==
input
.
type
,
(
grad_input
,
grad_input
.
type
,
input
,
input
.
type
)
# Check grad wrt inputs
grad_input
=
conv
.
AbstractConv2d_gradInputs
()(
constant_tensor
,
topgrad
,
out_shape
)
grad_topgrad
=
theano
.
grad
(
grad_input
.
sum
(),
wrt
=
topgrad
)
assert
grad_topgrad
.
type
==
topgrad
.
type
,
(
grad_topgrad
,
grad_topgrad
.
type
,
topgrad
,
topgrad
.
type
)
grad_input
=
conv
.
AbstractConv2d_gradInputs
()(
filters
,
constant_tensor
,
out_shape
)
grad_filters
=
theano
.
grad
(
grad_input
.
sum
(),
wrt
=
filters
)
assert
grad_filters
.
type
==
filters
.
type
,
(
grad_filters
,
grad_filters
.
type
,
filters
,
filters
.
type
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论