Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2ccd511d
提交
2ccd511d
authored
2月 02, 2017
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Force the abstract BN ops to have common dtype for tensors input.
上级
1e68d76b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
1 行删除
+24
-1
basic.py
theano/scalar/basic.py
+8
-0
bn.py
theano/tensor/nnet/bn.py
+16
-1
没有找到文件。
theano/scalar/basic.py
浏览文件 @
2ccd511d
...
...
@@ -88,6 +88,14 @@ def upcast(dtype, *dtypes):
return
rval
def
as_common_dtype
(
*
vars
):
"""
For for theano.scalar.Scalar and TensorVariable.
"""
dtype
=
upcast
(
*
[
v
.
dtype
for
v
in
vars
])
return
(
v
.
astype
(
dtype
)
for
v
in
vars
)
def
get_scalar_type
(
dtype
):
"""
Return a Scalar(dtype) object.
...
...
theano/tensor/nnet/bn.py
浏览文件 @
2ccd511d
...
...
@@ -7,7 +7,7 @@ from theano.gof.opt import copy_stack_trace
from
theano.tensor
import
as_tensor_variable
,
TensorType
from
theano.tensor
import
basic
as
T
from
theano.tensor.opt
import
register_specialize_device
from
theano.scalar
import
Composite
from
theano.scalar
import
Composite
,
as_common_dtype
from
theano.scalar
import
add
,
sub
,
true_div
,
mul
...
...
@@ -427,6 +427,13 @@ class AbstractBatchNormTrain(Op):
(
running_mean
is
not
None
and
running_var
is
not
None
))
assert
(
running_mean
is
None
or
running_mean
.
ndim
==
x
.
ndim
)
assert
(
running_var
is
None
or
running_var
.
ndim
==
x
.
ndim
)
# Upcast to common dtype on the non-scalar
# Keep as is dtype of scalar (epsilon and running_average_factor)
if
running_mean
:
x
,
scale
,
bias
,
running_mean
,
running_var
=
as_common_dtype
(
x
,
scale
,
bias
,
running_mean
,
running_var
)
else
:
x
,
scale
,
bias
=
as_common_dtype
(
x
,
scale
,
bias
)
inputs
=
[
x
,
scale
,
bias
,
epsilon
,
running_average_factor
]
output_types
=
[
x
.
type
(),
scale
.
type
(),
scale
.
type
()]
if
running_mean
is
not
None
and
running_var
is
not
None
:
...
...
@@ -524,6 +531,10 @@ class AbstractBatchNormInference(Op):
estimated_mean
=
as_tensor_variable
(
estimated_mean
)
estimated_variance
=
as_tensor_variable
(
estimated_variance
)
epsilon
=
as_tensor_variable
(
epsilon
)
# Upcast to common dtype on the non-scalar
# Keep as is dtype of scalar (epsilon)
x
,
scale
,
bias
,
estimated_mean
,
estimated_variance
=
as_common_dtype
(
x
,
scale
,
bias
,
estimated_mean
,
estimated_variance
)
assert
x
.
ndim
==
scale
.
ndim
==
bias
.
ndim
==
estimated_mean
.
ndim
==
estimated_variance
.
ndim
return
Apply
(
self
,
[
x
,
scale
,
bias
,
estimated_mean
,
estimated_variance
,
epsilon
],
[
x
.
type
()])
...
...
@@ -578,6 +589,10 @@ class AbstractBatchNormTrainGrad(Op):
x_invstd
=
as_tensor_variable
(
x_invstd
)
epsilon
=
as_tensor_variable
(
epsilon
)
# Upcast to common dtype on the non-scalar
# Keep as is dtype of scalar (epsilon)
x
,
dy
,
scale
,
x_mean
,
x_invstd
=
as_common_dtype
(
x
,
dy
,
scale
,
x_mean
,
x_invstd
)
assert
x
.
ndim
==
dy
.
ndim
==
scale
.
ndim
==
x_mean
.
ndim
==
x_invstd
.
ndim
return
Apply
(
self
,
[
x
,
dy
,
scale
,
x_mean
,
x_invstd
,
epsilon
],
[
x
.
type
(),
scale
.
type
(),
scale
.
type
()])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论