Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4e25e6c1
提交
4e25e6c1
authored
8月 24, 2017
作者:
Vikram
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Errors fixed
上级
caccc5f8
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
44 行增加
和
23 行删除
+44
-23
abstract_conv.py
theano/tensor/nnet/abstract_conv.py
+41
-20
corr.py
theano/tensor/nnet/corr.py
+3
-3
没有找到文件。
theano/tensor/nnet/abstract_conv.py
浏览文件 @
4e25e6c1
...
@@ -123,22 +123,29 @@ def get_conv_shape_1axis(image_shape, kernel_shape, border_mode,
...
@@ -123,22 +123,29 @@ def get_conv_shape_1axis(image_shape, kernel_shape, border_mode,
# Implicit dilated kernel shape
# Implicit dilated kernel shape
dil_kernel_shape
=
(
kernel_shape
-
1
)
*
dilation
+
1
dil_kernel_shape
=
(
kernel_shape
-
1
)
*
dilation
+
1
if
border_mode
==
"half"
:
if
border_mode
==
"half"
:
pad
=
dil_kernel_shape
//
2
pad
_l
=
pad_r
=
dil_kernel_shape
//
2
elif
border_mode
==
"full"
:
elif
border_mode
==
"full"
:
pad
=
dil_kernel_shape
-
1
pad
_l
=
pad_r
=
dil_kernel_shape
-
1
elif
border_mode
==
"valid"
:
elif
border_mode
==
"valid"
:
pad
=
0
pad
_l
=
pad_r
=
0
else
:
else
:
pad
=
border_mode
if
isinstance
(
border_mode
,
tuple
):
if
pad
<
0
:
pad_l
,
pad_r
=
border_mode
else
:
pad_l
=
pad_r
=
border_mode
if
pad_l
<
0
or
pad_r
<
0
:
raise
ValueError
(
"border_mode must be >= 0"
)
raise
ValueError
(
"border_mode must be >= 0"
)
# In case of symbolic shape, we want to build the smallest graph
# In case of symbolic shape, we want to build the smallest graph
# (image_shape + 2 * pad - dil_kernel_shape) // subsample + 1
# (image_shape + 2 * pad - dil_kernel_shape) // subsample + 1
if
pad
==
0
:
if
pad
_l
==
0
and
pad_r
==
0
:
out_shp
=
(
image_shape
-
dil_kernel_shape
)
out_shp
=
(
image_shape
-
dil_kernel_shape
)
elif
pad_l
==
0
:
out_shp
=
(
image_shape
+
pad_l
-
dil_kernel_shape
)
elif
pad_r
==
0
:
out_shp
=
(
image_shape
+
pad_r
-
dil_kernel_shape
)
else
:
else
:
out_shp
=
(
image_shape
+
2
*
pad
-
dil_kernel_shape
)
out_shp
=
(
image_shape
+
pad_l
+
pad_r
-
dil_kernel_shape
)
if
subsample
!=
1
:
if
subsample
!=
1
:
out_shp
=
out_shp
//
subsample
out_shp
=
out_shp
//
subsample
out_shp
=
out_shp
+
1
out_shp
=
out_shp
+
1
...
@@ -252,9 +259,16 @@ def get_conv_gradweights_shape_1axis(image_shape, top_shape, border_mode,
...
@@ -252,9 +259,16 @@ def get_conv_gradweights_shape_1axis(image_shape, top_shape, border_mode,
elif
border_mode
==
"valid"
:
elif
border_mode
==
"valid"
:
kernel_shape
=
image_shape
-
top_shape
kernel_shape
=
image_shape
-
top_shape
else
:
else
:
if
isinstance
(
border_mode
,
integer_types
):
if
border_mode
<
0
:
if
border_mode
<
0
:
raise
ValueError
(
"border_mode must be >= 0"
)
raise
ValueError
(
"border_mode must be >= 0"
)
kernel_shape
=
(
image_shape
+
2
*
border_mode
-
top_shape
)
pad_l
=
pad_r
=
border_mode
elif
isinstance
(
border_mode
,
tuple
):
if
min
(
border_mode
)
<
0
:
raise
ValueError
(
"border_mode must be >= 0"
)
pad_l
,
pad_r
=
border_mode
kernel_shape
=
(
image_shape
+
pad_l
+
pad_r
-
top_shape
)
if
dilation
>
1
:
if
dilation
>
1
:
kernel_shape
=
kernel_shape
/
dilation
kernel_shape
=
kernel_shape
/
dilation
...
@@ -363,23 +377,30 @@ def get_conv_gradinputs_shape_1axis(kernel_shape, top_shape, border_mode,
...
@@ -363,23 +377,30 @@ def get_conv_gradinputs_shape_1axis(kernel_shape, top_shape, border_mode,
# Implicit dilated kernel shape
# Implicit dilated kernel shape
dil_kernel_shape
=
(
kernel_shape
-
1
)
*
dilation
+
1
dil_kernel_shape
=
(
kernel_shape
-
1
)
*
dilation
+
1
if
border_mode
==
"half"
:
if
border_mode
==
"half"
:
pad
=
dil_kernel_shape
//
2
pad
_l
=
pad_r
=
dil_kernel_shape
//
2
elif
border_mode
==
"full"
:
elif
border_mode
==
"full"
:
pad
=
dil_kernel_shape
-
1
pad
_l
=
pad_r
=
dil_kernel_shape
-
1
elif
border_mode
==
"valid"
:
elif
border_mode
==
"valid"
:
pad
=
0
pad_l
=
pad_r
=
0
else
:
if
isinstance
(
border_mode
,
tuple
):
pad_l
,
pad_r
=
border_mode
else
:
else
:
pad
=
border_mode
pad_l
=
pad_r
=
border_mode
if
pad
<
0
:
if
pad
_l
<
0
or
pad_r
<
0
:
raise
ValueError
(
"border_mode must be >= 0"
)
raise
ValueError
(
"border_mode must be >= 0"
)
# In case of symbolic shape, we want to build the smallest graph
# In case of symbolic shape, we want to build the smallest graph
# image_shape = (top_shape - 1) * s - 2 * pad + dil_kernel_shape + a
# image_shape = (top_shape - 1) * s - 2 * pad + dil_kernel_shape + a
# where 0 <= a < subsample, but we have checked that subsample == 1
# where 0 <= a < subsample, but we have checked that subsample == 1
if
pad
==
0
:
if
pad
_l
==
0
and
pad_r
==
0
:
image_shape
=
(
top_shape
+
dil_kernel_shape
-
1
)
image_shape
=
(
top_shape
+
dil_kernel_shape
-
1
)
elif
pad_l
==
0
:
image_shape
=
(
top_shape
-
pad_l
+
dil_kernel_shape
-
1
)
elif
pad_r
==
0
:
image_shape
=
(
top_shape
-
pad_r
+
dil_kernel_shape
-
1
)
else
:
else
:
image_shape
=
(
top_shape
-
2
*
pad
+
dil_kernel_shape
-
1
)
image_shape
=
(
top_shape
-
pad_l
-
pad_r
+
dil_kernel_shape
-
1
)
return
image_shape
return
image_shape
...
@@ -1762,7 +1783,7 @@ class BaseAbstractConv(Op):
...
@@ -1762,7 +1783,7 @@ class BaseAbstractConv(Op):
'invalid border_mode {} which must be a '
'invalid border_mode {} which must be a '
'tuple of length {}'
.
format
(
border_mode
,
convdim
))
'tuple of length {}'
.
format
(
border_mode
,
convdim
))
for
mode
in
border_mode
:
for
mode
in
border_mode
:
if
not
((
isinstance
(
mode
,
integer_types
)
and
mode
>
0
)
or
if
not
((
isinstance
(
mode
,
integer_types
)
and
mode
>
=
0
)
or
(
isinstance
(
mode
,
tuple
)
and
len
(
mode
)
==
2
and
(
isinstance
(
mode
,
tuple
)
and
len
(
mode
)
==
2
and
min
(
mode
)
>=
0
)):
min
(
mode
)
>=
0
)):
raise
ValueError
(
raise
ValueError
(
...
@@ -2042,7 +2063,7 @@ class AbstractConv(BaseAbstractConv):
...
@@ -2042,7 +2063,7 @@ class AbstractConv(BaseAbstractConv):
'tuple of length {}'
.
format
(
mode
,
self
.
convdim
))
'tuple of length {}'
.
format
(
mode
,
self
.
convdim
))
border
=
()
border
=
()
for
m
in
mode
:
for
m
in
mode
:
if
isinstance
(
m
,
integer_types
)
and
m
>
0
:
if
isinstance
(
m
,
integer_types
)
and
m
>
=
0
:
border
+=
((
m
,
m
),)
border
+=
((
m
,
m
),)
elif
isinstance
(
m
,
tuple
)
and
len
(
m
)
==
2
and
\
elif
isinstance
(
m
,
tuple
)
and
len
(
m
)
==
2
and
\
min
(
m
)
>=
0
:
min
(
m
)
>=
0
:
...
@@ -2329,7 +2350,7 @@ class AbstractConv_gradWeights(BaseAbstractConv):
...
@@ -2329,7 +2350,7 @@ class AbstractConv_gradWeights(BaseAbstractConv):
'tuple of length {}'
.
format
(
mode
,
self
.
convdim
))
'tuple of length {}'
.
format
(
mode
,
self
.
convdim
))
border
=
()
border
=
()
for
m
in
mode
:
for
m
in
mode
:
if
isinstance
(
m
,
integer_types
)
and
m
>
0
:
if
isinstance
(
m
,
integer_types
)
and
m
>
=
0
:
border
+=
((
m
,
m
),)
border
+=
((
m
,
m
),)
elif
isinstance
(
m
,
tuple
)
and
len
(
m
)
==
2
and
\
elif
isinstance
(
m
,
tuple
)
and
len
(
m
)
==
2
and
\
min
(
m
)
>=
0
:
min
(
m
)
>=
0
:
...
@@ -2659,7 +2680,7 @@ class AbstractConv_gradInputs(BaseAbstractConv):
...
@@ -2659,7 +2680,7 @@ class AbstractConv_gradInputs(BaseAbstractConv):
'tuple of length {}'
.
format
(
mode
,
self
.
convdim
))
'tuple of length {}'
.
format
(
mode
,
self
.
convdim
))
border
=
()
border
=
()
for
m
in
mode
:
for
m
in
mode
:
if
isinstance
(
m
,
integer_types
)
and
m
>
0
:
if
isinstance
(
m
,
integer_types
)
and
m
>
=
0
:
border
+=
((
m
,
m
),)
border
+=
((
m
,
m
),)
elif
isinstance
(
m
,
tuple
)
and
len
(
m
)
==
2
and
\
elif
isinstance
(
m
,
tuple
)
and
len
(
m
)
==
2
and
\
min
(
m
)
>=
0
:
min
(
m
)
>=
0
:
...
@@ -2696,7 +2717,7 @@ class AbstractConv_gradInputs(BaseAbstractConv):
...
@@ -2696,7 +2717,7 @@ class AbstractConv_gradInputs(BaseAbstractConv):
dil_kernshp
=
tuple
((
kern
.
shape
[
-
self
.
convdim
+
i
]
-
1
)
*
self
.
filter_dilation
[
i
]
+
1
dil_kernshp
=
tuple
((
kern
.
shape
[
-
self
.
convdim
+
i
]
-
1
)
*
self
.
filter_dilation
[
i
]
+
1
for
i
in
range
(
self
.
convdim
))
for
i
in
range
(
self
.
convdim
))
pad
=
(
0
,)
*
self
.
convdim
pad
=
(
(
0
,
0
)
,)
*
self
.
convdim
if
mode
==
"full"
:
if
mode
==
"full"
:
pad
=
tuple
((
dil_kernshp
[
i
]
-
1
,)
*
2
for
i
in
range
(
self
.
convdim
))
pad
=
tuple
((
dil_kernshp
[
i
]
-
1
,)
*
2
for
i
in
range
(
self
.
convdim
))
elif
mode
==
"half"
:
elif
mode
==
"half"
:
...
...
theano/tensor/nnet/corr.py
浏览文件 @
4e25e6c1
...
@@ -75,7 +75,7 @@ class BaseCorrMM(gof.OpenMPOp):
...
@@ -75,7 +75,7 @@ class BaseCorrMM(gof.OpenMPOp):
'tuple of length 2'
.
format
(
border_mode
))
'tuple of length 2'
.
format
(
border_mode
))
border
=
()
border
=
()
for
mode
in
border_mode
:
for
mode
in
border_mode
:
if
isinstance
(
mode
,
integer_types
)
and
mode
>
0
:
if
isinstance
(
mode
,
integer_types
)
and
mode
>
=
0
:
border
+=
((
mode
,
mode
),)
border
+=
((
mode
,
mode
),)
elif
isinstance
(
mode
,
tuple
)
and
len
(
mode
)
==
2
and
\
elif
isinstance
(
mode
,
tuple
)
and
len
(
mode
)
==
2
and
\
min
(
mode
)
>=
0
:
min
(
mode
)
>=
0
:
...
@@ -489,8 +489,8 @@ class BaseCorrMM(gof.OpenMPOp):
...
@@ -489,8 +489,8 @@ class BaseCorrMM(gof.OpenMPOp):
// height and width: bottom = (top - 1) * sample + (weights-1)*dil + 1 - 2*pad
// height and width: bottom = (top - 1) * sample + (weights-1)*dil + 1 - 2*pad
out_dim[0] = (npy_intp)PyArray_DIMS(top)[0];
out_dim[0] = (npy_intp)PyArray_DIMS(top)[0];
out_dim[1] = (npy_intp)PyArray_DIMS(weights)[wdim-3] * numgroups;
out_dim[1] = (npy_intp)PyArray_DIMS(weights)[wdim-3] * numgroups;
out_dim[2] = (npy_intp)((
%(height)
s != -1) ?
%(height)
s : (PyArray_DIMS(top)[2] - 1) * dH + (PyArray_DIMS(weights)[wdim-2]-1)*dilH + 1 -
2*padH
);
out_dim[2] = (npy_intp)((
%(height)
s != -1) ?
%(height)
s : (PyArray_DIMS(top)[2] - 1) * dH + (PyArray_DIMS(weights)[wdim-2]-1)*dilH + 1 -
padH_l - padH_r
);
out_dim[3] = (npy_intp)((
%(width)
s != -1) ?
%(width)
s : (PyArray_DIMS(top)[3] - 1) * dW + (PyArray_DIMS(weights)[wdim-1]-1)*dilW + 1 -
2*padW
);
out_dim[3] = (npy_intp)((
%(width)
s != -1) ?
%(width)
s : (PyArray_DIMS(top)[3] - 1) * dW + (PyArray_DIMS(weights)[wdim-1]-1)*dilW + 1 -
padW_l - padW_r
);
if (unshared) {
if (unshared) {
if (out_dim[0] < 0 || out_dim[1] < 0 || out_dim[2] <= 0 || out_dim[3] <= 0)
if (out_dim[0] < 0 || out_dim[1] < 0 || out_dim[2] <= 0 || out_dim[3] <= 0)
{
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论