tensorflow computational model—— graphics
conception:
tensor: fundamental data structure(multi-dimension arrays)
two stages
first stage--construction
turn the operations to the nodes of the graph
default graph
tf.get_default_graph()
define new graph
g1= tf.graph()
with g1 as default():
specify device
with g1.device('/gpu:0')
second stage--session(left out now)
tensor
tensor=tf.constant(dtype=<type>,shape=<shape>,name=<name>)
14 dtypes
default dtype: int32 and float32
application:
- reference to temporal result
such as:result.get_shape ()
- acquire the result from graph
such as:tf.Session().run(result)
session
sess=tf.Session()
sess.run()
sess.close()
#-------------------
with tf.Session() as sess:
#sess.close() is not needed
#--------------------
sess=tf.Session()
with sess.as_default():
print(result.eval())
# same as
sess=tf.Session()
print(sess.run(result))
print(result.eval(session=sess))
#------------------------
sess=tf.InteractiveSession()
print(result.eval())
sess.close()
#ConfigProto for configure threads,GPUs,overtime
# following example shows the usual parameters to #be configured,the first one is recommended to be #True in GPU case
config=tf.ConfigProto(allow_soft_placement=True,log_device_placement=True)
sess=tf.InteractiveSession(config=config)