无符号名称usag

2024-04-25 08:58:22 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我们已经初始化了一个变量:

import theano.tensor as T
x = T.dscalar('x')

我不明白的是字符串参数的用途。根据文件:

By calling T.dscalar with a string argument, you create a Variable representing a floating-point scalar quantity with the given name. If you provide no argument, the symbol will be unnamed. Names are not required, but they can help debugging.

我不知道这到底意味着什么。一个人如何使用这个论点,在什么情况下它是相关的?你知道吗

从目前的情况来看,所呈现的代码

from theano import function
x = T.dscalar('x')
y = T.dscalar('y')
z = x + y
f = function([x, y], z)

如果我从初始化中删除参数,也可以运行

x = T.dscalar()
y = T.dscalar()

或者使用任何其他符号,即使两者都使用相同的符号,功能似乎不会改变。你知道吗

更让人困惑的是变量和参数都是“x”。用不同的名字命名它有用吗?你知道吗

那么,这个论点在什么情况下有用呢?你知道吗


Tags: the字符串importyou参数aswith符号
1条回答
网友
1楼 · 发布于 2024-04-25 08:58:22

调试。

import theano as th
import theano.tensor as T
x = T.scalar()
y = T.scalar()
th.printing.pp(x+y)
#'(<TensorType(float32, scalar)> + <TensorType(float32, scalar)>)'
x = T.scalar('x')
y = T.scalar('y')
th.printing.pp(x+y)
#'(x + y)'

还有这个:

>>> x,y = T.scalars('xy')
>>> fn = th.function([x,y], x+y)
>>> th.printing.debugprint(fn)
HostFromGpu(gpuarray) [id A] ''   3
 |GpuElemwise{Add}[(0, 0)]<gpuarray> [id B] ''   2
   |GpuFromHost<None> [id C] ''   1
   | |x [id D]
   |GpuFromHost<None> [id E] ''   0
     |y [id F]

如果您有一个大型模型,那么在调用theano.printing.pptheano.printing.debugprint时,给符号变量起一些名字确实有帮助。你知道吗

有时,模型可能会由于形状不匹配或其他错误而崩溃,如果在.theanorc中有exception_verbosity = high,则相关的模型图将被转储为theano.printing.debugprint。使用已定义的名称,转储看起来会更好,并减少调试所花的时间。你知道吗

相关问题 更多 >