官术网_书友最值得收藏!

Building a graph

A TensorFlow graph is a series of operations organized in graph. The model architecture is first built in the form of a TensorFlow graph. You need to keep in mind three basic operations:

  • tf.constant: Holds a constant tensor just like a constant in Python, but unlike Python, it gets activated only during a TensorFlow Session.
  • tf.Variable: Holds a variable tensor that is learnable during training and updates value. 
  • tf.Placeholder: This is an interesting feature of TensorFlow. At the time of building the graph, we don't provide the input data. But, it is required to lay out the shape and data type of input that the graph will be receiving. Thus, placeholder acts as a container that will allow the flow of input tensors when a Session is activated. 

Let's try to add two constants in TensorFlow as follows:

>>>import tensorflow as tf
>>>t1 = tf.constant('hey')
>>>t2 = tf.constant('there')
>>sum = t1 + t2
>>>print(sum)

This will output something like this: add:0, shape=(), dtype=string. You were expecting heythere? This doesn't happen because TensorFlow runs the graph only when a Session is activated. By defining the constants, we just made a graph, and that's why the print was trying to tell what the sum would be when the graph is run. So, let's create a Session.

主站蜘蛛池模板: 牟定县| 固阳县| 鄂托克旗| 临澧县| 莱州市| 阿图什市| 旌德县| 靖宇县| 广西| 罗平县| 特克斯县| 博白县| 天台县| 洪洞县| 定日县| 汉寿县| 吴旗县| 新邵县| 马山县| 齐齐哈尔市| 伊通| 梅州市| 香河县| 仁怀市| 屏边| 将乐县| 武城县| 湄潭县| 民勤县| 旅游| 邯郸市| 永善县| 广南县| 阳谷县| 星子县| 通城县| 梓潼县| 香格里拉县| 黔东| 雅江县| 牟定县|