Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cdfd55e7
提交
cdfd55e7
authored
3月 02, 2015
作者:
Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
address some comments, grad of maxpooling with padding still not working
上级
1abd8ee1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
39 行删除
+22
-39
downsample.py
theano/tensor/signal/downsample.py
+22
-39
没有找到文件。
theano/tensor/signal/downsample.py
浏览文件 @
cdfd55e7
...
@@ -12,7 +12,6 @@ import numpy
...
@@ -12,7 +12,6 @@ import numpy
import
theano
import
theano
from
theano
import
gof
,
Op
,
tensor
,
Variable
,
Apply
from
theano
import
gof
,
Op
,
tensor
,
Variable
,
Apply
def
max_pool2D
(
*
args
,
**
kwargs
):
def
max_pool2D
(
*
args
,
**
kwargs
):
import
sys
import
sys
print
>>
sys
.
stderr
,
"DEPRECATION: max_pool2D renamed to max_pool_2d"
print
>>
sys
.
stderr
,
"DEPRECATION: max_pool2D renamed to max_pool_2d"
...
@@ -185,7 +184,7 @@ class DownsampleFactorMax(Op):
...
@@ -185,7 +184,7 @@ class DownsampleFactorMax(Op):
if
self
.
padding
[
0
]
>=
self
.
ds
[
0
]
or
self
.
padding
[
1
]
>=
self
.
ds
[
1
]:
if
self
.
padding
[
0
]
>=
self
.
ds
[
0
]
or
self
.
padding
[
1
]
>=
self
.
ds
[
1
]:
raise
NotImplementedError
(
'padding_h and padding_w must be smaller than strides'
)
raise
NotImplementedError
(
'padding_h and padding_w must be smaller than strides'
)
def
__str__
(
self
):
def
__str__
(
self
):
return
'
%
s{
%
s,
%
s,
%
s,
%
s}'
%
(
self
.
__class__
.
__name__
,
return
'
%
s{
%
s,
%
s,
%
s,
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
ds
,
self
.
st
,
self
.
ignore_border
,
self
.
padding
)
self
.
ds
,
self
.
st
,
self
.
ignore_border
,
self
.
padding
)
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
...
@@ -220,19 +219,12 @@ class DownsampleFactorMax(Op):
...
@@ -220,19 +219,12 @@ class DownsampleFactorMax(Op):
img_cols
=
x
.
shape
[
-
1
]
+
2
*
self
.
padding
[
1
]
img_cols
=
x
.
shape
[
-
1
]
+
2
*
self
.
padding
[
1
]
pad_h
=
self
.
padding
[
0
]
pad_h
=
self
.
padding
[
0
]
pad_w
=
self
.
padding
[
1
]
pad_w
=
self
.
padding
[
1
]
def
pad_img
(
x
):
w
=
x
.
shape
[
3
]
# pad the image
h
=
x
.
shape
[
2
]
fill
=
x
.
min
()
-
1
fill
=
x
.
min
()
-
1
y
=
numpy
.
zeros
((
x
.
shape
[
0
],
x
.
shape
[
1
],
img_rows
,
img_cols
))
+
fill
t
=
numpy
.
ones
((
x
.
shape
[
0
],
x
.
shape
[
1
],
1
,
1
))
y
[:,
:,
pad_h
:
-
pad_h
,
pad_w
:
-
pad_w
]
=
x
ud_bar
=
(
numpy
.
zeros
((
pad_h
,
w
))
+
fill
)[
# max pooling
numpy
.
newaxis
,
numpy
.
newaxis
,:,:]
*
t
lr_bar
=
(
numpy
.
zeros
((
pad_h
*
2
+
h
,
pad_w
))
+
fill
)[
numpy
.
newaxis
,
numpy
.
newaxis
,:,:]
*
t
y
=
numpy
.
concatenate
([
ud_bar
,
x
,
ud_bar
],
axis
=
2
)
y
=
numpy
.
concatenate
([
lr_bar
,
y
,
lr_bar
],
axis
=
3
)
return
y
y
=
pad_img
(
x
)
for
n
in
xrange
(
x
.
shape
[
0
]):
for
n
in
xrange
(
x
.
shape
[
0
]):
for
k
in
xrange
(
x
.
shape
[
1
]):
for
k
in
xrange
(
x
.
shape
[
1
]):
for
r
in
xrange
(
pr
):
for
r
in
xrange
(
pr
):
...
@@ -377,27 +369,12 @@ class DownsampleFactorMaxGrad(Op):
...
@@ -377,27 +369,12 @@ class DownsampleFactorMaxGrad(Op):
img_cols
=
x
.
shape
[
-
1
]
+
2
*
self
.
padding
[
1
]
img_cols
=
x
.
shape
[
-
1
]
+
2
*
self
.
padding
[
1
]
pad_h
=
self
.
padding
[
0
]
pad_h
=
self
.
padding
[
0
]
pad_w
=
self
.
padding
[
1
]
pad_w
=
self
.
padding
[
1
]
def
pad_img
(
x
):
w
=
x
.
shape
[
3
]
h
=
x
.
shape
[
2
]
# pad the image
fill
=
x
.
min
()
-
1.
fill
=
x
.
min
()
-
1
t
=
numpy
.
ones
((
x
.
shape
[
0
],
x
.
shape
[
1
],
1
,
1
))
y
=
numpy
.
zeros
((
x
.
shape
[
0
],
x
.
shape
[
1
],
img_rows
,
img_cols
))
+
fill
ud_bar
=
(
numpy
.
zeros
((
pad_h
,
w
))
+
fill
)[
y
[:,
:,
pad_h
:
-
pad_h
,
pad_w
:
-
pad_w
]
=
x
numpy
.
newaxis
,
numpy
.
newaxis
,:,:]
*
t
lr_bar
=
(
numpy
.
zeros
((
pad_h
*
2
+
h
,
pad_w
))
+
fill
)[
numpy
.
newaxis
,
numpy
.
newaxis
,:,:]
*
t
y
=
numpy
.
concatenate
([
ud_bar
,
x
,
ud_bar
],
axis
=
2
)
y
=
numpy
.
concatenate
([
lr_bar
,
y
,
lr_bar
],
axis
=
3
)
return
y
def
unpad
(
g
):
w
=
x
.
shape
[
3
]
h
=
x
.
shape
[
2
]
r_st
=
pad_h
r_end
=
g
.
shape
[
2
]
-
pad_h
c_st
=
pad_w
c_end
=
g
.
shape
[
3
]
-
pad_w
return
g
[:,:,
r_st
:
r_end
,
c_st
:
c_end
]
y
=
pad_img
(
x
)
gx
=
numpy
.
zeros_like
(
y
)
gx
=
numpy
.
zeros_like
(
y
)
for
n
in
xrange
(
x
.
shape
[
0
]):
for
n
in
xrange
(
x
.
shape
[
0
]):
for
k
in
xrange
(
x
.
shape
[
1
]):
for
k
in
xrange
(
x
.
shape
[
1
]):
...
@@ -411,7 +388,8 @@ class DownsampleFactorMaxGrad(Op):
...
@@ -411,7 +388,8 @@ class DownsampleFactorMaxGrad(Op):
for
col_ind
in
xrange
(
col_st
,
col_end
):
for
col_ind
in
xrange
(
col_st
,
col_end
):
if
(
maxout
[
n
,
k
,
r
,
c
]
==
y
[
n
,
k
,
row_ind
,
col_ind
]):
if
(
maxout
[
n
,
k
,
r
,
c
]
==
y
[
n
,
k
,
row_ind
,
col_ind
]):
gx
[
n
,
k
,
row_ind
,
col_ind
]
+=
gz
[
n
,
k
,
r
,
c
]
gx
[
n
,
k
,
row_ind
,
col_ind
]
+=
gz
[
n
,
k
,
r
,
c
]
gx
=
unpad
(
gx
)
# unpad the image
gx
=
gx
[:,
:,
pad_h
:
-
pad_h
,
pad_w
:
-
pad_w
]
gx_stg
[
0
]
=
gx
gx_stg
[
0
]
=
gx
def
infer_shape
(
self
,
node
,
in_shapes
):
def
infer_shape
(
self
,
node
,
in_shapes
):
...
@@ -420,11 +398,16 @@ class DownsampleFactorMaxGrad(Op):
...
@@ -420,11 +398,16 @@ class DownsampleFactorMaxGrad(Op):
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
x
,
maxout
,
gz
=
inp
x
,
maxout
,
gz
=
inp
ggx
,
=
grads
ggx
,
=
grads
return
[
theano
.
tensor
.
zeros_like
(
x
),
if
self
.
padding
==
(
0
,
0
):
return
[
theano
.
tensor
.
zeros_like
(
x
),
theano
.
tensor
.
zeros_like
(
maxout
),
theano
.
tensor
.
zeros_like
(
maxout
),
DownsampleFactorMaxGradGrad
(
DownsampleFactorMaxGradGrad
(
self
.
ds
,
ignore_border
=
self
.
ignore_border
,
st
=
self
.
st
)(
x
,
maxout
,
ggx
)]
self
.
ds
,
ignore_border
=
self
.
ignore_border
,
st
=
self
.
st
)(
x
,
maxout
,
ggx
)]
else
:
return
[
theano
.
tensor
.
zeros_like
(
x
),
theano
.
tensor
.
zeros_like
(
maxout
),
theano
.
gradients
.
grad_not_implemented
(
self
,
2
,
gz
,
'Hessian not implemented with padding'
]
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
if
self
.
ds
!=
self
.
st
:
if
self
.
ds
!=
self
.
st
:
raise
theano
.
gof
.
utils
.
MethodNotDefined
()
raise
theano
.
gof
.
utils
.
MethodNotDefined
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论