Skip to content

Commit

Permalink
Merge pull request jikexueyuanwiki#51 from Warln/master
Browse files Browse the repository at this point in the history
图表可视化graph_viz.md翻译
  • Loading branch information
floydzhang315 committed Nov 18, 2015
2 parents 93a1953 + 1737817 commit fff7fc1
Showing 1 changed file with 66 additions and 106 deletions.
172 changes: 66 additions & 106 deletions SOURCE/how_tos/graph_viz.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# TensorBoard: Graph Visualization <a class="md-anchor" id="AUTOGENERATED-tensorboard--graph-visualization"></a>
# TensorBoard: 图表可视化 <a class="md-anchor" id="AUTOGENERATED-tensorboard--graph-visualization"></a>

TensorFlow computation graphs are powerful but complicated. The graph visualization can help you understand and debug them. Here's an example of the visualization at work.
TensorFlow图表计算强大而又复杂,图表可视化在理解和调试时显得非常有帮助。 下面是一个运作时的可式化例子。

![Visualization of a TensorFlow graph](./graph_vis_animation.gif "Visualization of a TensorFlow graph")
*Visualization of a TensorFlow graph.*
![一个TensorFlow图表的可视化](http://tensorflow.org/how_tos/graph_viz/graph_vis_animation.gif)
"一个TensorFlow图表的可视化")
*一个TensorFlow图表的可视化。*

To see your own graph, run TensorBoard pointing it to the log directory of the job, click on the graph tab on the top pane and select the appropriate run using the menu at the upper left corner. For in depth information on how to run TensorBoard and make sure you are logging all the necessary information, see [Summaries and TensorBoard](../../how_tos/summaries_and_tensorboard/index.md).
要看到自己的图表,将TensorBoard指向此工作的日志目录并运行,点击图表顶部窗格的标签页,然后在左上角的菜单中选择合适的运行。想要深入学习关于如何运行TensorBoard以及如何保证你是在记录所有必要信息,查看[Summaries和TensorBoard](../../how_tos/summaries_and_tensorboard/index.md).

## Name scoping and nodes <a class="md-anchor" id="AUTOGENERATED-name-scoping-and-nodes"></a>
## 名称包围和节点 <a class="md-anchor" id="AUTOGENERATED-name-scoping-and-nodes"></a>

