Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
717f2534
提交
717f2534
authored
8月 25, 2017
作者:
Vikram
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Dilated causal wrapper fn. float32 error fixed
上级
e514f4d3
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
81 行增加
和
4 行删除
+81
-4
abstract_conv.py
theano/tensor/nnet/abstract_conv.py
+48
-0
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+33
-4
没有找到文件。
theano/tensor/nnet/abstract_conv.py
浏览文件 @
717f2534
...
@@ -1505,6 +1505,54 @@ def conv3d_grad_wrt_weights(input,
...
@@ -1505,6 +1505,54 @@ def conv3d_grad_wrt_weights(input,
return
gradWeight_op
(
input
,
output_grad
,
filter_shape
[
-
3
:])
return
gradWeight_op
(
input
,
output_grad
,
filter_shape
[
-
3
:])
def
dilated_causal_conv
(
input
,
filters
,
filter_shape
,
input_shape
=
None
,
subsample
=
1
,
filter_flip
=
True
,
filter_dilation
=
1
,
num_groups
=
1
):
input
=
as_tensor_variable
(
input
)
filters
=
as_tensor_variable
(
filters
)
if
input
.
ndim
!=
3
:
raise
ValueError
(
'Input should be 3D for Dilated Causal convolution.'
)
if
filters
.
ndim
!=
3
:
raise
ValueError
(
'Filters should be 3D for Dilated Causal convolution'
)
input
=
input
.
dimshuffle
(
0
,
1
,
2
,
'x'
)
filters
=
filters
.
dimshuffle
(
0
,
1
,
2
,
'x'
)
if
input_shape
is
not
None
:
assert
(
len
(
input_shape
)
==
3
)
input_shape
=
tuple
(
input_shape
)
input_shape
+=
(
1
,)
assert
(
len
(
filter_shape
)
==
3
)
filter_shape
=
tuple
(
filter_shape
)
filter_shape
+=
(
1
,)
left_pad
=
filter_dilation
*
(
filter_shape
[
2
]
-
1
)
subsample
=
(
subsample
,
1
)
filter_dilation
=
(
filter_dilation
,
1
)
conv_op
=
AbstractConv2d
(
imshp
=
input_shape
,
kshp
=
filter_shape
,
border_mode
=
((
left_pad
,
0
),
0
),
subsample
=
subsample
,
filter_flip
=
filter_flip
,
filter_dilation
=
filter_dilation
,
num_groups
=
num_groups
,
unshared
=
False
)
output
=
conv_op
(
input
,
filters
)
shape
=
output
.
shape
[:
-
1
]
return
output
.
reshape
(
shape
)
def
bilinear_kernel_2D
(
ratio
,
normalize
=
True
):
def
bilinear_kernel_2D
(
ratio
,
normalize
=
True
):
"""Compute 2D kernel for bilinear upsampling
"""Compute 2D kernel for bilinear upsampling
...
...
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
717f2534
...
@@ -24,6 +24,7 @@ from theano.tensor.nnet.abstract_conv import bilinear_kernel_1D
...
@@ -24,6 +24,7 @@ from theano.tensor.nnet.abstract_conv import bilinear_kernel_1D
from
theano.tensor.nnet.abstract_conv
import
bilinear_kernel_2D
from
theano.tensor.nnet.abstract_conv
import
bilinear_kernel_2D
from
theano.tensor.nnet.abstract_conv
import
bilinear_upsampling
from
theano.tensor.nnet.abstract_conv
import
bilinear_upsampling
from
theano.tensor.nnet.abstract_conv
import
separable_conv2d
,
separable_conv3d
from
theano.tensor.nnet.abstract_conv
import
separable_conv2d
,
separable_conv3d
from
theano.tensor.nnet.abstract_conv
import
dilated_causal_conv
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.corr3d
import
(
Corr3dMM
,
Corr3dMM_gradWeights
,
from
theano.tensor.nnet.corr3d
import
(
Corr3dMM
,
Corr3dMM_gradWeights
,
...
@@ -1909,8 +1910,8 @@ class TestAsymmetricPadding(unittest.TestCase):
...
@@ -1909,8 +1910,8 @@ class TestAsymmetricPadding(unittest.TestCase):
imshp
=
(
3
,
2
,
4
,
4
)
imshp
=
(
3
,
2
,
4
,
4
)
kshp
=
(
4
,
2
,
2
,
2
)
kshp
=
(
4
,
2
,
2
,
2
)
topshp
=
(
3
,
4
,
6
,
5
)
topshp
=
(
3
,
4
,
6
,
6
)
pad
=
((
1
,
2
),
(
1
,
1
))
pad
=
((
1
,
2
),
(
2
,
1
))
def
test_fwd
(
self
):
def
test_fwd
(
self
):
img_sym
=
theano
.
tensor
.
tensor4
(
'img'
)
img_sym
=
theano
.
tensor
.
tensor4
(
'img'
)
...
@@ -1936,7 +1937,7 @@ class TestAsymmetricPadding(unittest.TestCase):
...
@@ -1936,7 +1937,7 @@ class TestAsymmetricPadding(unittest.TestCase):
self
.
imshp
[
2
]
+
self
.
pad
[
0
][
0
]
+
self
.
pad
[
0
][
1
],
self
.
imshp
[
2
]
+
self
.
pad
[
0
][
0
]
+
self
.
pad
[
0
][
1
],
self
.
imshp
[
3
]
+
self
.
pad
[
1
][
0
]
+
self
.
pad
[
1
][
1
])
self
.
imshp
[
3
]
+
self
.
pad
[
1
][
0
]
+
self
.
pad
[
1
][
1
])
exp_img
=
np
.
zeros
(
exp_imshp
)
exp_img
=
np
.
zeros
(
exp_imshp
,
dtype
=
theano
.
config
.
floatX
)
exp_img
[:,
:,
self
.
pad
[
0
][
0
]:
self
.
imshp
[
2
]
+
self
.
pad
[
0
][
0
],
exp_img
[:,
:,
self
.
pad
[
0
][
0
]:
self
.
imshp
[
2
]
+
self
.
pad
[
0
][
0
],
self
.
pad
[
1
][
0
]:
self
.
imshp
[
3
]
+
self
.
pad
[
1
][
0
]]
=
img
self
.
pad
[
1
][
0
]:
self
.
imshp
[
3
]
+
self
.
pad
[
1
][
0
]]
=
img
ref_output
=
ref_func
(
exp_img
,
kern
)
ref_output
=
ref_func
(
exp_img
,
kern
)
...
@@ -1969,7 +1970,7 @@ class TestAsymmetricPadding(unittest.TestCase):
...
@@ -1969,7 +1970,7 @@ class TestAsymmetricPadding(unittest.TestCase):
self
.
imshp
[
2
]
+
self
.
pad
[
0
][
0
]
+
self
.
pad
[
0
][
1
],
self
.
imshp
[
2
]
+
self
.
pad
[
0
][
0
]
+
self
.
pad
[
0
][
1
],
self
.
imshp
[
3
]
+
self
.
pad
[
1
][
0
]
+
self
.
pad
[
1
][
1
])
self
.
imshp
[
3
]
+
self
.
pad
[
1
][
0
]
+
self
.
pad
[
1
][
1
])
exp_img
=
np
.
zeros
(
exp_imshp
)
exp_img
=
np
.
zeros
(
exp_imshp
,
dtype
=
theano
.
config
.
floatX
)
exp_img
[:,
:,
self
.
pad
[
0
][
0
]:
self
.
imshp
[
2
]
+
self
.
pad
[
0
][
0
],
exp_img
[:,
:,
self
.
pad
[
0
][
0
]:
self
.
imshp
[
2
]
+
self
.
pad
[
0
][
0
],
self
.
pad
[
1
][
0
]:
self
.
imshp
[
3
]
+
self
.
pad
[
1
][
0
]]
=
img
self
.
pad
[
1
][
0
]:
self
.
imshp
[
3
]
+
self
.
pad
[
1
][
0
]]
=
img
ref_output
=
ref_func
(
exp_img
,
top
)
ref_output
=
ref_func
(
exp_img
,
top
)
...
@@ -2014,3 +2015,31 @@ class TestAsymmetricPadding(unittest.TestCase):
...
@@ -2014,3 +2015,31 @@ class TestAsymmetricPadding(unittest.TestCase):
return
asymmetric_conv_op
(
filters_val
,
output_val
,
tensor
.
as_tensor_variable
(
self
.
imshp
[
-
2
:]))
return
asymmetric_conv_op
(
filters_val
,
output_val
,
tensor
.
as_tensor_variable
(
self
.
imshp
[
-
2
:]))
utt
.
verify_grad
(
conv_gradinputs
,
[
kern
,
top
],
mode
=
self
.
mode
,
eps
=
1
)
utt
.
verify_grad
(
conv_gradinputs
,
[
kern
,
top
],
mode
=
self
.
mode
,
eps
=
1
)
class
TestDilatedCausalConv
(
unittest
.
TestCase
):
mode
=
theano
.
compile
.
mode
.
Mode
(
optimizer
=
'None'
)
imshp
=
(
3
,
2
,
5
)
kshp
=
(
2
,
2
,
3
)
topshp
=
(
3
,
2
,
5
)
def
test_interface
(
self
):
img_sym
=
theano
.
tensor
.
tensor3
(
'img'
)
kern_sym
=
theano
.
tensor
.
tensor3
(
'kern'
)
img
=
np
.
random
.
random
(
self
.
imshp
)
.
astype
(
theano
.
config
.
floatX
)
kern
=
np
.
random
.
random
(
self
.
kshp
)
.
astype
(
theano
.
config
.
floatX
)
sym_out
=
dilated_causal_conv
(
img_sym
,
kern_sym
,
self
.
kshp
,
filter_dilation
=
1
)
causal_func
=
theano
.
function
([
img_sym
,
kern_sym
],
sym_out
,
mode
=
self
.
mode
)
output
=
causal_func
(
img
,
kern
)
assert
output
.
shape
==
self
.
topshp
# def causal_conv(inputs_val, filters_val):
# return dilated_causal_conv(inputs_val, filters_val, self.kshp, filter_dilation=1)
# utt.verify_grad(causal_conv, [img, kern], mode=self.mode, eps=1)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论