Theano Tutorial文档翻译(八) - 怎样标准化Theano的信息


原文地址:http://deeplearning.net/software/theano/tutorial/shape_info.html


严格给定Theano变量的形状是不太可能的,当一个特定值被在实时提供到Theano函数是,函数会确定条件的形状。

目前,不管形状Theano的信息在两种方法被使用:
- 当标准形状提前被知道时,为了生成更快的C代码在CPU和GPU的2维卷积。
- 当我们只需要知道形状而不需要具体的值时。

import theano
x = theano.tensor.matrix('x')
f = theano.function([x], (x**2).shape)
theano.printing.debugprint(f)
#MakeVector{dtype='int64'} [id A] ''   2
# |Shape_i{0} [id B] ''   1
# | |x [id C]
# |Shape_i{1} [id D] ''   0
#   |x [id C]

输出的编译函数不会包括任意乘法或乘方。Theano移除了他们为了直接计算他们的形状。

Shape Inference Problem 形状确定问题

Theano在图里传播形状的信息。有时候会带来问题。

import numpy
import theano
x = theano.tensor.matrix('x')
y = theano.tensor.matrix('y')
z = theano.tensor.join(0, x, y)
xv = numpy.random.rand(5,4)
yv = numpy.random.rand(3,3)
f = theano.function([x, y], z.shape)
theano.printing.debugprint(f)
#MakeVector{dtype='int64'} [id A] ''   4
# |Elemwise{Add}[(0, 0)] [id B] ''   3
# | |Shape_i{0} [id C] ''   1
# | | |x [id D]
# | |Shape_i{0} [id E] ''   2
# |   |y [id F]
# |Shape_i{1} [id G] ''   0
#   |x [id D]
f(xv, yv)
# 没有问题
f = theano.function([x,y],z)
theano.orinting.debugprintf(f)
#Join [id A] ''   0
# |TensorConstant{0} [id B]
# |x [id C]
# |y [id D]
f(xv, yv)
# 出错
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值