CS285 2019 Tensorflow Tutorial( Tips and tricks)
# -*- coding: utf-8 -*-
import os
import warnings
os.environ['TF_CPP_MIN_LOG_LEVEL']='3'
warnings.filterwarnings('ignore')
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.patches as mpatches
def tf_reset():
try:
sess.close()
except:
pass
tf.reset_default_graph()
return tf.Session()
#(a) Check your dimensions
a = tf.constant(np.random.random((4,1)))
b = tf.constant(np.random.random((1,4)))
c=a*b
assert c.get_shape()==(4,4)
#(b) Check what variables have been created
sess =tf_reset()
a = tf.get_variable('I_am_a_variable',shape=[4,6])
b = tf.get_variable('I_am_a_variable_too',shape=[2,7])
for var in tf.global_variables():
print(var.name)
# Look at the tensorflow API, or open up a python terminal a