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

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)
主站蜘蛛池模板: 城口县| 衡东县| 奇台县| 墨竹工卡县| 西乌| 当涂县| 定安县| 南召县| 渭源县| 平山县| 阿拉善右旗| 清流县| 嘉禾县| 会泽县| 六枝特区| 察隅县| 礼泉县| 哈巴河县| 延长县| 西林县| 桃江县| 历史| 康保县| 饶河县| 芜湖市| 永嘉县| 吉安市| 义乌市| 阿巴嘎旗| 西充县| 建昌县| 柏乡县| 湖南省| 如东县| 香港| 吉林省| 西乡县| 闻喜县| 蓬溪县| 永康市| 贵州省|