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

Multiple graphs

We can create our own graphs, which are separate from the default graph, and execute them in a session. However, creating and executing multiple graphs is not recommended, because of the following disadvantages:

  • Creating and using multiple graphs in the same program would require multiple TensorFlow sessions, and each session would consume heavy resources
  • Data cannot be directly passed in-between graphs

Hence, the recommended approach is to have multiple subgraphs in a single graph. In case we wish to use our own graph instead of the default graph, we can do so with the tf.graph() command. In the following example, we create our own graph, g, and execute it as the default graph:

g = tf.Graph()
output = 0

# Assume Linear Model y = w * x + b

with g.as_default():
# Define model parameters
w = tf.Variable([.3], tf.float32)
b = tf.Variable([-.3], tf.float32)
# Define model input and output
x = tf.placeholder(tf.float32)
y = w * x + b

with tf.Session(graph=g) as tfs:
# initialize and print the variable y
tf.global_variables_initializer().run()
output = tfs.run(y,{x:[1,2,3,4]})

print('output : ',output)

Now, let's put this learning into practice and implement the classification of handwritten digital images with TensorFlow.

主站蜘蛛池模板: 泾川县| 武清区| 班戈县| 余庆县| 客服| 伽师县| 建瓯市| 灵丘县| 湄潭县| 金寨县| 锡林郭勒盟| 敦煌市| 和龙市| 阿克苏市| 灵山县| 伊通| 湟中县| 新源县| 岱山县| 临清市| 宁明县| 虎林市| 社会| 涿鹿县| 榆社县| 专栏| 石狮市| 辛集市| 合肥市| 商南县| 偏关县| 雷波县| 从江县| 雷波县| 攀枝花市| 金阳县| 三台县| 云龙县| 察隅县| 高陵县| 资阳市|