首先上 关于输出shape信息的这个函数
特别多,大致翻译一下
def debugprint(obj, depth=-1, print_type=False,
file=None, ids='CHAR', stop_on_name=False,
done=None, print_storage=False):
"""Print a computation graph as text to stdout or a file.
:type obj: Variable, Apply, or Function instance
:param obj: symbolic thing to print
:type depth: integer
:param depth: print graph to this depth (-1 for unlimited)
:type print_type: boolean
:param print_type: whether to print the type of printed objects
:type file: None, 'str', or file-like object
:param file: print to this file ('str' means to return a string)
:type ids: str
:param ids: How do we print the identifier of the variable
id - print the python id value
int - print integer character
CHAR - print capital character
"" - don't print an identifier
:param stop_on_name: When True, if a node in the graph has a name,
we don't print anything below it.
:type done: None or dict
:param done: A dict where we store the ids of printed node.
Useful to have multiple call to debugprint share the same ids.
:type print_storage: bool
:param print_storage: If True, this will print the storage map
for Theano functions. Combined with allow_gc=False, after the
execution of a Theano function, we see the intermediate result.
:returns: string if `file` == 'str', else file arg
Each line printed represents a Variable in the graph.
The indentation of lines corresponds to its depth in the symbolic graph.
The first part of the text identifies whether it is an input
(if a name or type is printed) or the output of some Apply (in which case
the Op is printed).
The second part of the text is an identifier of the Variable.
If print_type is True, we add a part containing the type of the Variable
If a Variable is encountered multiple times in the depth-first search,
it is only printed recursively the first time. Later, just the Variable
identifier is printed.
If an Apply has multiple outputs, then a '.N' suffix will be appended
to the Apply's identifier, to indicate which output a line corresponds to.
"""
将一个computation graph作为文本输出到终端或者文件
:type obj: 变量,Apply或者函数
:param obj: 要数出的符号
:type depth: 实数r
:param depth: 输出的深度为(限制为-1)
:type print_type: boolean
:param print_type: 是否输出输出对象的类型
:type file: 空,字符串,或者文件对象
:param file: 输出文件 ('str' 就是返回字符串)
:type ids: str
:param ids:怎样输出变量的标识符
id - 输出python的id值
int - 输出int型的表达式
CHAR - print capital character
"" - 不要输出一个标识符
:param stop_on_name: 如果为真, 如果图中的一个节点右名字,
在它的下面部署出任何东西.
:type done: 空或者字典
:param done: 一个字典,这个字典存储来要输出节点的id.
在多次调用共享同一个id的debugprint方法时非常有用
:type print_storage: bool
:param print_storage: 如果为真, 将会给theano funtion输出一个存储map
. Combined with allow_gc=False, after the
.在执行这个Theabo function 之后,我们将会看见中间结果
:returns: string if `file` == 'str', else file arg
每一行代表来graph中的一个变量
行的排列和缩进代表了这个比变量在图中的深度
文本的第一部分表示这是否是一个输入
(如果输出来名字和类型) 或者是一个输出或者Apply节点
(这时输出操作符).
第二部分是变量的标识符
如果print_type为真,我们将会加上一个部分,这个部分包含这个变量的类型
如果一个变量在一个深度优先搜诉中出现来多次
在这个递归过程中,他只会被输出一次,指数出这个变量的标识符
如果一个Apply有多个输出,那么这个Apply标识符将会被添加
一个'.N'后缀,来区分这个输出对应着哪一行
下面看官方文档给出的例子
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]#输出来它的name,所以是一个input,[id C]是它的标识符
|Shape_i{1} [id D] '' 0
|x [id C]
先这样,并不是很懂,感觉要把后面graph那一课看了再回来