- Mastering TensorFlow 1.x
- Armando Fandango
- 184字
- 2021-06-25 22:50:58
Multiple graphs
You can create your own graphs separate from the default graph and execute them in a session. However, creating and executing multiple graphs is not recommended, as it has the following disadvantages:
- Creating and using multiple graphs in the same program would require multiple TensorFlow sessions and each session would consume heavy resources
- You cannot directly pass data in between graphs
Hence, the recommended approach is to have multiple subgraphs in a single graph. In case you wish to use your own graph instead of the default graph, you can do so with the tf.graph() command. Here is an example where 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)
推薦閱讀
- Instant uTorrent
- Linux KVM虛擬化架構實戰指南
- 硬件產品經理成長手記(全彩)
- Mastering Manga Studio 5
- micro:bit魔法修煉之Mpython初體驗
- CC2530單片機技術與應用
- 筆記本電腦維修300問
- 超大流量分布式系統架構解決方案:人人都是架構師2.0
- “硬”核:硬件產品成功密碼
- 單片機原理與技能訓練
- 嵌入式系統原理及應用:基于ARM Cortex-M4體系結構
- Blender for Video Production Quick Start Guide
- 筆記本電腦的結構、原理與維修
- The Reinforcement Learning Workshop
- Learning Microsoft Cognitive Services