Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c52b9396
提交
c52b9396
authored
2月 23, 2017
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't add twice the Assert about shape in AbstractConv
上级
f1fdacc3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
16 行增加
和
13 行删除
+16
-13
abstract_conv.py
theano/tensor/nnet/abstract_conv.py
+16
-13
没有找到文件。
theano/tensor/nnet/abstract_conv.py
浏览文件 @
c52b9396
...
@@ -1680,19 +1680,20 @@ class AbstractConv2d(AbstractConv):
...
@@ -1680,19 +1680,20 @@ class AbstractConv2d(AbstractConv):
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
bottom
,
weights
=
inp
bottom
,
weights
=
inp
top
,
=
grads
top
,
=
grads
# Don't add the assert again, as it was already added in the forward.
d_bottom
=
AbstractConv2d_gradInputs
(
self
.
imshp
,
self
.
kshp
,
d_bottom
=
AbstractConv2d_gradInputs
(
self
.
imshp
,
self
.
kshp
,
self
.
border_mode
,
self
.
border_mode
,
self
.
subsample
,
self
.
subsample
,
self
.
filter_flip
,
self
.
filter_flip
,
self
.
filter_dilation
)(
self
.
filter_dilation
)(
weights
,
top
,
bottom
.
shape
[
-
2
:])
weights
,
top
,
bottom
.
shape
[
-
2
:]
,
add_assert_shape
=
False
)
d_weights
=
AbstractConv2d_gradWeights
(
self
.
imshp
,
self
.
kshp
,
d_weights
=
AbstractConv2d_gradWeights
(
self
.
imshp
,
self
.
kshp
,
self
.
border_mode
,
self
.
border_mode
,
self
.
subsample
,
self
.
subsample
,
self
.
filter_flip
,
self
.
filter_flip
,
self
.
filter_dilation
)(
self
.
filter_dilation
)(
bottom
,
top
,
weights
.
shape
[
-
2
:])
bottom
,
top
,
weights
.
shape
[
-
2
:]
,
add_assert_shape
=
False
)
# Make sure that the broadcastable pattern of the inputs is used
# Make sure that the broadcastable pattern of the inputs is used
# for the gradients, even if the grad opts are not able to infer
# for the gradients, even if the grad opts are not able to infer
...
@@ -1781,7 +1782,7 @@ class AbstractConv_gradWeights(BaseAbstractConv):
...
@@ -1781,7 +1782,7 @@ class AbstractConv_gradWeights(BaseAbstractConv):
filter_dilation
=
filter_dilation
)
filter_dilation
=
filter_dilation
)
# Update shape/height_width
# Update shape/height_width
def
make_node
(
self
,
img
,
topgrad
,
shape
):
def
make_node
(
self
,
img
,
topgrad
,
shape
,
add_assert_shape
=
True
):
# Make sure both inputs are Variables with the same Type
# Make sure both inputs are Variables with the same Type
if
not
isinstance
(
img
,
theano
.
Variable
):
if
not
isinstance
(
img
,
theano
.
Variable
):
img
=
as_tensor_variable
(
img
)
img
=
as_tensor_variable
(
img
)
...
@@ -1795,10 +1796,10 @@ class AbstractConv_gradWeights(BaseAbstractConv):
...
@@ -1795,10 +1796,10 @@ class AbstractConv_gradWeights(BaseAbstractConv):
raise
TypeError
(
'img must be
%
dD tensor'
%
(
2
+
self
.
convdim
))
raise
TypeError
(
'img must be
%
dD tensor'
%
(
2
+
self
.
convdim
))
if
topgrad
.
type
.
ndim
!=
2
+
self
.
convdim
:
if
topgrad
.
type
.
ndim
!=
2
+
self
.
convdim
:
raise
TypeError
(
'topgrad must be
%
dD tensor'
%
(
2
+
self
.
convdim
))
raise
TypeError
(
'topgrad must be
%
dD tensor'
%
(
2
+
self
.
convdim
))
if
add_assert_shape
:
img
=
assert_shape
(
img
,
self
.
imshp
,
img
=
assert_shape
(
img
,
self
.
imshp
,
'AbstractConv_gradWeights shape mismatch: shape of '
'AbstractConv_gradWeights shape mismatch: shape of '
'image does not match given imshp.'
)
'image does not match given imshp.'
)
shape
=
as_tensor_variable
(
shape
)
shape
=
as_tensor_variable
(
shape
)
broadcastable
=
[
topgrad
.
broadcastable
[
1
],
broadcastable
=
[
topgrad
.
broadcastable
[
1
],
...
@@ -2020,7 +2021,7 @@ class AbstractConv_gradInputs(BaseAbstractConv):
...
@@ -2020,7 +2021,7 @@ class AbstractConv_gradInputs(BaseAbstractConv):
filter_dilation
=
filter_dilation
)
filter_dilation
=
filter_dilation
)
# Update shape/height_width
# Update shape/height_width
def
make_node
(
self
,
kern
,
topgrad
,
shape
):
def
make_node
(
self
,
kern
,
topgrad
,
shape
,
add_assert_shape
=
True
):
# Make sure both inputs are Variables with the same Type
# Make sure both inputs are Variables with the same Type
if
not
isinstance
(
kern
,
theano
.
Variable
):
if
not
isinstance
(
kern
,
theano
.
Variable
):
kern
=
as_tensor_variable
(
kern
)
kern
=
as_tensor_variable
(
kern
)
...
@@ -2035,9 +2036,10 @@ class AbstractConv_gradInputs(BaseAbstractConv):
...
@@ -2035,9 +2036,10 @@ class AbstractConv_gradInputs(BaseAbstractConv):
if
topgrad
.
type
.
ndim
!=
2
+
self
.
convdim
:
if
topgrad
.
type
.
ndim
!=
2
+
self
.
convdim
:
raise
TypeError
(
'topgrad must be
%
dD tensor'
%
(
2
+
self
.
convdim
))
raise
TypeError
(
'topgrad must be
%
dD tensor'
%
(
2
+
self
.
convdim
))
kern
=
assert_shape
(
kern
,
self
.
kshp
,
if
add_assert_shape
:
'AbstractConv_gradInputs shape mismatch: shape of '
kern
=
assert_shape
(
kern
,
self
.
kshp
,
'filters does not match given kshp.'
)
'AbstractConv_gradInputs shape mismatch: shape of '
'filters does not match given kshp.'
)
shape
=
as_tensor_variable
(
shape
)
shape
=
as_tensor_variable
(
shape
)
broadcastable
=
[
topgrad
.
type
.
broadcastable
[
0
],
broadcastable
=
[
topgrad
.
type
.
broadcastable
[
0
],
...
@@ -2158,8 +2160,9 @@ class AbstractConv2d_gradInputs(AbstractConv_gradInputs):
...
@@ -2158,8 +2160,9 @@ class AbstractConv2d_gradInputs(AbstractConv_gradInputs):
self
.
border_mode
,
self
.
border_mode
,
self
.
subsample
,
self
.
subsample
,
self
.
filter_flip
,
self
.
filter_flip
,
self
.
filter_dilation
)(
bottom
,
top
,
self
.
filter_dilation
)(
weights
.
shape
[
-
2
:])
bottom
,
top
,
weights
.
shape
[
-
2
:])
d_top
=
AbstractConv2d
(
self
.
imshp
,
self
.
kshp
,
d_top
=
AbstractConv2d
(
self
.
imshp
,
self
.
kshp
,
self
.
border_mode
,
self
.
border_mode
,
self
.
subsample
,
self
.
subsample
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论