Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132928 views
License: OTHER
1
""" Example to demonstrate how the graph definition gets
2
bloated because of lazy loading
3
Author: Chip Huyen
4
Prepared for the class CS 20SI: "TensorFlow for Deep Learning Research"
5
cs20si.stanford.edu
6
"""
7
import os
8
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
9
10
import tensorflow as tf
11
12
########################################
13
## NORMAL LOADING ##
14
## print out a graph with 1 Add node ##
15
########################################
16
17
x = tf.Variable(10, name='x')
18
y = tf.Variable(20, name='y')
19
z = tf.add(x, y)
20
21
with tf.Session() as sess:
22
sess.run(tf.global_variables_initializer())
23
writer = tf.summary.FileWriter('./graphs/l2', sess.graph)
24
for _ in range(10):
25
sess.run(z)
26
print(tf.get_default_graph().as_graph_def())
27
writer.close()
28
29
########################################
30
## LAZY LOADING ##
31
## print out a graph with 10 Add nodes##
32
########################################
33
34
x = tf.Variable(10, name='x')
35
y = tf.Variable(20, name='y')
36
37
with tf.Session() as sess:
38
sess.run(tf.global_variables_initializer())
39
writer = tf.summary.FileWriter('./graphs/l2', sess.graph)
40
for _ in range(10):
41
sess.run(tf.add(x, y))
42
print(tf.get_default_graph().as_graph_def())
43
writer.close()
44