Typical TensorFlow graphs can have many thousands of nodes--far too many to see
easily all at once, or even to lay out using standard graph tools. To simplify,
variable names can be scoped and the visualization uses this information to
define a hierarchy on the nodes in the graph. By default, only the top of this
hierarchy is shown. Here is an example that defines three operations under the
`hidden` name scope using
[`tf.name_scope`](../../api_docs/python/framework.md#name_scope):
典型的TensorFlow可以有数以万计的节点,如此多而难以一下全部看到,甚至无法使用标准图表工具。让变量名可以被包围,并且可视化把该信息用于在图表中的节点上定义一个层级。默认情况下, 只有顶层节点会显示。下面这个例子使用[`tf.name_scope`](../../api_docs/python/framework.md#name_scope)`hidden`命名域下定义了三个操作:

```python
import tensorflow as tf
Expand All @@ -26,186 +21,151 @@ with tf.name_scope('hidden') as scope:
b = tf.Variable(tf.zeros([1]), name='biases')
```

This results in the following three op names:
结果是得到了下面三个op命名:

* *hidden*/alpha
* *hidden*/weights
* *hidden*/biases

By default, the visualization will collapse all three into a node labeled `hidden`.
The extra detail isn't lost. You can double-click, or click
on the orange `+` sign in the top right to expand the node, and then you'll see
three subnodes for `alpha`, `weights` and `biases`.
默认地,可视效果会把三个折叠为一个节点并标注为`hidden`。其额外细节并没有消失,你可以双击,或点击右上方橙色的`+`来展开节点,然后就会看到三个子节点`alpha``weights``biases`了。

Here's a real-life example of a more complicated node in its initial and
expanded states.
这有一个生动的例子,例中有一个更复杂的节点,节点处于其初始和展开状态。

<table width="100%;">
<tr>
<td style="width: 50%;">
<img src="./pool1_collapsed.png" alt="Unexpanded name scope" title="Unexpanded name scope" />
<img src="http://tensorflow.org/how_tos/graph_viz/pool1_collapsed.png" alt="未展开的名字域" title="未展开的名字域" />
</td>
<td style="width: 50%;">
<img src="./pool1_expanded.png" alt="Expanded name scope" title="Expanded name scope" />
<img src="http://tensorflow.org/how_tos/graph_viz/pool1_expanded.png" alt="展开的名字域" title="展开的名字域" />
</td>
</tr>
<tr>
<td style="width: 50%;">
Initial view of top-level name scope <code>pool_1</code>. Clicking on the orange <code>+</code> button on the top right or double-clicking on the node itself will expand it.
顶级名字域的初始视图<code>pool_1</code>,点击右上方橙色的<code>+</code>按钮或双击节点来展开。
</td>
<td style="width: 50%;">
Expanded view of <code>pool_1</code> name scope. Clicking on the orange <code>-</code> button on the top right or double-clicking on the node itself will collapse the name scope.
展开的<code>pool_1</code>名字域视图,点击右上方橙色的<code>-</code>按钮或双击节点来收起此名字域。
</td>
</tr>
</table>

Grouping nodes by name scopes is critical to making a legible graph. If you're
building a model, name scopes give you control over the resulting visualization.
**The better your name scopes, the better your visualization.**

The figure above illustrates a second aspect of the visualization. TensorFlow
graphs have two kinds of connections: data dependencies and control
dependencies. Data dependencies show the flow of tensors between two ops and
are shown as solid arrows, while control dependencies use dotted lines. In the
expanded view (right side of the figure above) all the connections are data
dependencies with the exception of the dotted line connecting `CheckNumerics`
and `control_dependency`.

There's a second trick to simplifying the layout. Most TensorFlow graphs have a
few nodes with many connections to other nodes. For example, many nodes might
have a control dependencies on an initialization step. Drawing all edges
between the `init` node and its dependencies would create a very cluttered
view.

To reduce clutter, the visualization separates out all high-degree nodes to an
*auxiliary* area on the right and doesn't draw lines to represent their edges.
Instead of lines, we draw small *node icons* to indicate the connections.
Separating out the auxiliary nodes typically doesn't remove critical
information since these nodes are usually related to bookkeeping functions.
通过名字域把节点分组来得到可读性高的图表是关键性的。如果你在构建一个模型,名字域就可以用来控制可式化结果。

**你的名字域越好,可视性就越好。**

上面的图像例子说明了可视化的另一方面, TensorFlow图表有两种连接关系:数据依赖和控制依赖。数据依赖显示两个op之间的tensor流程,用实心箭头指示,而控制依赖用点线表示。在已展开的视图(上面的图像的右边)中,除了用点线连接的`CheckNumerics``control_dependency`之外,所有连接都是数据依赖的。

还有一种手段用来简化布局。大多数TensorFlow图表有一部分节点,这部分节点和其他节点之间有狠多连接。比如,许多节点在初始化阶段可能会有一个控制依赖,而绘制所有`init`节点的边缘和其依赖可能会创造出一个混乱的视图。

为了减少混乱,可式化把所有high-degree节点分离到右边的一个*从属*区域, 而不会绘制线条来表示他们的边缘。线条也不用来表示连接了,我们绘制了小*节点图标*来指示这些连接关系。
分离出从属节点通常不会把关键信息删除掉,因为这些节点和内构功能是相关的。

<table width="100%;">
<tr>
<td style="width: 50%;">
<img src="./conv_1.png" alt="conv_1 is part of the main graph" title="conv_1 is part of the main graph" />
<img src="http://tensorflow.org/how_tos/graph_viz/conv_1.png" alt="conv_1是主图表的部分" title="conv_1是主图表的部分" />
</td>
<td style="width: 50%;">
<img src="./save.png" alt="save is extracted as auxiliary node" title="save is extracted as auxiliary node" />
<img src="http://tensorflow.org/how_tos/graph_viz/save.png" alt="save被抽出为从属节点" title="save被抽出为从属节点" />
</td>
</tr>
<tr>
<td style="width: 50%;">
Node <code>conv_1</code> is connected to <code>save</code>. Note the little <code>save</code> node icon on its right.
节点<code>conv_1</code>被连接到<code>save</code>,注意其右边<code>save</code>节点图标的标题。
</td>
<td style="width: 50%;">
<code>save</code> has a high degree, and will appear as an auxiliary node. The connection with <code>conv_1</code> is shown as a node icon on its left. To further reduce clutter, since <code>save</code> has a lot of connections, we show the first 5 and abbreviate the others as <code>... 12 more</code>.
<code>save</code> has a high degree, 并会作为从属节点出现,与<code>conv_1</code>的连接作为一个节点图标显示在其左边。为了继续减少杂乱,既然<code>save</code>有很多连接,我们则只显示前5个,而把其余的缩略为<code>... 12 more</code>
</td>
</tr>
</table>

One last structural simplification is *series collapsing*. Sequential
motifs--that is, nodes whose names differ by a number at the end and have
isomorphic structures--are collapsed into a single *stack* of nodes, as shown
below. For networks with long sequences, this greatly simplifies the view. As
with hierarchical nodes, double-clicking expands the series.
最后一个结构上的简化法叫做*序列折叠*。 序列基序--就是, 拥有相同结构并且其名称结尾的数字不同的节点,--将它们折叠进一个单独的节点**中。对长序列网来说,序列折叠极大地简化了视图, 对于已层叠的节点,双击会展开序列。

<table width="100%;">
<tr>
<td style="width: 50%;">
<img src="./series.png" alt="Sequence of nodes" title="Sequence of nodes" />
<img src="http://tensorflow.org/how_tos/graph_viz/series.png" alt="节点序列" title="节点序列" />
</td>
<td style="width: 50%;">
<img src="./series_expanded.png" alt="Expanded sequence of nodes" title="Expanded sequence of nodes" />
<img src="http://tensorflow.org/how_tos/graph_viz/series_expanded.png" alt="展开的节点序列" title="展开的节点序列" />
</td>
</tr>
<tr>
<td style="width: 50%;">
A collapsed view of a node sequence.
一个节点序列的折叠视图。
</td>
<td style="width: 50%;">
A small piece of the expanded view, after double-click.
视图的一小块, 双击后展开。
</td>
</tr>
</table>

Finally, as one last aid to legibility, the visualization uses special icons
for constants and summary nodes. To summarize, here's a table of node symbols:
最后,针对易读性的最后一点要说到的是,可视化为常节点和摘要节点使用了特别的图标,总结起来有下面这些节点符号:

Symbol | Meaning
符号 | 意义
--- | ---
![Name scope](./namespace_node.png "Name scope") | *High-level* node representing a name scope. Double-click to expand a high-level node.
![Sequence of unconnected nodes](./horizontal_stack.png "Sequence of unconnected nodes") | Sequence of numbered nodes that are not connected to each other.
![Sequence of connected nodes](./vertical_stack.png "Sequence of connected nodes") | Sequence of numbered nodes that are connected to each other.
![Operation node](./op_node.png "Operation node") | An individual operation node.
![Constant node](./constant.png "Constant node") | A constant.
![Summary node](./summary.png "Summary node") | A summary node.
![Data flow edge](./dataflow_edge.png "Data flow edge") | Edge showing the data flow between operations.
![Control dependency edge](./control_edge.png "Control dependency edge") | Edge showing the control dependency between operations.
![Reference edge](./reference_edge.png "Reference edge") | A reference edge showing that the outgoing operation node can mutate the incoming tensor.

## Interaction <a class="md-anchor" id="AUTOGENERATED-interaction"></a>

Navigate the graph by panning and zooming. Click and drag to pan, and use a
scroll gesture to zoom. Double-click on a node, or click on its `+` button, to
expand a name scope that represents a group of operations. To easily keep
track of the current viewpoint when zooming and panning, there is a minimap in
the bottom right corner.

To close an open node, double-click it again or click its `-` button. You can
also click once to select a node. It will turn a darker color, and details
about it and the nodes it connects to will appear in the info card at upper
right corner of the visualization.
![名字域](http://tensorflow.org/how_tos/graph_viz/namespace_node.png "名字域") | *High-level*节点代表一个名字域,双击则展开一个高层节点。
![断线节点序列](http://tensorflow.org/how_tos/graph_viz/horizontal_stack.png "断线节点序列") | 彼此之间不连接的有限个节点序列。
![相连节点序列](http://tensorflow.org/how_tos/graph_viz/vertical_stack.png "相连节点序列") | 彼此之间相连的有限个节点序列。
![操作节点](http://tensorflow.org/how_tos/graph_viz/op_node.png "操作节点") | 一个单独的操作节点。
![常节点](http://tensorflow.org/how_tos/graph_viz/constant.png "常节点") | 一个常量。
![摘要节点](http://tensorflow.org/how_tos/graph_viz/summary.png "摘要节点") | 一个摘要节点。
![数据流边界](http://tensorflow.org/how_tos/graph_viz/dataflow_edge.png "数据流边界") | 显示各操作间的数据流边界。
![控制依赖边界](http://tensorflow.org/how_tos/graph_viz/control_edge.png "控制依赖边界") | 显示各操作间的控制依赖边界。
![参考边界](http://tensorflow.org/how_tos/graph_viz/reference_edge.png "参考边界") | 一个参考边界展示了即将离任的操作节点可以使之后到来的tensor发生变化。

## 交互 <a class="md-anchor" id="AUTOGENERATED-interaction"></a>

通过平移和缩放来导航图表,点击和拖动用于平移,滚动手势用于缩放。双击一个节点或点击其`+`按钮来展开代表一组操作的名字域。右下角有一个小地图可以在缩放和平移时方便的改变当前视角。

要关闭一个打开的节点,再次双击它或点击它的`-`按钮,你也可以只点击一次来选中一个节点,节点的颜色会加深,并且会看到节点的详情,其连接到的节点会在可视化右上角的详情卡片显现。

<table width="100%;">
<tr>
<td style="width: 50%;">
<img src="./infocard.png" alt="Info card of a name scope" title="Info card of a name scope" />
<img src="http://tensorflow.org/how_tos/graph_viz/infocard.png" alt="一个名字域的详情卡片" title="一个名字域的详情卡片" />
</td>
<td style="width: 50%;">
<img src="./infocard_op.png" alt="Info card of operation node" title="Info card of operation node" />
<img src="http://tensorflow.org/how_tos/graph_viz/infocard_op.png" alt="操作节点的详情卡片" title="操作节点的详情卡片" />
</td>
</tr>
<tr>
<td style="width: 50%;">
Info card showing detailed information for the <code>conv2</code> name scope. The inputs and outputs are combined from the inputs and outputs of the operation nodes inside the name scope. For name scopes no attributes are shown.
详情卡片展示<code>conv2</code>名字域的详细信息,名字域中操作节点的输入和输出被结合在一起,适用于不显示属性的名字域。
</td>
<td style="width: 50%;">
Info card showing detailed information for the <code>DecodeRaw</code> operation node. In addition to inputs and outputs, the card shows the device and the attributes associated with the current operation.
详情卡片展示<code>DecodeRaw</code>操作节点,除了输入和输出,卡片也会展示与当前节点相关的设备和属性。
</td>
</tr>
</table>

Selection can also be helpful in understanding high-degree nodes. Select any
high-degree node, and the corresponding node icons for its other connections
will be selected as well. This makes it easy, for example, to see which nodes
are being saved--and which aren't.
选择对于high-degree节点的理解也很有帮助,选择任意节点,则与它的其余连接相应的节点也会选中,这使得在进行例如查看哪一个节点是否已保存等操作时非常容易。

Clicking on a node name in the info card will select it. If necessary, the
viewpoint will automatically pan so that the node is visible.
点击详情卡片中的一个节点名称时会选中该节点,必要的话,视角会自动平移以使该节点可见。

Finally, you can choose two color schemes for your graph, using the color menu
above the legend. The default *Structure View* shows structure: when two
high-level nodes have the same structure, they appear in the same color of the
rainbow. Uniquely structured nodes are gray. There's a second view, which shows
what device the different operations run on. Name scopes are colored
proportionally to the fraction of devices for the operations inside them.
最后,使用图例上方的颜色菜单,你可以给你的图表选择两个颜色方案。默认的*结构视图*下,当两个high-level节点颜色一样时,其会以相同的彩虹色彩出现,而结构唯一的节点颜色是灰色。还有一个视图则展示了不同的操作运行于什么设备之上。名字域被恰当的根据其中的操作节点的设备片件来着色。

The images below give an illustration for a piece of a real-life graph.
下图是一张真实图表的图解:

<table width="100%;">
<tr>
<td style="width: 50%;">
<img src="./colorby_structure.png" alt="Color by structure" title="Color by structure" />
<img src="http://tensorflow.org/how_tos/graph_viz/colorby_structure.png" alt="按结构着色" title="按结构着色" />
</td>
<td style="width: 50%;">
<img src="./colorby_device.png" alt="Color by device" title="Color by device" />
<img src="http://tensorflow.org/how_tos/graph_viz/colorby_device.png" alt="按设备着色" title="按设备着色" />
</td>
</tr>
<tr>
<td style="width: 50%;">
Structure view: The gray nodes have unique structure. The orange <code>conv1</code> and <code>conv2</code> nodes have the same structure, and analogously for nodes with other colors.
结构视图:灰色节点的结构是唯一的。橙色的<code>conv1</code><code>conv2</code>节点有相同的结构, 其他颜色的节点也类似。
</td>
<td style="width: 50%;">
Device view: Name scopes are colored proportionally to the fraction of devices of the operation nodes inside them. Here, purple means GPU and the green is CPU.
设备视图:名字域被恰当的根据其中的操作节点的设备片件来着色, 在此处, 紫色代表GPU,绿色代表CPU。
</td>
</tr>
</table>

原文: [TensorBoard: Graph Visualization](http://tensorflow.org/how_tos/graph_viz/index.html#tensorboard-graph-visualization)
翻译: [@Warln](https://github.com/Warln)

0 comments on commit fff7fc1

Please sign in to comment.