Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

📚 The CoCalc Library - books, templates and other resources

Views: 96144
License: OTHER
1
""" Example of lazy vs normal loading
2
Created by Chip Huyen ([email protected])
3
CS20: "TensorFlow for Deep Learning Research"
4
cs20.stanford.edu
5
Lecture 02
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/normal_loading', 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/lazy_loading', 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