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

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)
主站蜘蛛池模板: 四会市| 交口县| 阿合奇县| 新邵县| 休宁县| 临邑县| 拜泉县| 临猗县| 历史| 门头沟区| 柞水县| 永平县| 淮南市| 思茅市| 分宜县| 通道| 祁东县| 电白县| 巴林左旗| 新宁县| 镇康县| 鞍山市| 海口市| 大石桥市| 上栗县| 改则县| 车险| 南召县| 微博| 德令哈市| 淮南市| 滨州市| 凤庆县| 石门县| 田林县| 南部县| 聂拉木县| 白玉县| 东兰县| 昌邑市| 海盐县|